From 17502b6a58c5b6483777c208bfb7709a8cbc1424 Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 29 Oct 2014 16:48:32 +0300 Subject: [PATCH] Select external objects for sketcher --- src/PartSet/PartSet_OperationFeatureBase.h | 8 -- .../PartSet_OperationFeatureCreate.cpp | 10 ++- src/PartSet/PartSet_Tools.cpp | 73 ++++++++++++++++++- src/PartSet/PartSet_Tools.h | 8 ++ 4 files changed, 88 insertions(+), 11 deletions(-) diff --git a/src/PartSet/PartSet_OperationFeatureBase.h b/src/PartSet/PartSet_OperationFeatureBase.h index cde5fb675..bb74a4431 100644 --- a/src/PartSet/PartSet_OperationFeatureBase.h +++ b/src/PartSet/PartSet_OperationFeatureBase.h @@ -46,14 +46,6 @@ Q_OBJECT ModuleBase_ISelection* theSelection); - protected: - /// Set value to the active widget - /// \param theFeature the feature - /// \param theX the horizontal coordinate - /// \param theY the vertical coordinate - /// \return true if the point is set - //bool setWidgetValue(ObjectPtr theFeature, double theX, double theY); - protected: CompositeFeaturePtr mySketch; ///< the sketch of the feature }; diff --git a/src/PartSet/PartSet_OperationFeatureCreate.cpp b/src/PartSet/PartSet_OperationFeatureCreate.cpp index c27800065..49c8b2490 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.cpp +++ b/src/PartSet/PartSet_OperationFeatureCreate.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #ifdef _DEBUG #include @@ -130,7 +131,14 @@ void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Module isClosedContour = true; } } else if (aShape.ShapeType() == TopAbs_EDGE) { // a line is selected - PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY); + ObjectPtr aObject = aPrs.object(); + if (sketch()->isSub(aObject)) + PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY); + else { + // we have to create the selected edge for the current sketch + ResultPtr aRes = PartSet_Tools::createFixedObjectByEdge(aPrs, sketch()); + aSelected.first().setFeature(aRes); + } } } } diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index dc4feb845..14971c097 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -28,15 +28,21 @@ #include #include #include +#include +#include +#include #include #include #include +#include #include #include #include #include +#include +#include #ifdef _DEBUG #include @@ -178,8 +184,8 @@ void PartSet_Tools::setFeaturePoint(FeaturePtr theFeature, double theX, double t if (!theFeature) return; boost::shared_ptr aData = theFeature->data(); - boost::shared_ptr aPoint = boost::dynamic_pointer_cast( - aData->attribute(theAttribute)); + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(theAttribute)); if (aPoint) aPoint->setValue(theX, theY); } @@ -341,3 +347,66 @@ bool PartSet_Tools::isConstraintFeature(const std::string& theKind) || theKind == SketchPlugin_ConstraintRadius::ID() || theKind == SketchPlugin_ConstraintRigid::ID(); } + +ResultPtr PartSet_Tools::createFixedObjectByEdge(const ModuleBase_ViewerPrs& thePrs, CompositeFeaturePtr theSketch) +{ + TopoDS_Shape aShape = thePrs.shape(); + if (aShape.ShapeType() != TopAbs_EDGE) + return ResultPtr(); + + Standard_Real aStart, aEnd; + Handle(V3d_View) aNullView; + FeaturePtr myFeature; + + Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aStart, aEnd); + GeomAdaptor_Curve aAdaptor(aCurve); + if (aAdaptor.GetType() == GeomAbs_Line) { + // Create line + myFeature = theSketch->addFeature(SketchPlugin_Line::ID()); + + //DataPtr aData = myFeature->data(); + //boost::shared_ptr anEndAttr = + // boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Line::END_ID())); + + //double aX, aY; + //gp_Pnt Pnt1 = aAdaptor.Value(aStart); + //convertTo2D(Pnt1, theSketch, aNullView, aX, aY); + //setFeaturePoint(myFeature, aX, aY, SketchPlugin_Line::START_ID()); + + //gp_Pnt Pnt2 = aAdaptor.Value(aEnd); + //convertTo2D(Pnt2, theSketch, aNullView, aX, aY); + //setFeaturePoint(myFeature, aX, aY, SketchPlugin_Line::END_ID()); + } else if (aAdaptor.GetType() == GeomAbs_Circle) { + if (aAdaptor.IsClosed()) { + // Create circle + myFeature = theSketch->addFeature(SketchPlugin_Circle::ID()); + //gp_Circ aCirc = aAdaptor.Circle(); + //gp_Pnt aCenter = aCirc.Location(); + + //double aX, aY; + //convertTo2D(aCenter, theSketch, aNullView, aX, aY); + //setFeaturePoint(myFeature, aX, aY, SketchPlugin_Circle::CENTER_ID()); + //setFeatureValue(myFeature, aCirc.Radius(), SketchPlugin_Circle::RADIUS_ID()); + } else { + // Create arc + myFeature = theSketch->addFeature(SketchPlugin_Arc::ID()); + } + } + if (myFeature) { + DataPtr aData = myFeature->data(); + AttributeSelectionPtr anAttr = + boost::dynamic_pointer_cast + (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID())); + + ResultPtr aRes = boost::dynamic_pointer_cast(thePrs.object()); + if (anAttr && aRes) { + boost::shared_ptr anEdge(new GeomAPI_Shape); + anEdge->setImpl(new TopoDS_Shape(aShape)); + + anAttr->setValue(aRes, anEdge); + myFeature->execute(); + return myFeature->firstResult(); + } + } + return ResultPtr(); +} \ No newline at end of file diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index 872102d8b..16c79788d 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -7,12 +7,14 @@ #include "PartSet.h" +#include #include #include #include #include +#include #include @@ -125,6 +127,12 @@ class PARTSET_EXPORT PartSet_Tools /// \param theKind a feature kind /// \return the boolean value static bool isConstraintFeature(const std::string& theKind); + + /// Creates a line (arc or circle) by given edge + /// Created line will have fixed constraint + /// \param theEdge - an edge + /// \return - result of created feature + static ResultPtr createFixedObjectByEdge(const ModuleBase_ViewerPrs& thePrs, CompositeFeaturePtr theSketch); }; #endif -- 2.39.2