1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <Config_PropManager.h>
22 #include <GeomAlgoAPI_CompoundBuilder.h>
23 #include <GeomAlgoAPI_EdgeBuilder.h>
24 #include <GeomAlgoAPI_FaceBuilder.h>
26 #include <GeomAPI_Dir.h>
27 #include <GeomAPI_Lin.h>
28 #include <GeomAPI_PlanarEdges.h>
29 #include <GeomAPI_ShapeIterator.h>
30 #include <GeomAPI_Vertex.h>
32 #include <GeomDataAPI_Point2D.h>
33 #include <GeomAlgoAPI_PointBuilder.h>
35 #include <ModelAPI_AttributeRefList.h>
36 #include <ModelAPI_AttributeString.h>
37 #include <ModelAPI_Data.h>
38 #include <ModelAPI_Document.h>
39 #include <ModelAPI_Feature.h>
40 #include <ModelAPI_Object.h>
41 #include <ModelAPI_ResultConstruction.h>
42 #include <ModelAPI_Validator.h>
43 #include <ModelAPI_Session.h>
44 #include <ModelAPI_Events.h>
46 #include <SketchPlugin_Sketch.h>
47 #include <SketchPlugin_Feature.h>
48 #include <SketchPlugin_IntersectionPoint.h>
49 #include <SketchPlugin_Projection.h>
50 #include <SketchPlugin_SketchEntity.h>
51 #include <SketchPlugin_Tools.h>
53 #include <Events_InfoMessage.h>
54 #include <Events_Loop.h>
61 SketchPlugin_Sketch::SketchPlugin_Sketch()
65 void SketchPlugin_Sketch::initAttributes()
67 data()->addAttribute(SketchPlugin_Sketch::ORIGIN_ID(), GeomDataAPI_Point::typeId());
68 data()->addAttribute(SketchPlugin_Sketch::DIRX_ID(), GeomDataAPI_Dir::typeId());
69 data()->addAttribute(SketchPlugin_Sketch::NORM_ID(), GeomDataAPI_Dir::typeId());
70 data()->addAttribute(SketchPlugin_Sketch::FEATURES_ID(), ModelAPI_AttributeRefList::typeId());
71 // the selected face, base for the sketcher plane, not obligatory
72 data()->addAttribute(SketchPlugin_SketchEntity::EXTERNAL_ID(),
73 ModelAPI_AttributeSelection::typeId());
74 ModelAPI_Session::get()->validators()->registerNotObligatory(
75 getKind(), SketchPlugin_SketchEntity::EXTERNAL_ID());
76 data()->addAttribute(SketchPlugin_Sketch::SOLVER_ERROR(), ModelAPI_AttributeString::typeId());
77 ModelAPI_Session::get()->validators()->registerNotObligatory(
78 getKind(), SketchPlugin_Sketch::SOLVER_ERROR());
79 data()->addAttribute(SketchPlugin_Sketch::SOLVER_DOF(), ModelAPI_AttributeString::typeId());
80 ModelAPI_Session::get()->validators()->registerNotObligatory(
81 getKind(), SketchPlugin_Sketch::SOLVER_DOF());
84 void SketchPlugin_Sketch::execute()
86 if (!data()->isValid())
88 std::shared_ptr<ModelAPI_AttributeRefList> aRefList = std::dynamic_pointer_cast<
89 ModelAPI_AttributeRefList>(data()->attribute(SketchPlugin_Sketch::FEATURES_ID()));
91 std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
92 data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
93 std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
94 data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
95 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
96 data()->attribute(SketchPlugin_Sketch::NORM_ID()));
98 std::list<ObjectPtr> aFeatures = aRefList->list();
99 if (aFeatures.empty()) // actually, this must be avoided by the validators
102 std::list<ObjectPtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
103 std::shared_ptr<SketchPlugin_Feature> aFeature;
104 std::list<std::shared_ptr<GeomAPI_Shape> > aFeaturesPreview;
105 for (; anIt != aLast; anIt++) {
106 aFeature = std::dynamic_pointer_cast<SketchPlugin_Feature>(*anIt);
108 if (!aFeature->sketch()) // on load document the back references are missed
109 aFeature->setSketch(this);
110 // do not include into the result the external edges with disabled flag "Include into result"
111 if (aFeature->data()->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())) {
112 if (aFeature->data()->selection(SketchPlugin_SketchEntity::EXTERNAL_ID())->context()) {
113 const std::string& anAttrName =
114 aFeature->getKind() == SketchPlugin_Projection::ID() ?
115 SketchPlugin_Projection::INCLUDE_INTO_RESULT() :
116 SketchPlugin_IntersectionPoint::INCLUDE_INTO_RESULT();
117 AttributeBooleanPtr aKeepResult = aFeature->boolean(anAttrName);
118 if (!aKeepResult || !aKeepResult->value())
122 // do not include the construction entities in the result
123 if (aFeature->data()->attribute(SketchPlugin_SketchEntity::AUXILIARY_ID())) {
124 if (aFeature->data()->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value())
128 const std::list<std::shared_ptr<ModelAPI_Result> >& aRes = aFeature->results();
129 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aResIter = aRes.cbegin();
130 for (; aResIter != aRes.cend(); aResIter++) {
131 std::shared_ptr<ModelAPI_ResultConstruction> aConstr = std::dynamic_pointer_cast<
132 ModelAPI_ResultConstruction>(*aResIter);
134 std::shared_ptr<GeomAPI_Shape> aShape = aConstr->shape();
136 aFeaturesPreview.push_back(aShape);
142 // Collect all edges as one big wire
143 std::shared_ptr<GeomAPI_PlanarEdges> aBigWire(new GeomAPI_PlanarEdges);
144 std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator aShapeIt = aFeaturesPreview.begin();
145 for (; aShapeIt != aFeaturesPreview.end(); ++aShapeIt) {
146 aBigWire->addEdge(*aShapeIt);
148 aBigWire->setPlane(anOrigin->pnt(), aDirX->dir(), aNorm->dir());
149 std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
150 aConstr->setShape(aBigWire);
154 std::shared_ptr<ModelAPI_Feature> SketchPlugin_Sketch::addFeature(std::string theID)
156 // Set last feature of the sketch as current feature.
157 // Reason: Changing of parameter through Python API may lead to creation of new features
158 // (e.g. changing number of copies in MultiRotation). If the sketch is not the last
159 // feature in the Object Browser, then new features will be added to the end feature.
160 // Therefore, setting any feature below the sketch as a current feature will disable
161 // these newly created features.
162 std::shared_ptr<ModelAPI_AttributeRefList> aRefList = std::dynamic_pointer_cast<
163 ModelAPI_AttributeRefList>(data()->attribute(SketchPlugin_Sketch::FEATURES_ID()));
164 int aSize = aRefList->size(false);
165 ObjectPtr aLastObject = aSize == 0 ? data()->owner() : aRefList->object(aSize - 1, false);
166 FeaturePtr aLastFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aLastObject);
167 document()->setCurrentFeature(aLastFeature, false);
170 std::shared_ptr<ModelAPI_Feature> aNew = document()->addFeature(theID, false);
172 // the sketch cannot be specified for the macro-features defined in python
173 // like SketchRectangle, so we need to check the type of new feature
174 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
175 std::dynamic_pointer_cast<SketchPlugin_Feature>(aNew);
177 aSketchFeature->setSketch(this);
178 data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->append(aNew);
180 // set as current also after it becomes sub to set correctly enabled for other sketch subs
181 document()->setCurrentFeature(aNew, false);
186 void SketchPlugin_Sketch::removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature)
188 if (!data()->isValid()) // sketch is already removed (case on undo of sketch), sync is not needed
190 AttributeRefListPtr aList = reflist(SketchPlugin_Sketch::FEATURES_ID());
191 // if the object is last, remove it from the list
192 // (needed to skip empty transaction on edit of sketch feature)
193 if (aList->object(aList->size(true) - 1, true) == theFeature) {
194 aList->remove(theFeature);
196 // to keep the persistent sub-elements indexing, do not remove elements from list,
197 // but substitute by nulls
198 aList->substitute(theFeature, ObjectPtr());
202 int SketchPlugin_Sketch::numberOfSubs(bool forTree) const
206 return data()->reflist(FEATURES_ID())->size(false);
209 std::shared_ptr<ModelAPI_Feature> SketchPlugin_Sketch::subFeature(
210 const int theIndex, bool forTree)
215 ObjectPtr anObj = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->object(theIndex, false);
216 FeaturePtr aRes = std::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
220 int SketchPlugin_Sketch::subFeatureId(const int theIndex) const
222 std::shared_ptr<ModelAPI_AttributeRefList> aRefList = std::dynamic_pointer_cast<
223 ModelAPI_AttributeRefList>(data()->attribute(SketchPlugin_Sketch::FEATURES_ID()));
224 std::list<ObjectPtr> aFeatures = aRefList->list();
225 std::list<ObjectPtr>::const_iterator anIt = aFeatures.begin();
226 int aResultIndex = 1; // number of the counted (created) features, started from 1
227 int aFeatureIndex = -1; // number of the not-empty features in the list
228 for (; anIt != aFeatures.end(); anIt++) {
231 if (aFeatureIndex == theIndex)
238 bool SketchPlugin_Sketch::isSub(ObjectPtr theObject) const
240 // check is this feature of result
241 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
243 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
245 aFeature = document()->feature(aRes);
248 return data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->isInList(aFeature);
254 static bool isOrigin(const GeomPointPtr& thePoint, const double theTolerance)
256 return fabs(thePoint->x()) < theTolerance &&
257 fabs(thePoint->y()) < theTolerance &&
258 fabs(thePoint->z()) < theTolerance;
261 static bool isCoordinateAxis(const GeomDirPtr& theDir, const double theTolerance)
263 return fabs(theDir->x() - 1.0) < theTolerance || fabs(theDir->x() + 1.0) < theTolerance ||
264 fabs(theDir->y() - 1.0) < theTolerance || fabs(theDir->y() + 1.0) < theTolerance ||
265 fabs(theDir->z() - 1.0) < theTolerance || fabs(theDir->z() + 1.0) < theTolerance;
268 static bool isCoordinatePlane(const GeomAx3Ptr& thePlane)
270 static const double THE_TOLERANCE = 1.e-7;
274 GeomPointPtr anOrigin = thePlane->origin();
275 GeomDirPtr aNormal = thePlane->normal();
276 GeomDirPtr aDirX = thePlane->dirX();
278 return isOrigin(anOrigin, THE_TOLERANCE) &&
279 isCoordinateAxis(aNormal, THE_TOLERANCE) &&
280 isCoordinateAxis(aDirX, THE_TOLERANCE);
283 void SketchPlugin_Sketch::attributeChanged(const std::string& theID) {
284 if (theID == SketchPlugin_SketchEntity::EXTERNAL_ID()) {
285 AttributeSelectionPtr aSelAttr = selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
286 if (aSelAttr->context().get()) { // update arguments due to the selection value
287 std::shared_ptr<GeomAPI_Shape> aSelection = aSelAttr->value();
288 if (!aSelection.get()) aSelection = aSelAttr->context()->shape();
289 // update the sketch plane
290 std::shared_ptr<GeomAPI_Face> aFace;
291 if (aSelection->isFace()) {
292 aFace = aSelection->face();
293 } else if (aSelection->isCompound()) {
294 GeomAPI_ShapeIterator anIt(aSelection);
295 aFace = anIt.current()->face();
298 std::shared_ptr<GeomAPI_Pln> aPlane = aFace->getPlane();
300 double anA, aB, aC, aD;
301 aPlane->coefficients(anA, aB, aC, aD);
303 // calculate attributes of the sketch
304 std::shared_ptr<GeomAPI_Dir> aNormDir(new GeomAPI_Dir(anA, aB, aC));
305 std::shared_ptr<GeomAPI_XYZ> aCoords = aNormDir->xyz();
306 std::shared_ptr<GeomAPI_XYZ> aZero(new GeomAPI_XYZ(0, 0, 0));
307 aCoords = aCoords->multiplied(-aD * aCoords->distance(aZero));
308 std::shared_ptr<GeomAPI_Pnt> anOrigPnt(new GeomAPI_Pnt(aCoords));
309 // X axis is preferable to be dirX on the sketch
310 // here can not be very small value to avoid very close to X normal axis (issue 595)
311 static const double tol = 0.1;
312 bool isX = fabs(anA) - 1.0 < tol && fabs(aB) < tol && fabs(aC) < tol;
313 std::shared_ptr<GeomAPI_Dir> aTempDir(
314 isX ? new GeomAPI_Dir(0, 1, 0) : new GeomAPI_Dir(1, 0, 0));
315 std::shared_ptr<GeomAPI_Dir> aYDir(new GeomAPI_Dir(aNormDir->cross(aTempDir)));
316 std::shared_ptr<GeomAPI_Dir> aXDir(new GeomAPI_Dir(aYDir->cross(aNormDir)));
318 // update position of the sketch
319 std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast
320 <GeomDataAPI_Point>(data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
321 anOrigin->setValue(anOrigPnt);
322 std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
323 data()->attribute(SketchPlugin_Sketch::NORM_ID()));
324 aNormal->setValue(aNormDir);
325 std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
326 data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
327 aDirX->setValue(aXDir);
328 std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
332 } else if (theID == NORM_ID() || theID == DIRX_ID() || theID == ORIGIN_ID()) {
333 // check if current and previous sketch planes are coordinate planes and they are different
334 GeomAx3Ptr aCurPlane;
335 bool areCoordPlanes = false;
337 aCurPlane = coordinatePlane();
338 areCoordPlanes = isCoordinatePlane(aCurPlane) && isCoordinatePlane(myPlane);
341 // send all sub-elements are also updated: all entities become created on different plane
342 static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
343 std::list<ObjectPtr> aSubs = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->list();
344 std::list<ObjectPtr>::iterator aSub = aSubs.begin();
345 for(; aSub != aSubs.end(); aSub++) {
348 updateCoordinateAxis(*aSub, aCurPlane);
350 ModelAPI_EventCreator::get()->sendUpdated(*aSub, anUpdateEvent);
358 void SketchPlugin_Sketch::createPoint2DResult(ModelAPI_Feature* theFeature,
359 SketchPlugin_Sketch* theSketch,
360 const std::string& theAttributeID, const int theIndex)
362 std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
363 theFeature->attribute(theAttributeID));
365 if (!aPoint || !aPoint->isInitialized())
368 std::shared_ptr<GeomAPI_Pnt> aCenter(theSketch->to3D(aPoint->x(), aPoint->y()));
369 //std::cout<<"Execute circle "<<aCenter->x()<<" "<<aCenter->y()<<" "<<aCenter->z()<<std::endl;
370 // make a visible point
371 std::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::vertex(aCenter);
372 std::shared_ptr<ModelAPI_ResultConstruction> aResult = theFeature->document()->createConstruction(
373 theFeature->data(), theIndex);
374 aResult->setShape(aCenterPointShape);
375 aResult->setIsInHistory(false);
377 theFeature->setResult(aResult, theIndex);
380 FeaturePtr SketchPlugin_Sketch::addUniqueNamedCopiedFeature(FeaturePtr theFeature,
381 SketchPlugin_Sketch* theSketch,
382 const bool theIsCopy)
384 FeaturePtr aNewFeature = theSketch->addFeature(theFeature->getKind());
385 // addFeature generates a unique name for the feature, it caches the name
386 std::string aUniqueFeatureName = aNewFeature->data()->name();
387 // all attribute values are copied\pasted to the new feature, name is not an exception
388 theFeature->data()->copyTo(aNewFeature->data());
389 // external state should not be copied as a new object is an object of the current sketch
390 if (theFeature->selection(SketchPlugin_SketchEntity::EXTERNAL_ID()).get())
391 aNewFeature->selection(SketchPlugin_SketchEntity::EXTERNAL_ID())->setValue(ResultPtr(),
393 aNewFeature->data()->setName(aUniqueFeatureName);
394 // text expressions could block setValue of some attributes
395 SketchPlugin_Tools::clearExpressions(aNewFeature);
396 // Set copy attribute
397 AttributeBooleanPtr anAttr = aNewFeature->data()->boolean(SketchPlugin_SketchEntity::COPY_ID());
399 anAttr->setValue(theIsCopy);
405 std::shared_ptr<GeomAPI_Ax3> SketchPlugin_Sketch::plane(SketchPlugin_Sketch* theSketch)
407 std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
409 std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
410 aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
411 std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
412 aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
413 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
414 aData->attribute(SketchPlugin_Sketch::NORM_ID()));
416 return std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(anOrigin->pnt(), aDirX->dir(), aNorm->dir()));
419 bool SketchPlugin_Sketch::customAction(const std::string& theActionId)
422 if (theActionId == ACTION_REMOVE_EXTERNAL())
423 isOk = removeLinksToExternal();
425 std::string aMsg = "Error: Feature \"%1\" does not support action \"%2\".";
426 Events_InfoMessage("SketchPlugin_Sketch", aMsg).arg(getKind()).arg(theActionId).send();
431 static bool isExternalBased(const FeaturePtr theFeature)
433 return theFeature->getKind() == SketchPlugin_Projection::ID() ||
434 theFeature->getKind() == SketchPlugin_IntersectionPoint::ID();
437 bool SketchPlugin_Sketch::removeLinksToExternal()
439 std::list<FeaturePtr> aRemove;
440 std::list<ObjectPtr> aSubs = reflist(FEATURES_ID())->list();
441 for (std::list<ObjectPtr>::iterator anIt = aSubs.begin(); anIt != aSubs.end(); ++anIt) {
442 FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
445 if (isExternalBased(aFeature)) {
446 // mark feature as to be removed
447 aRemove.push_back(aFeature);
450 AttributeSelectionPtr anExtAttr =
451 aFeature->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
452 ResultPtr anExternal = anExtAttr ? anExtAttr->context() : ResultPtr();
454 FeaturePtr anExtFeature = ModelAPI_Feature::feature(anExternal);
455 if (anExtFeature && isExternalBased(anExtFeature)) {
456 // make result of projection/intersection as non-external,
457 aFeature->selection(SketchPlugin_SketchEntity::EXTERNAL_ID())->setValue(
458 ObjectPtr(), GeomShapePtr());
459 // set feature auxiliary if the parent is not included into sketch result
460 bool isIncludedToSketchResult = false;
461 if (anExtFeature->getKind() == SketchPlugin_Projection::ID()) {
462 isIncludedToSketchResult = anExtFeature->boolean(
463 SketchPlugin_Projection::INCLUDE_INTO_RESULT())->value();
465 if (anExtFeature->getKind() == SketchPlugin_IntersectionPoint::ID()) {
466 isIncludedToSketchResult = anExtFeature->boolean(
467 SketchPlugin_IntersectionPoint::INCLUDE_INTO_RESULT())->value();
470 aFeature->boolean(SketchPlugin_SketchEntity::COPY_ID())->setValue(false);
471 aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->setValue(
472 !isIncludedToSketchResult);
477 for (std::list<FeaturePtr>::iterator anIt = aRemove.begin(); anIt != aRemove.end(); ++anIt)
478 document()->removeFeature(*anIt);
483 static ObjectPtr findAxis(GeomShapePtr theAxisToCompare,
488 if (theAxisToCompare) {
489 ObjectPtr anAxes[] = { theOX, theOY, theOZ };
490 for (int i = 0; i < 3; ++i) {
491 ResultPtr anAx = std::dynamic_pointer_cast<ModelAPI_Result>(anAxes[i]);
492 if (anAx && theAxisToCompare->isEqual(anAx->shape()))
499 static ObjectPtr findAxis(ObjectPtr theAxisToCompare,
504 if (theAxisToCompare == theOX)
506 else if (theAxisToCompare == theOY)
508 else if (theAxisToCompare == theOZ)
510 // nothing helped, search by shape
511 ResultPtr anAxis = std::dynamic_pointer_cast<ModelAPI_Result>(theAxisToCompare);
512 return findAxis(anAxis ? anAxis->shape() : GeomShapePtr(), theOX, theOY, theOZ);
515 GeomShapePtr axisOnNewPlane(ObjectPtr theAxis, GeomAx3Ptr theOldPlane, GeomAx3Ptr theNewPlane)
517 ResultPtr anAxis = std::dynamic_pointer_cast<ModelAPI_Result>(theAxis);
519 return GeomShapePtr();
521 GeomEdgePtr anAxisEdge = anAxis->shape()->edge();
522 GeomLinePtr anAxisLine = anAxisEdge->line();
523 GeomDirPtr anAxisDir = anAxisLine->direction();
525 double aFirstParam, aLastParam;
526 anAxisEdge->getRange(aFirstParam, aLastParam);
528 if (theOldPlane->dirX()->isParallel(anAxisDir))
529 anAxisDir = theNewPlane->dirX();
530 else if (theOldPlane->dirY()->isParallel(anAxisDir))
531 anAxisDir = theNewPlane->dirY();
532 else if (theOldPlane->normal()->isParallel(anAxisDir))
533 anAxisDir = theNewPlane->normal();
535 GeomPointPtr aFirstPoint(new GeomAPI_Pnt(aFirstParam * anAxisDir->x(),
536 aFirstParam * anAxisDir->y(),
537 aFirstParam * anAxisDir->z()));
538 GeomPointPtr aLastPoint(new GeomAPI_Pnt(aLastParam * anAxisDir->x(),
539 aLastParam * anAxisDir->y(),
540 aLastParam * anAxisDir->z()));
541 return GeomAlgoAPI_EdgeBuilder::line(aFirstPoint, aLastPoint);
544 void SketchPlugin_Sketch::updateCoordinateAxis(ObjectPtr theSub, GeomAx3Ptr thePlane)
546 FeaturePtr aFeature = ModelAPI_Feature::feature(theSub);
550 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
551 ObjectPtr anOX = aRootDoc->objectByName(ModelAPI_ResultConstruction::group(), "OX");
552 ObjectPtr anOY = aRootDoc->objectByName(ModelAPI_ResultConstruction::group(), "OY");
553 ObjectPtr anOZ = aRootDoc->objectByName(ModelAPI_ResultConstruction::group(), "OZ");
555 AttributeSelectionPtr anExtFeature;
556 if (aFeature->getKind() == SketchPlugin_Projection::ID())
557 anExtFeature = aFeature->selection(SketchPlugin_Projection::EXTERNAL_FEATURE_ID());
558 else if (aFeature->getKind() == SketchPlugin_IntersectionPoint::ID())
559 anExtFeature = aFeature->selection(SketchPlugin_IntersectionPoint::EXTERNAL_FEATURE_ID());
563 ObjectPtr aContext = anExtFeature->context();
564 GeomShapePtr aShape = anExtFeature->value();
565 if (!aShape) { // selected object is a construction
566 ObjectPtr anAxis = findAxis(aContext, anOX, anOY, anOZ);
567 GeomShapePtr aNewAxis = axisOnNewPlane(anAxis, myPlane, thePlane);
568 anAxis = findAxis(aNewAxis, anOX, anOY, anOZ);
570 anExtFeature->setValue(anAxis, aShape);