1 #include <SketchSolver_ConstraintMultiTranslation.h>
2 #include <SketchSolver_Error.h>
3 #include <SketchSolver_Manager.h>
5 ////#include <SketchPlugin_Arc.h>
6 #include <SketchPlugin_MultiTranslation.h>
8 ////#include <ModelAPI_AttributeDouble.h>
9 ////#include <ModelAPI_AttributeInteger.h>
10 ////#include <ModelAPI_AttributeRefAttr.h>
11 ////#include <ModelAPI_AttributeRefList.h>
12 ////#include <ModelAPI_ResultConstruction.h>
13 ////#include <ModelAPI_Data.h>
15 ////#include <GeomAPI_Dir2d.h>
16 ////#include <GeomAPI_XY.h>
21 void SketchSolver_ConstraintMultiTranslation::getAttributes(
22 EntityWrapperPtr& theStartPoint, EntityWrapperPtr& theEndPoint,
23 std::list< std::list<EntityWrapperPtr> >& theEntities)
25 DataPtr aData = myBaseConstraint->data();
26 AttributePtr aStartPointAttr = aData->attribute(SketchPlugin_MultiTranslation::START_POINT_ID());
27 AttributePtr aEndPointAttr = aData->attribute(SketchPlugin_MultiTranslation::END_POINT_ID());
28 if (!aStartPointAttr || !aStartPointAttr->isInitialized() ||
29 !aEndPointAttr || !aEndPointAttr->isInitialized()) {
30 myErrorMsg = SketchSolver_Error::NOT_INITIALIZED();
34 myType = CONSTRAINT_MULTI_TRANSLATION;
36 myStorage->update(aStartPointAttr);
37 theStartPoint = myStorage->entity(aStartPointAttr);
38 myStorage->update(aEndPointAttr);
39 theEndPoint = myStorage->entity(aEndPointAttr);
41 getEntitiesAndCopies(theEntities);
43 //// int aType = SLVS_E_UNKNOWN; // type of created entity
44 //// Slvs_hEntity anEntityID = myGroup->getAttributeId(aStartPointAttr);
45 //// if (anEntityID == SLVS_E_UNKNOWN)
46 //// anEntityID = changeEntity(aStartPointAttr, aType);
47 //// theStartPoint = anEntityID;
48 //// anEntityID = myGroup->getAttributeId(aEndPointAttr);
49 //// if (anEntityID == SLVS_E_UNKNOWN)
50 //// anEntityID = changeEntity(aEndPointAttr, aType);
51 //// theEndPoint = anEntityID;
53 //// // Lists of objects and number of copies
54 //// AttributeRefListPtr anInitialRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
55 //// aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
56 //// myNumberOfObjects = anInitialRefList->size();
57 //// myNumberOfCopies = (size_t) aData->integer(SketchPlugin_MultiTranslation::NUMBER_OF_OBJECTS_ID())->value() - 1;
58 //// if (myNumberOfCopies <= 0)
61 //// AttributeRefListPtr aRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
62 //// myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
64 //// myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
68 //// // Obtain all points of initial features and store them into separate lists
69 //// // containing their translated copies.
70 //// // Also all circles and arc collected too, because they will be constrained by equal radii.
71 //// FeaturePtr aFeature;
72 //// ResultConstructionPtr aRC;
73 //// static const size_t MAX_POINTS = 3;
74 //// std::vector<Slvs_hEntity> aPoints[MAX_POINTS]; // lists of points of features
75 //// std::vector<Slvs_hEntity> anEntities; // list of translated entities
76 //// std::list<ObjectPtr> anObjectList = aRefList->list();
77 //// std::list<ObjectPtr>::iterator anObjectIter = anObjectList.begin();
78 //// while (anObjectIter != anObjectList.end()) {
79 //// for (size_t i = 0; i < MAX_POINTS; i++)
80 //// aPoints[i].clear();
81 //// anEntities.clear();
83 //// for (size_t i = 0; i <= myNumberOfCopies && anObjectIter != anObjectList.end(); i++, anObjectIter++) {
84 //// aFeature = ModelAPI_Feature::feature(*anObjectIter);
87 //// anEntityID = changeEntity(aFeature, aType);
88 //// anEntities.push_back(anEntityID);
89 //// Slvs_Entity anEntity = myStorage->getEntity(anEntityID);
91 //// case SLVS_E_POINT_IN_2D:
92 //// case SLVS_E_POINT_IN_3D:
93 //// aPoints[0].push_back(anEntityID);
95 //// case SLVS_E_LINE_SEGMENT:
96 //// aPoints[0].push_back(anEntity.point[0]); // start point of line
97 //// aPoints[1].push_back(anEntity.point[1]); // end point of line
99 //// case SLVS_E_CIRCLE:
100 //// aPoints[0].push_back(anEntity.point[0]); // center of circle
102 //// case SLVS_E_ARC_OF_CIRCLE:
103 //// aPoints[0].push_back(anEntity.point[0]); // center of arc
104 //// aPoints[1].push_back(anEntity.point[1]); // start point of arc
105 //// aPoints[2].push_back(anEntity.point[2]); // end point of arc
108 //// myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
113 //// for (size_t i = 0; i < MAX_POINTS; ++i)
114 //// if (!aPoints[i].empty())
115 //// thePoints.push_back(aPoints[i]);
116 //// if (!anEntities.empty())
117 //// theEntities.push_back(anEntities);
121 void SketchSolver_ConstraintMultiTranslation::process()
124 if (!myBaseConstraint || !myStorage || myGroupID == GID_UNKNOWN) {
125 /// TODO: Put error message here
128 //// if (!mySlvsConstraints.empty()) // some data is changed, update constraint
129 //// update(myBaseConstraint);
131 EntityWrapperPtr aStartPoint, aEndPoint;
132 std::list<std::list<EntityWrapperPtr> > anEntitiesAndCopies;
133 getAttributes(aStartPoint, aEndPoint, anEntitiesAndCopies);
134 if (!myErrorMsg.empty())
137 //// // Create translation line
138 //// if (myTranslationLine == SLVS_E_UNKNOWN) {
139 //// Slvs_Entity aTranslationLine = Slvs_MakeLineSegment(SLVS_E_UNKNOWN, myGroup->getId(),
140 //// myGroup->getWorkplaneId(), aStartPoint, aEndPoint);
141 //// aTranslationLine.h = myStorage->addEntity(aTranslationLine);
142 //// myTranslationLine = aTranslationLine.h;
144 //// Slvs_Entity aTranslationLine = myStorage->getEntity(myTranslationLine);
145 //// if (aTranslationLine.point[0] != aStartPoint || aTranslationLine.point[1] != aEndPoint) {
146 //// aTranslationLine.point[0] = aStartPoint;
147 //// aTranslationLine.point[1] = aEndPoint;
148 //// myStorage->updateEntity(aTranslationLine);
152 BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
153 std::list<ConstraintWrapperPtr> aTransConstraints;
155 std::list< std::list<EntityWrapperPtr> >::iterator anEntIt = anEntitiesAndCopies.begin();
156 for (; anEntIt != anEntitiesAndCopies.end(); ++anEntIt) {
157 std::list<ConstraintWrapperPtr> aNewConstraints =
158 aBuilder->createConstraint(myBaseConstraint, myGroupID, mySketchID, myType,
159 0.0, aStartPoint, aEndPoint, *anEntIt);
160 aTransConstraints.insert(aTransConstraints.end(), aNewConstraints.begin(), aNewConstraints.end());
162 myStorage->addConstraint(myBaseConstraint, aTransConstraints);
165 //// processEntities(anEntitiesAndCopies);
169 ////void SketchSolver_ConstraintMultiTranslation::adjustConstraint()
174 //// Slvs_Entity aTranslationLine = myStorage->getEntity(myTranslationLine);
175 //// Slvs_hConstraint aFixed; // temporary variable
176 //// // Set the translation line unchanged during constraint recalculation
177 //// for (int i = 0; i < 2; i++) {
178 //// if (myStorage->isPointFixed(aTranslationLine.point[i], aFixed, true))
180 //// Slvs_Constraint aConstraint = Slvs_MakeConstraint(
181 //// SLVS_E_UNKNOWN, myGroup->getId(), SLVS_C_WHERE_DRAGGED, myGroup->getWorkplaneId(), 0.0,
182 //// aTranslationLine.point[i], SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN);
183 //// aConstraint.h = myStorage->addConstraint(aConstraint);
184 //// myStorage->addTemporaryConstraint(aConstraint.h);
187 //// // Check if the distance between point is 0, no need to resolve constraints (just wait another values)
189 //// for (int i = 0; i < 2; i++) {
190 //// Slvs_Entity aPnt = myStorage->getEntity(aTranslationLine.point[i]);
191 //// aXY[2*i] = myStorage->getParameter(aPnt.param[0]).val;
192 //// aXY[2*i+1] = myStorage->getParameter(aPnt.param[1]).val;
194 //// myDelta[0] = aXY[2] - aXY[0];
195 //// myDelta[1] = aXY[3] - aXY[1];
196 //// if (fabs(myDelta[0]) + fabs(myDelta[1]) < tolerance) {
197 //// myStorage->setNeedToResolve(false);
201 //// SketchSolver_ConstraintMulti::adjustConstraint();
204 ////void SketchSolver_ConstraintMultiTranslation::getRelative(
205 //// double theAbsX, double theAbsY, double& theRelX, double& theRelY)
207 //// theRelX = theAbsX;
208 //// theRelY = theAbsY;
211 ////void SketchSolver_ConstraintMultiTranslation::getAbsolute(
212 //// double theRelX, double theRelY, double& theAbsX, double& theAbsY)
214 //// theAbsX = theRelX;
215 //// theAbsY = theRelY;
218 ////void SketchSolver_ConstraintMultiTranslation::transformRelative(double& theX, double& theY)
220 //// // translate coordinates
221 //// theX += myDelta[0];
222 //// theY += myDelta[1];
225 const std::string& SketchSolver_ConstraintMultiTranslation::nameNbObjects()
227 return SketchPlugin_MultiTranslation::NUMBER_OF_OBJECTS_ID();