From: vsv Date: Mon, 1 Dec 2014 08:46:25 +0000 (+0300) Subject: Create fixed edges on constraint creation X-Git-Tag: V_0.6.0^2~45 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8d5a36c1da99b17a0a9f85954fe1a5419528ec79;p=modules%2Fshaper.git Create fixed edges on constraint creation --- diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 2f4fbb47a..a63aecd79 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -456,6 +456,14 @@ QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theModelWidgets.append(aWgt); return aWgt->getControl(); + } if (theType == "sketch_constraint_shape_selector") { + PartSet_WidgetConstraintShapeSelector* aWgt = + new PartSet_WidgetConstraintShapeSelector(theParent, workshop(), theWidgetApi, theParentId); + aWgt->setSketcher(myCurrentSketch); + + theModelWidgets.append(aWgt); + return aWgt->getControl(); + }else return 0; } diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index fdc4e25c8..f6e8ae84f 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -396,15 +396,16 @@ bool PartSet_Tools::isConstraintFeature(const std::string& theKind) || theKind == SketchPlugin_ConstraintRigid::ID(); } -ResultPtr PartSet_Tools::createFixedObjectByEdge(const ModuleBase_ViewerPrs& thePrs, CompositeFeaturePtr theSketch) +ResultPtr PartSet_Tools::createFixedObjectByEdge(const TopoDS_Shape& theShape, + const ObjectPtr& theObject, + CompositeFeaturePtr theSketch) { - TopoDS_Shape aShape = thePrs.shape(); - if (aShape.ShapeType() != TopAbs_EDGE) + if (theShape.ShapeType() != TopAbs_EDGE) return ResultPtr(); // Check that we already have such external edge std::shared_ptr aInEdge = std::shared_ptr(new GeomAPI_Edge()); - aInEdge->setImpl(new TopoDS_Shape(aShape)); + aInEdge->setImpl(new TopoDS_Shape(theShape)); ResultPtr aResult = findExternalEdge(theSketch, aInEdge); if (aResult) return aResult; @@ -414,35 +415,15 @@ ResultPtr PartSet_Tools::createFixedObjectByEdge(const ModuleBase_ViewerPrs& the Handle(V3d_View) aNullView; FeaturePtr aMyFeature; - Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aStart, aEnd); + Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(theShape), aStart, aEnd); GeomAdaptor_Curve aAdaptor(aCurve); if (aAdaptor.GetType() == GeomAbs_Line) { // Create line aMyFeature = theSketch->addFeature(SketchPlugin_Line::ID()); - - //DataPtr aData = myFeature->data(); - //std::shared_ptr anEndAttr = - // std::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 aMyFeature = 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 aMyFeature = theSketch->addFeature(SketchPlugin_Arc::ID()); @@ -454,10 +435,10 @@ ResultPtr PartSet_Tools::createFixedObjectByEdge(const ModuleBase_ViewerPrs& the std::dynamic_pointer_cast (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID())); - ResultPtr aRes = std::dynamic_pointer_cast(thePrs.object()); + ResultPtr aRes = std::dynamic_pointer_cast(theObject); if (anAttr && aRes) { std::shared_ptr anEdge(new GeomAPI_Shape); - anEdge->setImpl(new TopoDS_Shape(aShape)); + anEdge->setImpl(new TopoDS_Shape(theShape)); anAttr->setValue(aRes, anEdge); diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index 522f0363d..bceef165a 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -141,7 +141,9 @@ class PARTSET_EXPORT PartSet_Tools /// Created line will have fixed constraint /// \param theEdge - an edge /// \return - result of created feature - static ResultPtr createFixedObjectByEdge(const ModuleBase_ViewerPrs& thePrs, CompositeFeaturePtr theSketch); + static ResultPtr createFixedObjectByEdge(const TopoDS_Shape& theShape, + const ObjectPtr& theObject, + CompositeFeaturePtr theSketch); /// Checks whether the list of selected presentations contains the given one /// \param theSelected a list of presentations diff --git a/src/PartSet/PartSet_WidgetShapeSelector.cpp b/src/PartSet/PartSet_WidgetShapeSelector.cpp index 6036af1d4..9e391c62e 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetShapeSelector.cpp @@ -6,6 +6,7 @@ #include #include +#include bool PartSet_WidgetShapeSelector::storeValue() const @@ -36,3 +37,23 @@ bool PartSet_WidgetShapeSelector::storeValue() const } return ModuleBase_WidgetShapeSelector::storeValue(); } + +//********************************************* +bool PartSet_WidgetConstraintShapeSelector::storeValue() const +{ + FeaturePtr aFeature = ModelAPI_Feature::feature(mySelectedObject); + if (aFeature) { + std::shared_ptr aSPFeature = + std::dynamic_pointer_cast(aFeature); + if ((!aSPFeature) && (!myShape->isNull())) { + ObjectPtr aObj = PartSet_Tools::createFixedObjectByEdge(myShape->impl(), + mySelectedObject, mySketch); + if (aObj) { + PartSet_WidgetConstraintShapeSelector* that = (PartSet_WidgetConstraintShapeSelector*) this; + that->mySelectedObject = aObj; + } + } + } + return ModuleBase_WidgetShapeSelector::storeValue(); +} + diff --git a/src/PartSet/PartSet_WidgetShapeSelector.h b/src/PartSet/PartSet_WidgetShapeSelector.h index a216830ae..fabbea2ae 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.h +++ b/src/PartSet/PartSet_WidgetShapeSelector.h @@ -32,4 +32,25 @@ private: CompositeFeaturePtr mySketch; }; + +class PARTSET_EXPORT PartSet_WidgetConstraintShapeSelector: public ModuleBase_WidgetShapeSelector +{ +Q_OBJECT + public: + PartSet_WidgetConstraintShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, + const Config_WidgetAPI* theData, const std::string& theParentId) + : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId) {} + + virtual ~PartSet_WidgetConstraintShapeSelector() {} + + /// Saves the internal parameters to the given feature + virtual bool storeValue() const; + + void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; } + CompositeFeaturePtr sketch() const { return mySketch; } + +private: + CompositeFeaturePtr mySketch; +}; + #endif \ No newline at end of file diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 4395e92fc..e19bf2772 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -62,18 +62,18 @@ - - - - diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 0ebba5866..9ca390ecb 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -578,3 +578,11 @@ void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFi return; aContext->RemoveFilter(theFilter); } + +void XGUI_Displayer::removeFilters() +{ + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (aContext.IsNull()) + return; + aContext->RemoveFilters(); +} diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 80b511c0f..f56322328 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -105,6 +105,8 @@ class XGUI_EXPORT XGUI_Displayer void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter); + void removeFilters(); + /// Updates the viewer void updateViewer(); diff --git a/src/XGUI/XGUI_ModuleConnector.cpp b/src/XGUI/XGUI_ModuleConnector.cpp index e42ce2da5..cd13a987b 100644 --- a/src/XGUI/XGUI_ModuleConnector.cpp +++ b/src/XGUI/XGUI_ModuleConnector.cpp @@ -33,12 +33,12 @@ XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop) connect(anOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)), SIGNAL(operationAborted(ModuleBase_Operation*))); - myDocumentShapeFilter = new ModuleBase_ShapeDocumentFilter(this); + //myDocumentShapeFilter = new ModuleBase_ShapeDocumentFilter(this); } XGUI_ModuleConnector::~XGUI_ModuleConnector() { - myDocumentShapeFilter.Nullify(); + //myDocumentShapeFilter.Nullify(); } ModuleBase_ISelection* XGUI_ModuleConnector::selection() const @@ -75,14 +75,14 @@ void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes) } aDisp->activateObjectsOutOfContext(aModes); //TODO: We have to open Local context because at neutral point filters don't work (bug 25340) - aDisp->addSelectionFilter(myDocumentShapeFilter); + //aDisp->addSelectionFilter(myDocumentShapeFilter); } void XGUI_ModuleConnector::deactivateSubShapesSelection() { XGUI_Displayer* aDisp = myWorkshop->displayer(); // The document limitation selection has to be only during operation - aDisp->removeSelectionFilter(myDocumentShapeFilter); + //aDisp->removeSelectionFilter(myDocumentShapeFilter); aDisp->closeLocalContexts(false); } diff --git a/src/XGUI/XGUI_ViewerProxy.cpp b/src/XGUI/XGUI_ViewerProxy.cpp index 747dec245..ffd09a2a5 100644 --- a/src/XGUI/XGUI_ViewerProxy.cpp +++ b/src/XGUI/XGUI_ViewerProxy.cpp @@ -5,6 +5,7 @@ #include "XGUI_ViewWindow.h" #include "XGUI_Viewer.h" #include "XGUI_SalomeConnector.h" +#include "XGUI_Displayer.h" XGUI_ViewerProxy::XGUI_ViewerProxy(XGUI_Workshop* theParent) : ModuleBase_IViewer(theParent), @@ -239,26 +240,17 @@ bool XGUI_ViewerProxy::isMultiSelectionEnabled() const //*************************************** void XGUI_ViewerProxy::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) { - Handle(AIS_InteractiveContext) aContext = AISContext(); - if (!aContext.IsNull()) { - aContext->AddFilter(theFilter); - } + myWorkshop->displayer()->addSelectionFilter(theFilter); } //*************************************** void XGUI_ViewerProxy::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) { - Handle(AIS_InteractiveContext) aContext = AISContext(); - if (!aContext.IsNull()) { - aContext->RemoveFilter(theFilter); - } + myWorkshop->displayer()->removeSelectionFilter(theFilter); } //*************************************** void XGUI_ViewerProxy::clearSelectionFilters() { - Handle(AIS_InteractiveContext) aContext = AISContext(); - if (!aContext.IsNull()) { - aContext->RemoveFilters(); - } + myWorkshop->displayer()->removeFilters(); }