]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp
Salome HOME
First phase of SketchSolver refactoring
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintMultiTranslation.cpp
1 #include <SketchSolver_ConstraintMultiTranslation.h>
2 #include <SketchSolver_Error.h>
3 #include <SketchSolver_Manager.h>
4
5 ////#include <SketchPlugin_Arc.h>
6 #include <SketchPlugin_MultiTranslation.h>
7 ////
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>
14 ////
15 ////#include <GeomAPI_Dir2d.h>
16 ////#include <GeomAPI_XY.h>
17 ////
18 ////#include <math.h>
19
20
21 void SketchSolver_ConstraintMultiTranslation::getAttributes(
22     EntityWrapperPtr& theStartPoint, EntityWrapperPtr& theEndPoint,
23     std::list< std::list<EntityWrapperPtr> >& theEntities)
24 {
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();
31     return;
32   }
33
34   myType = CONSTRAINT_MULTI_TRANSLATION;
35
36   myStorage->update(aStartPointAttr);
37   theStartPoint = myStorage->entity(aStartPointAttr);
38   myStorage->update(aEndPointAttr);
39   theEndPoint = myStorage->entity(aEndPointAttr);
40
41   getEntitiesAndCopies(theEntities);
42
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;
52 ////
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)
59 ////    return;
60 ////
61 ////  AttributeRefListPtr aRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
62 ////      myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
63 ////  if (!aRefList) {
64 ////    myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
65 ////    return;
66 ////  }
67 ////
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();
82 ////
83 ////    for (size_t i = 0; i <= myNumberOfCopies && anObjectIter != anObjectList.end(); i++, anObjectIter++) {
84 ////      aFeature = ModelAPI_Feature::feature(*anObjectIter);
85 ////      if (!aFeature)
86 ////        continue;
87 ////      anEntityID = changeEntity(aFeature, aType);
88 ////      anEntities.push_back(anEntityID);
89 ////      Slvs_Entity anEntity = myStorage->getEntity(anEntityID);
90 ////      switch (aType) {
91 ////      case SLVS_E_POINT_IN_2D:
92 ////      case SLVS_E_POINT_IN_3D:
93 ////        aPoints[0].push_back(anEntityID);
94 ////        break;
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
98 ////        break;
99 ////      case SLVS_E_CIRCLE:
100 ////        aPoints[0].push_back(anEntity.point[0]); // center of circle
101 ////        break;
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
106 ////        break;
107 ////      default:
108 ////        myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
109 ////        return;
110 ////      }
111 ////    }
112 ////
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);
118 ////  }
119 }
120
121 void SketchSolver_ConstraintMultiTranslation::process()
122 {
123   cleanErrorMsg();
124   if (!myBaseConstraint || !myStorage || myGroupID == GID_UNKNOWN) {
125     /// TODO: Put error message here
126     return;
127   }
128 ////  if (!mySlvsConstraints.empty()) // some data is changed, update constraint
129 ////    update(myBaseConstraint);
130
131   EntityWrapperPtr aStartPoint, aEndPoint;
132   std::list<std::list<EntityWrapperPtr> > anEntitiesAndCopies;
133   getAttributes(aStartPoint, aEndPoint, anEntitiesAndCopies);
134   if (!myErrorMsg.empty())
135     return;
136
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;
143 ////  } else {
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);
149 ////    }
150 ////  }
151
152   BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
153   std::list<ConstraintWrapperPtr> aTransConstraints;
154
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());
161   }
162   myStorage->addConstraint(myBaseConstraint, aTransConstraints);
163
164   myAdjusted = false;
165 ////  processEntities(anEntitiesAndCopies);
166   adjustConstraint();
167 }
168
169 ////void SketchSolver_ConstraintMultiTranslation::adjustConstraint()
170 ////{
171 ////  if (myAdjusted)
172 ////    return;
173 ////
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))
179 ////      continue;
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);
185 ////  }
186 ////
187 ////  // Check if the distance between point is 0, no need to resolve constraints (just wait another values)
188 ////  double aXY[4];
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;
193 ////  }
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);
198 ////    return;
199 ////  }
200 ////
201 ////  SketchSolver_ConstraintMulti::adjustConstraint();
202 ////}
203 ////
204 ////void SketchSolver_ConstraintMultiTranslation::getRelative(
205 ////    double theAbsX, double theAbsY, double& theRelX, double& theRelY)
206 ////{
207 ////  theRelX = theAbsX;
208 ////  theRelY = theAbsY;
209 ////}
210 ////
211 ////void SketchSolver_ConstraintMultiTranslation::getAbsolute(
212 ////    double theRelX, double theRelY, double& theAbsX, double& theAbsY)
213 ////{
214 ////  theAbsX = theRelX;
215 ////  theAbsY = theRelY;
216 ////}
217 ////
218 ////void SketchSolver_ConstraintMultiTranslation::transformRelative(double& theX, double& theY)
219 ////{
220 ////  // translate coordinates
221 ////  theX += myDelta[0];
222 ////  theY += myDelta[1];
223 ////}
224
225 const std::string& SketchSolver_ConstraintMultiTranslation::nameNbObjects()
226 {
227   return SketchPlugin_MultiTranslation::NUMBER_OF_OBJECTS_ID();
228 }