1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: SketchPlugin_ConstraintFillet.cpp
4 // Created: 19 Mar 2015
5 // Author: Artem ZHIDKOV
7 #include "SketchPlugin_ConstraintFillet.h"
9 #include <GeomAPI_Dir2d.h>
10 #include <GeomAPI_Pnt2d.h>
11 #include <GeomAPI_XY.h>
12 #include <GeomDataAPI_Point2D.h>
13 #include <ModelAPI_AttributeDouble.h>
14 #include <ModelAPI_AttributeRefAttr.h>
15 #include <ModelAPI_AttributeRefList.h>
16 #include <ModelAPI_Data.h>
17 #include <ModelAPI_Events.h>
18 #include <ModelAPI_ResultConstruction.h>
19 #include <ModelAPI_Session.h>
20 #include <ModelAPI_Validator.h>
22 #include <SketchPlugin_Arc.h>
23 #include <SketchPlugin_Line.h>
24 #include <SketchPlugin_Sketch.h>
25 #include <SketchPlugin_ConstraintCoincidence.h>
26 #include <SketchPlugin_ConstraintTangent.h>
27 #include <SketchPlugin_ConstraintRadius.h>
29 #include <SketcherPrs_Factory.h>
31 #include <Config_PropManager.h>
32 #include <Events_Loop.h>
34 static const std::string PREVIOUS_VALUE("FilletPreviousRadius");
36 /// \brief Attract specified point on theNewArc to the attribute of theFeature
37 static void recalculateAttributes(FeaturePtr theNewArc, const std::string& theNewArcAttribute,
38 FeaturePtr theFeature, const std::string& theFeatureAttribute);
40 /// \brief Calculates center of fillet arc and coordinates of tangency points
41 static void calculateFilletCenter(FeaturePtr theFeatureA, FeaturePtr theFeatureB,
42 double theRadius, bool theNotInversed[2],
43 std::shared_ptr<GeomAPI_XY>& theCenter,
44 std::shared_ptr<GeomAPI_XY>& theTangentA,
45 std::shared_ptr<GeomAPI_XY>& theTangentB);
48 SketchPlugin_ConstraintFillet::SketchPlugin_ConstraintFillet()
52 void SketchPlugin_ConstraintFillet::initAttributes()
54 data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId());
55 data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
56 data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId());
57 data()->addAttribute(SketchPlugin_Constraint::ENTITY_C(), ModelAPI_AttributeRefList::typeId());
58 data()->addAttribute(PREVIOUS_VALUE, ModelAPI_AttributeDouble::typeId());
59 // initialize attribute not applicable for user
60 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), SketchPlugin_Constraint::ENTITY_C());
61 data()->attribute(PREVIOUS_VALUE)->setInitialized();
62 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(PREVIOUS_VALUE))->setValue(0.0);
65 void SketchPlugin_ConstraintFillet::execute()
67 // the viewer update should be blocked in order to avoid the temporaty fillet sub-features visualization
68 // before they are processed by the solver
69 //std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
70 // new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)));
71 //Events_Loop::loop()->send(aMsg);
73 std::shared_ptr<ModelAPI_Data> aData = data();
74 ResultConstructionPtr aRC;
75 // Check the base objects are initialized
76 double aFilletRadius = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
77 aData->attribute(SketchPlugin_Constraint::VALUE()))->value();
78 AttributeRefAttrPtr aBaseA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
79 aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
80 AttributeRefAttrPtr aBaseB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
81 aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
82 if (!aBaseA->isInitialized() || !aBaseB->isInitialized() ||
83 !aBaseA->isObject() || !aBaseB->isObject())
85 // Check the fillet shapes is not initialized yet
86 AttributeRefListPtr aRefListOfFillet = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
87 aData->attribute(SketchPlugin_Constraint::ENTITY_C()));
88 bool needNewObjects = aRefListOfFillet->size() == 0;
90 // Obtain features for the base objects
91 FeaturePtr aFeatureA, aFeatureB;
92 aRC = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aBaseA->object());
93 if (aRC) aFeatureA = aRC->document()->feature(aRC);
94 aRC = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aBaseB->object());
95 if (aRC) aFeatureB = aRC->document()->feature(aRC);
96 if (!aFeatureA || !aFeatureB)
99 FeaturePtr aNewFeatureA, aNewFeatureB, aNewArc;
100 if (needNewObjects) {
101 // Create list of objects composing a fillet
103 aNewFeatureA = sketch()->addFeature(aFeatureA->getKind());
104 aFeatureA->data()->copyTo(aNewFeatureA->data());
106 aNewFeatureB = sketch()->addFeature(aFeatureB->getKind());
107 aFeatureB->data()->copyTo(aNewFeatureB->data());
108 // create filleting arc (it will be attached to the list later)
109 aNewArc = sketch()->addFeature(SketchPlugin_Arc::ID());
111 // Obtain features from the list
112 std::list<ObjectPtr> aNewFeatList = aRefListOfFillet->list();
113 std::list<ObjectPtr>::iterator aFeatIt = aNewFeatList.begin();
114 aNewFeatureA = ModelAPI_Feature::feature(*aFeatIt++);
115 aNewFeatureB = ModelAPI_Feature::feature(*aFeatIt++);
116 aNewArc = ModelAPI_Feature::feature(*aFeatIt);
119 // Calculate arc attributes
120 static const int aNbFeatures = 2;
121 FeaturePtr aFeature[aNbFeatures] = {aFeatureA, aFeatureB};
122 FeaturePtr aNewFeature[aNbFeatures] = {aNewFeatureA, aNewFeatureB};
123 std::shared_ptr<GeomAPI_Dir2d> aTangentDir[aNbFeatures]; // tangent directions of the features in coincident point
124 bool isStart[aNbFeatures]; // indicates which point the features share
125 std::shared_ptr<GeomAPI_Pnt2d> aStartEndPnt[aNbFeatures * 2]; // first pair of points relate to first feature, second pair - to second
126 std::string aFeatAttributes[aNbFeatures * 2]; // attributes of features
127 for (int i = 0; i < aNbFeatures; i++) {
128 std::string aStartAttr, aEndAttr;
129 if (aNewFeature[i]->getKind() == SketchPlugin_Line::ID()) {
130 aStartAttr = SketchPlugin_Line::START_ID();
131 aEndAttr = SketchPlugin_Line::END_ID();
132 } else if (aNewFeature[i]->getKind() == SketchPlugin_Arc::ID()) {
133 aStartAttr = SketchPlugin_Arc::START_ID();
134 aEndAttr = SketchPlugin_Arc::END_ID();
135 } else { // wrong argument
136 aRefListOfFillet->remove(aNewFeatureA);
137 aRefListOfFillet->remove(aNewFeatureB);
138 aRefListOfFillet->remove(aNewArc);
141 aFeatAttributes[2*i] = aStartAttr;
142 aStartEndPnt[2*i] = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
143 aFeature[i]->attribute(aStartAttr))->pnt();
144 aFeatAttributes[2*i+1] = aEndAttr;
145 aStartEndPnt[2*i+1] = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
146 aFeature[i]->attribute(aEndAttr))->pnt();
148 for (int i = 0; i < aNbFeatures; i++) {
150 for (; j < 2 * aNbFeatures; j++)
151 if (aStartEndPnt[i]->distance(aStartEndPnt[j]) < 1.e-10) {
153 isStart[1] = j==aNbFeatures;
156 if (j < 2 * aNbFeatures)
159 // tangent directions of the features
160 for (int i = 0; i < aNbFeatures; i++) {
161 std::shared_ptr<GeomAPI_XY> aDir;
162 if (aNewFeature[i]->getKind() == SketchPlugin_Line::ID()) {
163 aDir = aStartEndPnt[2*i+1]->xy()->decreased(aStartEndPnt[2*i]->xy());
165 aDir = aDir->multiplied(-1.0);
166 } else if (aNewFeature[i]->getKind() == SketchPlugin_Arc::ID()) {
167 std::shared_ptr<GeomAPI_Pnt2d> aCenterPoint =
168 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
169 aNewFeature[i]->attribute(SketchPlugin_Arc::CENTER_ID()))->pnt();
170 aDir = isStart[i] ? aStartEndPnt[2*i]->xy() : aStartEndPnt[2*i+1]->xy();
171 aDir = aDir->decreased(aCenterPoint->xy());
173 double x = aDir->x();
174 double y = aDir->y();
178 aDir = aDir->multiplied(-1.0);
180 aTangentDir[i] = std::shared_ptr<GeomAPI_Dir2d>(new GeomAPI_Dir2d(aDir));
183 // Wait all constraints being created, then send update events
184 static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
185 bool isUpdateFlushed = Events_Loop::loop()->isFlushed(anUpdateEvent);
187 Events_Loop::loop()->setFlushed(anUpdateEvent, false);
189 // By default, the start point of fillet arc is connected to FeatureA,
190 // and the end point - to FeatureB. But when the angle between TangentDirA and
191 // TangentDirB greater 180 degree, the sequaence of features need to be reversed.
192 double cosBA = aTangentDir[0]->cross(aTangentDir[1]); // cos(B-A), where A and B - angles between corresponding tanget direction and the X axis
193 bool isReversed = cosBA > 0.0;
195 // Calculate fillet arc parameters
196 std::shared_ptr<GeomAPI_XY> aCenter, aTangentPntA, aTangentPntB;
197 calculateFilletCenter(aFeatureA, aFeatureB, aFilletRadius, isStart, aCenter, aTangentPntA, aTangentPntB);
199 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
200 aNewFeatureA->attribute(aFeatAttributes[isStart[0] ? 0 : 1]))->setValue(
201 aTangentPntA->x(), aTangentPntA->y());
202 aNewFeatureA->execute();
203 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
204 aNewFeatureB->attribute(aFeatAttributes[2 + (isStart[1] ? 0 : 1)]))->setValue(
205 aTangentPntB->x(), aTangentPntB->y());
206 aNewFeatureB->execute();
208 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
209 aNewArc->attribute(SketchPlugin_Arc::CENTER_ID()))->setValue(
210 aCenter->x(), aCenter->y());
212 std::shared_ptr<GeomAPI_XY> aTmp = aTangentPntA;
213 aTangentPntA = aTangentPntB;
216 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
217 aNewArc->attribute(SketchPlugin_Arc::START_ID()))->setValue(aTangentPntA->x(), aTangentPntA->y());
218 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
219 aNewArc->attribute(SketchPlugin_Arc::END_ID()))->setValue(aTangentPntB->x(), aTangentPntB->y());
222 if (needNewObjects) {
223 // attach new arc to the list
224 aRefListOfFillet->append(aNewFeatureA->lastResult());
225 aRefListOfFillet->append(aNewFeatureB->lastResult());
226 aRefListOfFillet->append(aNewArc->lastResult());
228 // Create list of additional constraints:
229 // 1. Coincidence of boundary points of features (copied lines/arcs) and fillet arc
231 FeaturePtr aConstraint = sketch()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
232 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
233 aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
234 aRefAttr->setAttr(aNewArc->attribute(SketchPlugin_Arc::START_ID()));
235 aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
236 aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
237 int aFeatInd = isReversed ? 1 : 0;
238 int anAttrInd = (isReversed ? 2 : 0) + (isStart[isReversed ? 1 : 0] ? 0 : 1);
239 aRefAttr->setAttr(aNewFeature[aFeatInd]->attribute(aFeatAttributes[anAttrInd]));
240 recalculateAttributes(aNewArc, SketchPlugin_Arc::START_ID(), aNewFeature[aFeatInd], aFeatAttributes[anAttrInd]);
241 aConstraint->execute();
242 ModelAPI_EventCreator::get()->sendUpdated(aConstraint, anUpdateEvent);
244 aConstraint = sketch()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
245 aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
246 aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
247 aRefAttr->setAttr(aNewArc->attribute(SketchPlugin_Arc::END_ID()));
248 aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
249 aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
250 aFeatInd = isReversed ? 0 : 1;
251 anAttrInd = (isReversed ? 0 : 2) + (isStart[isReversed ? 0 : 1] ? 0 : 1);
252 aRefAttr->setAttr(aNewFeature[aFeatInd]->attribute(aFeatAttributes[anAttrInd]));
253 recalculateAttributes(aNewArc, SketchPlugin_Arc::END_ID(), aNewFeature[aFeatInd], aFeatAttributes[anAttrInd]);
254 aConstraint->execute();
255 ModelAPI_EventCreator::get()->sendUpdated(aConstraint, anUpdateEvent);
256 // 2. Fillet arc radius
257 aConstraint = sketch()->addFeature(SketchPlugin_ConstraintRadius::ID());
258 aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
259 aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
260 aRefAttr->setObject(aNewArc->lastResult());
261 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
262 aConstraint->attribute(SketchPlugin_Constraint::VALUE()))->setValue(aFilletRadius);
263 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
264 aConstraint->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()))->setValue(
265 isStart[0] ? aStartEndPnt[0] : aStartEndPnt[1]);
266 aConstraint->execute();
267 ModelAPI_EventCreator::get()->sendUpdated(aConstraint, anUpdateEvent);
268 // 3. Tangency of fillet arc and features
269 for (int i = 0; i < aNbFeatures; i++) {
270 aConstraint = sketch()->addFeature(SketchPlugin_ConstraintTangent::ID());
271 aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
272 aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
273 aRefAttr->setObject(aNewArc->lastResult());
274 aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
275 aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
276 bool isArc = aNewFeature[i]->getKind() == SketchPlugin_Arc::ID();
277 aRefAttr->setObject(isArc ? aNewFeature[i]->lastResult() : aNewFeature[i]->firstResult());
278 aConstraint->execute();
279 ModelAPI_EventCreator::get()->sendUpdated(aConstraint, anUpdateEvent);
281 // 4. Coincidence of free boundaries of base and copied features
282 for (int i = 0; i < aNbFeatures; i++) {
283 anAttrInd = 2*i + (isStart[i] ? 1 : 0);
284 aConstraint = sketch()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
285 aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
286 aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
287 aRefAttr->setAttr(aFeature[i]->attribute(aFeatAttributes[anAttrInd]));
288 aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
289 aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
290 aRefAttr->setAttr(aNewFeature[i]->attribute(aFeatAttributes[anAttrInd]));
292 // 5. Tangent points should be placed on the base features
293 for (int i = 0; i < aNbFeatures; i++) {
294 anAttrInd = 2*i + (isStart[i] ? 0 : 1);
295 aConstraint = sketch()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
296 aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
297 aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
298 aRefAttr->setAttr(aNewFeature[i]->attribute(aFeatAttributes[anAttrInd]));
299 aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
300 aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
301 aRefAttr->setObject(aFeature[i]->lastResult());
303 // make base features auxiliary
304 aFeatureA->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->setValue(true);
305 aFeatureB->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->setValue(true);
307 // Update radius value
308 int aNbSubs = sketch()->numberOfSubs();
309 FeaturePtr aSubFeature;
310 for (int aSub = 0; aSub < aNbSubs; aSub++) {
311 aSubFeature = sketch()->subFeature(aSub);
312 if (aSubFeature->getKind() != SketchPlugin_ConstraintRadius::ID())
314 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
315 aSubFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
316 if (!aRefAttr || !aRefAttr->isObject())
318 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
319 if (aFeature == aNewArc) {
320 AttributeDoublePtr aRadius = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
321 aSubFeature->attribute(SketchPlugin_Constraint::VALUE()));
322 aRadius->setValue(aFilletRadius);
328 // send events to update the sub-features by the solver
330 Events_Loop::loop()->setFlushed(anUpdateEvent, true);
332 // the viewer update should be unblocked in order after the fillet features
333 // are processed by the solver
334 //aMsg = std::shared_ptr<Events_Message>(
335 // new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)));
336 //Events_Loop::loop()->send(aMsg);
339 AISObjectPtr SketchPlugin_ConstraintFillet::getAISObject(AISObjectPtr thePrevious)
344 AISObjectPtr anAIS = thePrevious;
345 /// TODO: Equal constraint presentation should be put here
349 bool SketchPlugin_ConstraintFillet::isMacro() const
355 // ========= Auxiliary functions =================
356 void recalculateAttributes(FeaturePtr theNewArc, const std::string& theNewArcAttribute,
357 FeaturePtr theFeature, const std::string& theFeatureAttribute)
359 std::shared_ptr<GeomAPI_Pnt2d> anArcPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
360 theNewArc->attribute(theNewArcAttribute))->pnt();
361 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
362 theFeature->attribute(theFeatureAttribute))->setValue(anArcPoint->x(), anArcPoint->y());
366 void possibleFilletCenterLineLine(
367 std::shared_ptr<GeomAPI_XY> thePointA, std::shared_ptr<GeomAPI_Dir2d> theDirA,
368 std::shared_ptr<GeomAPI_XY> thePointB, std::shared_ptr<GeomAPI_Dir2d> theDirB,
369 double theRadius, std::list< std::shared_ptr<GeomAPI_XY> >& theCenters)
371 std::shared_ptr<GeomAPI_Dir2d> aDirAT(new GeomAPI_Dir2d(-theDirA->y(), theDirA->x()));
372 std::shared_ptr<GeomAPI_Dir2d> aDirBT(new GeomAPI_Dir2d(-theDirB->y(), theDirB->x()));
373 std::shared_ptr<GeomAPI_XY> aPntA, aPntB;
374 double aDet = theDirA->cross(theDirB);
375 for (double aStepA = -1.0; aStepA <= 1.0; aStepA += 2.0) {
376 aPntA = thePointA->added(aDirAT->xy()->multiplied(aStepA * theRadius));
377 for (double aStepB = -1.0; aStepB <= 1.0; aStepB += 2.0) {
378 aPntB = thePointB->added(aDirBT->xy()->multiplied(aStepB * theRadius));
379 double aVX = aDirAT->xy()->dot(aPntA);
380 double aVY = aDirBT->xy()->dot(aPntB);
381 std::shared_ptr<GeomAPI_XY> aPoint(new GeomAPI_XY(
382 (theDirB->x() * aVX - theDirA->x() * aVY) / aDet,
383 (theDirB->y() * aVX - theDirA->y() * aVY) / aDet));
384 theCenters.push_back(aPoint);
389 void calculateFilletCenter(FeaturePtr theFeatureA, FeaturePtr theFeatureB,
390 double theRadius, bool theNotInversed[2],
391 std::shared_ptr<GeomAPI_XY>& theCenter,
392 std::shared_ptr<GeomAPI_XY>& theTangentA,
393 std::shared_ptr<GeomAPI_XY>& theTangentB)
395 if (theFeatureA->getKind() == SketchPlugin_Line::ID() &&
396 theFeatureB->getKind() == SketchPlugin_Line::ID()) {
397 std::shared_ptr<GeomAPI_XY> aStartA, aEndA, aStartB, aEndB;
398 std::shared_ptr<GeomDataAPI_Point2D> aStartPoint, aEndPoint;
400 aStartPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
401 theFeatureA->attribute(SketchPlugin_Line::START_ID()));
402 aEndPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
403 theFeatureA->attribute(SketchPlugin_Line::END_ID()));
404 aStartA = std::shared_ptr<GeomAPI_XY>(theNotInversed[0] ?
405 new GeomAPI_XY(aStartPoint->x(), aStartPoint->y()) :
406 new GeomAPI_XY(aEndPoint->x(), aEndPoint->y()));
407 aEndA = std::shared_ptr<GeomAPI_XY>(theNotInversed[0] ?
408 new GeomAPI_XY(aEndPoint->x(), aEndPoint->y()) :
409 new GeomAPI_XY(aStartPoint->x(), aStartPoint->y()));
411 aStartPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
412 theFeatureB->attribute(SketchPlugin_Line::START_ID()));
413 aEndPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
414 theFeatureB->attribute(SketchPlugin_Line::END_ID()));
415 aStartB = std::shared_ptr<GeomAPI_XY>(theNotInversed[1] ?
416 new GeomAPI_XY(aStartPoint->x(), aStartPoint->y()) :
417 new GeomAPI_XY(aEndPoint->x(), aEndPoint->y()));
418 aEndB = std::shared_ptr<GeomAPI_XY>(theNotInversed[1] ?
419 new GeomAPI_XY(aEndPoint->x(), aEndPoint->y()) :
420 new GeomAPI_XY(aStartPoint->x(), aStartPoint->y()));
422 std::shared_ptr<GeomAPI_Dir2d> aDirA(new GeomAPI_Dir2d(aEndA->decreased(aStartA)));
423 std::shared_ptr<GeomAPI_Dir2d> aDirB(new GeomAPI_Dir2d(aEndB->decreased(aStartB)));
424 std::shared_ptr<GeomAPI_Dir2d> aDirAT(new GeomAPI_Dir2d(-aDirA->y(), aDirA->x()));
425 std::shared_ptr<GeomAPI_Dir2d> aDirBT(new GeomAPI_Dir2d(-aDirB->y(), aDirB->x()));
427 // get and filter possible centers
428 std::list< std::shared_ptr<GeomAPI_XY> > aSuspectCenters;
429 possibleFilletCenterLineLine(aStartA, aDirA, aStartB, aDirB, theRadius, aSuspectCenters);
431 std::list< std::shared_ptr<GeomAPI_XY> >::iterator anIt = aSuspectCenters.begin();
432 for (; anIt != aSuspectCenters.end(); anIt++) {
433 aDot = aDirAT->xy()->dot(aStartA->decreased(*anIt));
434 theTangentA = (*anIt)->added(aDirAT->xy()->multiplied(aDot));
435 if (theTangentA->decreased(aStartA)->dot(aDirA->xy()) < 0.0)
436 continue; // incorrect position
437 aDot = aDirBT->xy()->dot(aStartB->decreased(*anIt));
438 theTangentB = (*anIt)->added(aDirBT->xy()->multiplied(aDot));
439 if (theTangentB->decreased(aStartB)->dot(aDirB->xy()) < 0.0)
440 continue; // incorrect position
441 // the center is found, stop searching