]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Create fixed edges on constraint creation
authorvsv <vitaly.smetannikov@opencascade.com>
Mon, 1 Dec 2014 08:46:25 +0000 (11:46 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Mon, 1 Dec 2014 08:46:25 +0000 (11:46 +0300)
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h
src/PartSet/PartSet_WidgetShapeSelector.cpp
src/PartSet/PartSet_WidgetShapeSelector.h
src/SketchPlugin/plugin-Sketch.xml
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h
src/XGUI/XGUI_ModuleConnector.cpp
src/XGUI/XGUI_ViewerProxy.cpp

index 2f4fbb47a0b8e0692af5d7537d1d218dd605c904..a63aecd79e1be309031624c3deebe5ed598bb756 100644 (file)
@@ -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;
 }
index fdc4e25c8ffe186fec15a8e89b8f67eab9f1df53..f6e8ae84fe8645128b6b020f056cf3e409b41207 100644 (file)
@@ -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<GeomAPI_Edge> aInEdge = std::shared_ptr<GeomAPI_Edge>(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<GeomDataAPI_Point2D> anEndAttr = 
-    //  std::dynamic_pointer_cast<GeomDataAPI_Point2D>(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<ModelAPI_AttributeSelection>
       (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID()));
 
-    ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePrs.object());
+    ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
     if (anAttr && aRes) {
       std::shared_ptr<GeomAPI_Shape> anEdge(new GeomAPI_Shape);
-      anEdge->setImpl(new TopoDS_Shape(aShape));
+      anEdge->setImpl(new TopoDS_Shape(theShape));
 
       anAttr->setValue(aRes, anEdge);
 
index 522f0363d1a1a268522bf07aa1794f67c0adefa3..bceef165aa4b03801364da28ca8b65b94349fdea 100644 (file)
@@ -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
index 6036af1d490b95312e74f039a60e20d26284f7fa..9e391c62e07132e8ea140bee24a1cba52ed7e0a9 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <ModelAPI_AttributeRefAttr.h>
 #include <PartSet_Tools.h>
+#include <SketchPlugin_Feature.h>
 
 
 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<SketchPlugin_Feature> aSPFeature = 
+            std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+    if ((!aSPFeature) && (!myShape->isNull())) {
+      ObjectPtr aObj = PartSet_Tools::createFixedObjectByEdge(myShape->impl<TopoDS_Shape>(),
+                                                              mySelectedObject, mySketch);
+      if (aObj) {
+        PartSet_WidgetConstraintShapeSelector* that = (PartSet_WidgetConstraintShapeSelector*) this;
+        that->mySelectedObject = aObj;
+      }
+    }
+  }
+  return ModuleBase_WidgetShapeSelector::storeValue();
+}
+
index a216830ae281c46a20c2dc2d7f2797c610b143a7..fabbea2aeb7046204d70206687bbde2f52a091e5 100644 (file)
@@ -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
index 4395e92fcba66b05d159391b902c6dd1cfecd954..e19bf277228840565327b36e5b6d54bae1a8e4cf 100644 (file)
       </feature>
       
       <feature id="SketchConstraintParallel" title="Parallel" tooltip="Create constraint defining two parallel lines" icon=":icons/parallel.png">
-               <shape_selector id="ConstraintEntityA" label="First line" tooltip="Select an line in the viewer" 
+               <sketch_constraint_shape_selector id="ConstraintEntityA" label="First line" tooltip="Select an line in the viewer" 
                        shape_types="edge" use_subshapes="true"/>
-               <shape_selector id="ConstraintEntityB" label="Last line" tooltip="Select an line in the viewer" 
+               <sketch_constraint_shape_selector id="ConstraintEntityB" label="Last line" tooltip="Select an line in the viewer" 
                        shape_types="edge" use_subshapes="true"/>
         <sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" internal="1" obligatory="0"/>
         <validator id="PartSet_ParallelValidator"/>
       </feature>
       
       <feature id="SketchConstraintPerpendicular" title="Perpendicular" tooltip="Create constraint defining two perpendicular lines" icon=":icons/perpendicular.png">
-               <shape_selector id="ConstraintEntityA" label="First line" tooltip="Select an line in the viewer" 
+               <sketch_constraint_shape_selector id="ConstraintEntityA" label="First line" tooltip="Select an line in the viewer" 
                        shape_types="edge" use_subshapes="true"/>
-               <shape_selector id="ConstraintEntityB" label="Last line" tooltip="Select an line in the viewer" 
+               <sketch_constraint_shape_selector id="ConstraintEntityB" label="Last line" tooltip="Select an line in the viewer" 
                        shape_types="edge" use_subshapes="true"/>
         <validator id="PartSet_PerpendicularValidator"/>
       </feature>
index 0ebba5866f740bcac44bf6e9adbf8788fe1bc970..9ca390ecb243023847224d61da0b94d02839fea9 100644 (file)
@@ -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();
+}
index 80b511c0f887bebceb2562dfdd517f0d7d03467d..f563223280a444faf49eeeea1918cae78bb1210f 100644 (file)
@@ -105,6 +105,8 @@ class XGUI_EXPORT XGUI_Displayer
 
   void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
 
+  void removeFilters();
+
   /// Updates the viewer
   void updateViewer();
 
index e42ce2da5e756e0981634ef26f835453075f43cc..cd13a987be12da53666ee1e9b286089b4e66ab3b 100644 (file)
@@ -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);
 }
 
index 747dec2455b3797cd49a47be352668525345f90b..ffd09a2a53b65ed3ef9cb031c380957fbfc890b6 100644 (file)
@@ -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();
 }