X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_Tools.cpp;h=ed69af84a7e5a813b6d50583aa0d06d3d8939f6c;hb=19fc4aa0b7041736b4a099bb1fc3ddc89695a338;hp=8a4c158f3935ca4a311730804b968411d35990c2;hpb=3ada52ad6bce1f69571d9dea97f6631f155681d7;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 8a4c158f3..ed69af84a 100755 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -15,6 +15,8 @@ #include #include +#include + #include #include #include @@ -429,12 +431,44 @@ ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShap Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(theShape), aStart, aEnd); GeomAdaptor_Curve aAdaptor(aCurve); + std::shared_ptr anEdge = std::shared_ptr(new GeomAPI_Edge); + anEdge->setImpl(new TopoDS_Shape(theShape)); if (aAdaptor.GetType() == GeomAbs_Line) { // Create line aMyFeature = theSketch->addFeature(SketchPlugin_Line::ID()); + if (!theObject.get()) { + // There is no selected result + std::shared_ptr aPnt1 = anEdge->firstPoint(); + std::shared_ptr aPnt2 = anEdge->lastPoint(); + std::shared_ptr aPnt2d1 = convertTo2D(theSketch, aPnt1); + std::shared_ptr aPnt2d2 = convertTo2D(theSketch, aPnt2); + + std::shared_ptr aData = aMyFeature->data(); + std::shared_ptr aPoint1 = + std::dynamic_pointer_cast(aData->attribute(SketchPlugin_Line::START_ID())); + std::shared_ptr aPoint2 = + std::dynamic_pointer_cast(aData->attribute(SketchPlugin_Line::END_ID())); + + aPoint1->setValue(aPnt2d1); + aPoint2->setValue(aPnt2d2); + + // If this is an axis then its name has to be changed correspondently + std::string aSuffix = ""; + bool aXdir = fabs(aPnt1->x() - aPnt2->x()) > Precision::Confusion(); + bool aYdir = fabs(aPnt1->y() - aPnt2->y()) > Precision::Confusion(); + bool aZdir = fabs(aPnt1->z() - aPnt2->z()) > Precision::Confusion(); + if (aXdir && (!aYdir) && (!aZdir)) + aSuffix = "X"; + else if ((!aXdir) && aYdir && (!aZdir)) + aSuffix = "Y"; + else if ((!aXdir) && (!aYdir) && aZdir) + aSuffix = "Z"; + if (aSuffix.length() > 0) + aData->setName("Axis_" + aSuffix); + aMyFeature->execute(); + + } } else if (aAdaptor.GetType() == GeomAbs_Circle) { - std::shared_ptr anEdge = std::shared_ptr(new GeomAPI_Edge); - anEdge->setImpl(new TopoDS_Shape(theShape)); if (anEdge->isArc()) { // Create arc aMyFeature = theSketch->addFeature(SketchPlugin_Arc::ID()); @@ -451,7 +485,10 @@ ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShap (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); ResultPtr aRes = std::dynamic_pointer_cast(theObject); - if (anAttr && aRes) { + if (!aRes.get()) { + aRes = aMyFeature->firstResult(); + } + if (anAttr.get() && aRes.get()) { std::shared_ptr anEdge(new GeomAPI_Shape); anEdge->setImpl(new TopoDS_Shape(theShape)); @@ -478,7 +515,29 @@ ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShap (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); ResultPtr aRes = std::dynamic_pointer_cast(theObject); - if (anAttr && aRes) { + if (!aRes.get()) { + // If the point is selected not from Result object + std::shared_ptr aShape = + std::shared_ptr(new GeomAPI_Shape()); + aShape->setImpl(new TopoDS_Shape(theShape)); + + std::shared_ptr aVertex = + std::shared_ptr(new GeomAPI_Vertex(aShape)); + std::shared_ptr aPnt = aVertex->point(); + + std::shared_ptr aPnt2d = convertTo2D(theSketch, aPnt); + std::shared_ptr aPoint = + std::dynamic_pointer_cast(aData->attribute(SketchPlugin_Point::COORD_ID())); + aPoint->setValue(aPnt2d); + if ((aPnt->x() < Precision::Confusion()) && + (aPnt->y() < Precision::Confusion()) && + (aPnt->z() < Precision::Confusion())) + aData->setName("Origin"); + + aMyFeature->execute(); + aRes = aMyFeature->firstResult(); + } + if (anAttr.get() && aRes.get()) { std::shared_ptr aVert(new GeomAPI_Shape); aVert->setImpl(new TopoDS_Shape(theShape)); @@ -676,7 +735,7 @@ void PartSet_Tools::findCoincidences(FeaturePtr theStartCoin, QList& if (!aPnt) return; FeaturePtr aObj = ModelAPI_Feature::feature(aPnt->object()); if (!theList.contains(aObj)) { - std::shared_ptr aOrig = getPoint(theStartCoin, theAttr); + std::shared_ptr aOrig = getCoincedencePoint(theStartCoin); if (aOrig.get() == NULL) return; theList.append(aObj); @@ -686,7 +745,7 @@ void PartSet_Tools::findCoincidences(FeaturePtr theStartCoin, QList& std::shared_ptr aAttr = (*aIt); FeaturePtr aConstrFeature = std::dynamic_pointer_cast(aAttr->owner()); if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { - std::shared_ptr aPnt = getPoint(aConstrFeature, theAttr); + std::shared_ptr aPnt = getCoincedencePoint(aConstrFeature); if (aPnt.get() && aOrig->isEqual(aPnt)) { findCoincidences(aConstrFeature, theList, SketchPlugin_ConstraintCoincidence::ENTITY_A()); findCoincidences(aConstrFeature, theList, SketchPlugin_ConstraintCoincidence::ENTITY_B()); @@ -696,6 +755,15 @@ void PartSet_Tools::findCoincidences(FeaturePtr theStartCoin, QList& } } +std::shared_ptr PartSet_Tools::getCoincedencePoint(FeaturePtr theStartCoin) +{ + std::shared_ptr aPnt = SketcherPrs_Tools::getPoint(theStartCoin.get(), + SketchPlugin_Constraint::ENTITY_A()); + if (aPnt.get() == NULL) + aPnt = SketcherPrs_Tools::getPoint(theStartCoin.get(), SketchPlugin_Constraint::ENTITY_B()); + return aPnt; +} + AttributePtr PartSet_Tools::findAttributeBy2dPoint(ObjectPtr theObj, const TopoDS_Shape theShape, FeaturePtr theSketch)