20 #ifndef SketchPlugin_Sketch_H_
21 #define SketchPlugin_Sketch_H_
23 #include "SketchPlugin.h"
24 #include <SketchPlugin_Feature.h>
25 #include <GeomAPI_Pnt.h>
26 #include <GeomAPI_Pln.h>
27 #include <GeomAPI_IPresentable.h>
28 #include <GeomAPI_ICustomPrs.h>
30 #include <GeomAPI_Ax3.h>
31 #include <GeomAPI_XYZ.h>
32 #include <GeomDataAPI_Point.h>
33 #include <GeomDataAPI_Dir.h>
36 #ifdef SET_PLANES_COLOR_IN_PREFERENCES
37 #define YZ_PLANE_COLOR "225,0,0"
38 #define XZ_PLANE_COLOR "0,225,0"
39 #define XY_PLANE_COLOR "0,0,225"
50 inline static const std::string&
ID()
52 static const std::string MY_SKETCH_ID(
"Sketch");
58 static const std::string MY_ORIGIN_ID(
"Origin");
62 inline static const std::string&
DIRX_ID()
64 static const std::string MY_DIRX_ID(
"DirX");
68 inline static const std::string&
NORM_ID()
70 static const std::string MY_NORM_ID(
"Norm");
77 static const std::string MY_DEFAULT_SIZE_ID_ID(
"DefaultSize");
78 return MY_DEFAULT_SIZE_ID_ID;
81 inline static const std::string& AXES_ENABLED_ID()
83 static const std::string MY_AXES_ENABLED_ID(
"AxesEnabled");
84 return MY_AXES_ENABLED_ID;
87 inline static const std::string& SUBSTRATE_ENABLED_ID()
89 static const std::string MY_SUBSTRATE_ENABLED_ID(
"SubstrateEnabled");
90 return MY_SUBSTRATE_ENABLED_ID;
93 inline static const std::string& CONSTRUCTION_GRID_TYPE_ID()
95 static const std::string MY_CONSTRUCTION_GRID_TYPE_ID(
"GridType");
96 return MY_CONSTRUCTION_GRID_TYPE_ID;
99 inline static const std::string& RECTANGULAR_CONSTRUCTION_GRID_STEP_X_ID()
101 static const std::string MY_RECTANGULAR_CONSTRUCTION_GRID_STEP_X_ID(
"RectangularGridStepX");
102 return MY_RECTANGULAR_CONSTRUCTION_GRID_STEP_X_ID;
104 inline static const std::string& RECTANGULAR_CONSTRUCTION_GRID_STEP_Y_ID()
106 static const std::string MY_RECTANGULAR_CONSTRUCTION_GRID_STEP_Y_ID(
"RectangularGridStepY");
107 return MY_RECTANGULAR_CONSTRUCTION_GRID_STEP_Y_ID;
109 inline static const std::string& RECTANGULAR_CONSTRUCTION_GRID_OFFSET_ANGLE_ID()
111 static const std::string MY_RECTANGULAR_CONSTRUCTION_GRID_OFFSET_ANGLE_ID(
"RectangularGridOffsetAngle");
112 return MY_RECTANGULAR_CONSTRUCTION_GRID_OFFSET_ANGLE_ID;
114 inline static const std::string& RECTANGULAR_CONSTRUCTION_GRID_OFFSET_X_ID()
116 static const std::string MY_RECTANGULAR_CONSTRUCTION_GRID_OFFSET_X_ID(
"RectangularGridOffsetX");
117 return MY_RECTANGULAR_CONSTRUCTION_GRID_OFFSET_X_ID;
119 inline static const std::string& RECTANGULAR_CONSTRUCTION_GRID_OFFSET_Y_ID()
121 static const std::string MY_RECTANGULAR_CONSTRUCTION_GRID_OFFSET_Y_ID(
"RectangularGridOffsetY");
122 return MY_RECTANGULAR_CONSTRUCTION_GRID_OFFSET_Y_ID;
125 inline static const std::string& CIRCULAR_CONSTRUCTION_GRID_STEP_R_ID()
127 static const std::string MY_CIRCULAR_CONSTRUCTION_GRID_STEP_R_ID(
"CircularGridStepR");
128 return MY_CIRCULAR_CONSTRUCTION_GRID_STEP_R_ID;
130 inline static const std::string& CIRCULAR_CONSTRUCTION_GRID_NUM_OF_ANG_SEGMENTS_ID()
132 static const std::string MY_CIRCULAR_CONSTRUCTION_GRID_NUM_OF_ANG_SEGMENTS_ID(
"CircularGridNumOfAnularSegments");
133 return MY_CIRCULAR_CONSTRUCTION_GRID_NUM_OF_ANG_SEGMENTS_ID;
135 inline static const std::string& CIRCULAR_CONSTRUCTION_GRID_OFFSET_ANGLE_ID()
137 static const std::string MY_CIRCULAR_CONSTRUCTION_GRID_OFFSET_ANGLE_ID(
"CircularGridOffsetAngle");
138 return MY_CIRCULAR_CONSTRUCTION_GRID_OFFSET_ANGLE_ID;
140 inline static const std::string& CIRCULAR_CONSTRUCTION_GRID_OFFSET_X_ID()
142 static const std::string MY_CIRCULAR_CONSTRUCTION_GRID_OFFSET_X_ID(
"CircularGridOffsetX");
143 return MY_CIRCULAR_CONSTRUCTION_GRID_OFFSET_X_ID;
145 inline static const std::string& CIRCULAR_CONSTRUCTION_GRID_OFFSET_Y_ID()
147 static const std::string MY_CIRCULAR_CONSTRUCTION_GRID_OFFSET_Y_ID(
"CircularGridOffsetY");
148 return MY_CIRCULAR_CONSTRUCTION_GRID_OFFSET_Y_ID;
154 static const std::string MY_FEATURES_ID(
"Features");
155 return MY_FEATURES_ID;
160 static const std::string MY_SOLVER_ERROR(
"SolverError");
161 return MY_SOLVER_ERROR;
167 static const std::string MY_SOLVER_DOF(
"SolverDOF");
168 return MY_SOLVER_DOF;
174 static const std::string MY_ACTION_REMOVE_EXTERNAL(
"RemoveExternalLinks");
175 return MY_ACTION_REMOVE_EXTERNAL;
179 SKETCHPLUGIN_EXPORT
virtual const std::string&
getKind()
186 SKETCHPLUGIN_EXPORT
virtual void execute();
194 std::shared_ptr<GeomAPI_Pnt>
to3D(
const double theX,
const double theY)
const
196 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
198 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
200 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
202 std::shared_ptr<GeomAPI_Dir> aY(
new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
204 std::shared_ptr<GeomAPI_XYZ> aSum = aC->pnt()->xyz()->added(aX->dir()->xyz()->multiplied(theX))
205 ->added(aY->xyz()->multiplied(theY));
207 return std::shared_ptr<GeomAPI_Pnt>(
new GeomAPI_Pnt(aSum));
212 std::shared_ptr<GeomAPI_Pnt2d>
to2D(
const std::shared_ptr<GeomAPI_Pnt>& thePnt)
const
214 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
216 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
218 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
220 std::shared_ptr<GeomAPI_Dir> aY(
new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
221 return thePnt->to2D(aC->pnt(), aX->dir(), aY);
234 std::shared_ptr<GeomAPI_Pln>
plane()
const
236 std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
238 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
241 if (anOrigin.get() && aNorm.get() && anOrigin->isInitialized() && aNorm->isInitialized())
242 return std::shared_ptr<GeomAPI_Pln>(
new GeomAPI_Pln(anOrigin->pnt(), aNorm->dir()));
244 return std::shared_ptr<GeomAPI_Pln>();
250 DataPtr aData =
data();
251 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
253 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
255 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
258 if (!aNorm->isInitialized() || !aX->isInitialized() ||
259 aNorm->dir()->cross(aX->dir())->squareModulus() < 1.e-14)
260 return std::shared_ptr<GeomAPI_Ax3>();
262 return std::shared_ptr<GeomAPI_Ax3>(
new GeomAPI_Ax3(aC->pnt(), aX->dir(), aNorm->dir()));
269 std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
272 return aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
277 SKETCHPLUGIN_EXPORT
virtual std::shared_ptr<ModelAPI_Feature>
addFeature(std::string theID);
280 virtual void removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature);
283 SKETCHPLUGIN_EXPORT
virtual int numberOfSubs(
bool forTree =
false)
const;
286 SKETCHPLUGIN_EXPORT
virtual std::shared_ptr<ModelAPI_Feature>
287 subFeature(
const int theIndex,
bool forTree =
false);
290 SKETCHPLUGIN_EXPORT
virtual int subFeatureId(
const int theIndex)
const;
293 SKETCHPLUGIN_EXPORT
virtual bool isSub(ObjectPtr theObject)
const;
295 SKETCHPLUGIN_EXPORT
virtual void attributeChanged(
const std::string& theID);
300 SKETCHPLUGIN_EXPORT
virtual bool customAction(
const std::string& theActionId);
309 const std::string& theAttributeID,
const int theIndex);
319 const std::string& theStartAttrID,
320 const std::string& theEndAttrID,
321 const int theIndex = 0);
331 const bool theIsCopy =
false);
354 bool removeLinksToExternal();
357 void updateCoordinateAxis(ObjectPtr theSub, std::shared_ptr<GeomAPI_Ax3> thePlane);
360 std::shared_ptr<GeomAPI_Ax3> myPlane;
The class represents a coordinate plane which is 2d plane with X and Y directions and origin.
Definition: GeomAPI_Ax3.h:33
3D direction defined by three normalized coordinates
Definition: GeomAPI_Dir.h:34
\Plane in 3D place, defined by normal, center and x-direction.
Definition: GeomAPI_Pln.h:38
3D point defined by three coordinates
Definition: GeomAPI_Pnt.h:38
Feature that consists of other features: like sketcher with edges inside.
Definition: ModelAPI_CompositeFeature.h:33
Feature function that represents the particular functionality of this operation.
Definition: ModelAPI_Feature.h:41
std::shared_ptr< ModelAPI_Attribute > attribute(const std::string &theID)
Returns the attribute by the identifier.
Definition: ModelAPI_Feature.h:271
virtual std::shared_ptr< ModelAPI_Data > data() const
Returns the data manager of this object: attributes.
Definition: ModelAPI_Object.cpp:45
Feature for creation of the new part in PartSet.
Definition: SketchPlugin_Sketch.h:47
static void createLine2DResult(ModelAPI_Feature *theFeature, SketchPlugin_Sketch *theSketch, const std::string &theStartAttrID, const std::string &theEndAttrID, const int theIndex=0)
Create a result for the segment given by a pair of attributes.
Definition: SketchPlugin_Sketch.cpp:513
static const std::string & DEFAULT_SIZE_ID()
Size of a skectch, if it has just been created on a default plane.
Definition: SketchPlugin_Sketch.h:75
static void createPoint2DResult(ModelAPI_Feature *theFeature, SketchPlugin_Sketch *theSketch, const std::string &theAttributeID, const int theIndex)
Create a result for the point in the attribute if the attribute is initialized.
Definition: SketchPlugin_Sketch.cpp:491
std::shared_ptr< GeomAPI_Pnt2d > to2D(const std::shared_ptr< GeomAPI_Pnt > &thePnt) const
Returns the point projected into the sketch plane.
Definition: SketchPlugin_Sketch.h:212
virtual std::shared_ptr< ModelAPI_Feature > addFeature(std::string theID)
appends a feature to the sketch sub-elements container
Definition: SketchPlugin_Sketch.cpp:271
virtual int subFeatureId(const int theIndex) const
Returns the sub-feature unique identifier in this composite feature by index.
Definition: SketchPlugin_Sketch.cpp:352
std::shared_ptr< GeomAPI_Ax3 > coordinatePlane() const
Returns currently defined plane as an object of Ax3.
Definition: SketchPlugin_Sketch.h:248
virtual int numberOfSubs(bool forTree=false) const
Returns the number of sub-elements.
Definition: SketchPlugin_Sketch.cpp:334
virtual bool isSub(ObjectPtr theObject) const
Returns true if feature or result belong to this composite feature as subs.
Definition: SketchPlugin_Sketch.cpp:370
virtual void execute()
Creates a new part document if needed.
Definition: SketchPlugin_Sketch.cpp:201
std::shared_ptr< GeomAPI_Pnt > to3D(const double theX, const double theY) const
Converts a 2D sketch space point into point in 3D space.
Definition: SketchPlugin_Sketch.h:194
static const std::string & ID()
Sketch feature kind.
Definition: SketchPlugin_Sketch.h:50
virtual void initAttributes()
Request for initialization of data model of the feature: adding all attributes.
Definition: SketchPlugin_Sketch.cpp:68
std::shared_ptr< GeomAPI_Pln > plane() const
Returns the basis plane for the sketch.
Definition: SketchPlugin_Sketch.h:234
bool isPlaneSet() const
Checks whether the plane is set in the sketch.
Definition: SketchPlugin_Sketch.h:267
virtual bool customAction(const std::string &theActionId)
Performs some custom feature specific functionality (normally called by some GUI button)
Definition: SketchPlugin_Sketch.cpp:585
virtual const std::string & getKind()
Returns the kind of a feature.
Definition: SketchPlugin_Sketch.h:179
virtual std::shared_ptr< ModelAPI_Feature > subFeature(const int theIndex, bool forTree=false)
Returns the sub-feature by zero-base index.
Definition: SketchPlugin_Sketch.cpp:341
static const std::string & ACTION_REMOVE_EXTERNAL()
Action ID to remove links to external entities while changing the sketch plane.
Definition: SketchPlugin_Sketch.h:172
static const std::string & SOLVER_DOF()
Sketch solver error.
Definition: SketchPlugin_Sketch.h:165
static FeaturePtr addUniqueNamedCopiedFeature(FeaturePtr theFeature, SketchPlugin_Sketch *theSketch, const bool theIsCopy=false)
Add new feature and fill the data of the feature by the data of the parameter feature.
Definition: SketchPlugin_Sketch.cpp:542
static const std::string & NORM_ID()
Vector Z, normal to the sketch plane.
Definition: SketchPlugin_Sketch.h:68
static const std::string & SOLVER_ERROR()
Sketch solver error.
Definition: SketchPlugin_Sketch.h:158
SketchPlugin_Sketch()
Use plugin manager for features creation.
Definition: SketchPlugin_Sketch.cpp:64
virtual void removeFeature(std::shared_ptr< ModelAPI_Feature > theFeature)
Just to synchronise the container of sub-features.
Definition: SketchPlugin_Sketch.cpp:318
static const std::string & DIRX_ID()
Vector X inside of the sketch plane.
Definition: SketchPlugin_Sketch.h:62
virtual bool isInHistory()
Returns true if this feature must be displayed in the history (top level of Part tree)
Definition: SketchPlugin_Sketch.h:225
static const std::string & ORIGIN_ID()
Origin point of the sketcher in 3D space.
Definition: SketchPlugin_Sketch.h:56
virtual void attributeChanged(const std::string &theID)
Called on change of any argument-attribute of this object.
Definition: SketchPlugin_Sketch.cpp:415
static const std::string & FEATURES_ID()
All features of this sketch (list of references)
Definition: SketchPlugin_Sketch.h:152