Salome HOME
"2.11 Constraint with a point from the intersection between an outer edge and plane...
authornds <nds@opencascade.com>
Fri, 12 Feb 2016 15:45:30 +0000 (18:45 +0300)
committerdbv <dbv@opencascade.com>
Tue, 16 Feb 2016 14:04:46 +0000 (17:04 +0300)
1. Using AttributeSelection instead of AttrRef for external line to use result+shape
2. switch off plane filter when the corresponded control is active
3. correction: propety panel is empty if the constraint is selected as point attribute does not present in XML

src/ModuleBase/ModuleBase_WidgetSelector.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_SketcherMgr.cpp
src/PartSet/PartSet_SketcherMgr.h
src/PartSet/PartSet_WidgetShapeSelector.cpp
src/PartSet/PartSet_WidgetShapeSelector.h
src/SketchPlugin/SketchPlugin_IntersectionPoint.cpp
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/plugin-Sketch.xml
src/XGUI/XGUI_Tools.cpp
src/XGUI/XGUI_Tools.h

index a73a677c2632b5771f49e66ce1ce7b4fa30ba225..58cb33062030fe26c3bb28a875a1b0df5ecc4c53 100755 (executable)
@@ -44,7 +44,7 @@ Q_OBJECT
   virtual bool isViewerSelector() { return true; }
 
   /// Activate or deactivate selection and selection filters
-  void activateSelectionAndFilters(bool toActivate);
+  virtual void activateSelectionAndFilters(bool toActivate);
 
   /// Checks the widget validity. By default, it returns true.
   /// \param thePrs a selected presentation in the view
index df2a560b700cbbc1de02f67ac229bc5c22947447..641d17ac239f668baa3bd2e5efc6d8d9817dd933 100755 (executable)
@@ -495,7 +495,10 @@ bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
           aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
 
           theWidgets = aFactory.getModelWidgets();
-          aProcessed = true;
+          // it is possible that the point does not present in XML definition,
+          // in this case, we assume that it is not processed by this module
+          // e.g. "Intersection point" feature
+          aProcessed = !theWidgets.isEmpty();
         }
       }
     }
index eaefdeb4afdcd7b0a249ce25e223cd166f13d621..936c30afcf40d0f48135c87027979881a1a2e5c6 100755 (executable)
@@ -62,6 +62,7 @@
 #include <SketchPlugin_ConstraintMiddle.h>
 #include <SketchPlugin_MultiRotation.h>
 #include <SketchPlugin_MultiTranslation.h>
+#include <SketchPlugin_IntersectionPoint.h>
 
 #include <SketcherPrs_Tools.h>
 
@@ -85,8 +86,6 @@
 
 //#define DEBUG_CURSOR
 
-//#define DEBUG_INTERSECTION_POINT
-
 /// Returns list of unique objects by sum of objects from List1 and List2
 /*QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
                                        const QList<ModuleBase_ViewerPrs>& theList2)
@@ -735,7 +734,7 @@ const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
     aIds << SketchPlugin_Arc::ID().c_str();
     aIds << SketchPlugin_Circle::ID().c_str();
     aIds << SketchPlugin_ConstraintFillet::ID().c_str();
-    aIds << SketchPlugin_Circle::ID().c_str();
+    aIds << SketchPlugin_IntersectionPoint::ID().c_str();
     // TODO
     // SketchRectangle is a python feature, so its ID is passed just as a string
     aIds << "SketchRectangle";
@@ -864,9 +863,7 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
   if (myPlaneFilter.IsNull()) 
     myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
 
-#ifndef DEBUG_INTERSECTION_POINT
   myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
-#endif
   bool aHasPlane = false;
   std::shared_ptr<GeomAPI_Pln> aPln;
   if (aFOperation->isEditOperation()) {
@@ -989,6 +986,14 @@ void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
   }
 }
 
+void PartSet_SketcherMgr::activatePlaneFilter(const bool& toActivate)
+{
+  if (toActivate)
+    myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
+  else
+    myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
+}
+
 void PartSet_SketcherMgr::operationActivatedByPreselection()
 {
   ModuleBase_Operation* anOperation = getCurrentOperation();
index 958a7e9a0583dcd225502629c8444b42a45d3577..f13c3cfdff815382ec6acbfdf6bc81ac615add32 100644 (file)
@@ -142,6 +142,10 @@ public:
   /// \param theOperation a committed operation
   void commitNestedSketch(ModuleBase_Operation* theOperation);
 
+  /// Append the sketch plane filter into the current viewer
+  /// \param toActivate state whether the filter should be activated/deactivated
+  void activatePlaneFilter(const bool& toActivate);
+
   /// Commit the operation if it is possible. If the operation is dimention constraint,
   /// it gives widget editor to input dimention value
   void operationActivatedByPreselection();
index 064a29efb529763d3ab48331ffb4b4cbd71bf66d..8bc3368bd8d86a9ff545420f8a69a1d7ed5d3c4e 100755 (executable)
@@ -5,6 +5,8 @@
 // Author:      Vitaly Smetannikov
 
 #include "PartSet_WidgetShapeSelector.h"
+#include "PartSet_Module.h"
+#include "PartSet_SketcherMgr.h"
 
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_Session.h>
@@ -22,6 +24,7 @@
 #include <XGUI_Displayer.h>
 #include <XGUI_SelectionMgr.h>
 #include <XGUI_Selection.h>
+#include <XGUI_Tools.h>
 
 PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
                                                          ModuleBase_IWorkshop* theWorkshop,
@@ -29,6 +32,7 @@ PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
                                                          const std::string& theParentId)
 : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId)
 {
+  myUseSketchPlane = theData->getBooleanAttribute("use_sketch_plane", true);
   myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"), true);
 }
 
@@ -37,6 +41,17 @@ PartSet_WidgetShapeSelector::~PartSet_WidgetShapeSelector()
   delete myExternalObjectMgr;
 }
 
+//********************************************************************
+void PartSet_WidgetShapeSelector::activateSelectionAndFilters(bool toActivate)
+{
+  ModuleBase_WidgetShapeSelector::activateSelectionAndFilters(toActivate);
+  if (!myUseSketchPlane) {
+    XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
+    PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(aWorkshop->module());
+    aModule->sketchMgr()->activatePlaneFilter(false);
+  }
+}
+
 //********************************************************************
 bool PartSet_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
 {
index 0f9a88218489236723d2902a1e4769ce82a2f866..9af349389ed90423e5024d99f58072e4ce3b9cf3 100644 (file)
@@ -42,6 +42,10 @@ Q_OBJECT
   /// Retrurns installed sketcher
   CompositeFeaturePtr sketch() const { return mySketch; }
 
+  /// Activate or deactivate selection and selection filters
+  /// \param toActivate boolean state whether it should be activated/deactivated
+  virtual void activateSelectionAndFilters(bool toActivate);
+
 protected:
   /// Checks the widget validity. By default, it returns true.
   /// \param thePrs a selected presentation in the view
@@ -68,6 +72,8 @@ protected:
 
   /// Pointer to a sketch 
   CompositeFeaturePtr mySketch;
+
+  bool myUseSketchPlane; /// state whether the sketch plane filter should be switched on
 };
 
 #endif
\ No newline at end of file
index 8310bccf6e6b5465a99755a4d6fe35725ad7e0a6..23b4d018dafc3836f0fe328a0a19cce00ea59d5e 100644 (file)
@@ -52,13 +52,17 @@ void SketchPlugin_IntersectionPoint::computePoint()
 {
   AttributeSelectionPtr aLineAttr =
       std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(attribute(EXTERNAL_LINE_ID()));
-  ResultPtr aLineResult = std::dynamic_pointer_cast<ModelAPI_Result>(aLineAttr->context());
-  if (!aLineResult)
+
+  std::shared_ptr<GeomAPI_Edge> anEdge;
+  if(aLineAttr && aLineAttr->value() && aLineAttr->value()->isEdge()) {
+    anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aLineAttr->value()));
+  } else if(aLineAttr->context() && aLineAttr->context()->shape() && aLineAttr->context()->shape()->isEdge()) {
+    anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aLineAttr->context()->shape()));
+  }
+  if(!anEdge.get())
     return;
 
-  std::shared_ptr<GeomAPI_Edge> aLinearEdge =
-      std::dynamic_pointer_cast<GeomAPI_Edge>(aLineResult->shape());
-  std::shared_ptr<GeomAPI_Lin> aLine = aLinearEdge->line();
+  std::shared_ptr<GeomAPI_Lin> aLine = anEdge->line();
   std::shared_ptr<GeomAPI_Pln> aSketchPlane = sketch()->plane();
 
   std::shared_ptr<GeomAPI_Pnt> anIntersection = aSketchPlane->intersect(aLine);
index b07e90ac46a1b4cbe0eda9a7cd4dd605f90f5aa8..a00da25cbba418085e8771ae67d651002576b460 100755 (executable)
@@ -696,14 +696,15 @@ bool SketchPlugin_IntersectionValidator::isValid(const AttributePtr& theAttribut
     theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
     return false;
   }
-  AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
-  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anAttr->context());
-  if (!aResult) {
-    theError = "The attribute " + theAttribute->id() + " should be an object";
-    return false;
+  AttributeSelectionPtr aLineAttr =
+                              std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+  std::shared_ptr<GeomAPI_Edge> anEdge;
+  if(aLineAttr && aLineAttr->value() && aLineAttr->value()->isEdge()) {
+    anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aLineAttr->value()));
+  } else if(aLineAttr->context() && aLineAttr->context()->shape() && aLineAttr->context()->shape()->isEdge()) {
+    anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aLineAttr->context()->shape()));
   }
 
-  std::shared_ptr<GeomAPI_Edge> anEdge = std::dynamic_pointer_cast<GeomAPI_Edge>(aResult->shape());
   if (!anEdge || !anEdge->isLine()) {
     theError = "The attribute " + theAttribute->id() + " should be a line";
     return false;
@@ -713,7 +714,7 @@ bool SketchPlugin_IntersectionValidator::isValid(const AttributePtr& theAttribut
 
   // find a sketch
   std::shared_ptr<SketchPlugin_Sketch> aSketch;
-  std::set<AttributePtr> aRefs = anAttr->owner()->data()->refsToMe();
+  std::set<AttributePtr> aRefs = aLineAttr->owner()->data()->refsToMe();
   std::set<AttributePtr>::const_iterator anIt = aRefs.begin();
   for (; anIt != aRefs.end(); ++anIt) {
     CompositeFeaturePtr aComp =
@@ -730,5 +731,5 @@ bool SketchPlugin_IntersectionValidator::isValid(const AttributePtr& theAttribut
 
   std::shared_ptr<GeomAPI_Pln> aPlane = aSketch->plane();
   std::shared_ptr<GeomAPI_Dir> aNormal = aPlane->direction();
-  return true;//fabs(aNormal->dot(aLineDir)) > tolerance * tolerance;
+  return fabs(aNormal->dot(aLineDir)) > tolerance * tolerance;
 }
index cdcef01559b3adfaf01d2030463e33ae5e674b9f..c654a5535eda30e6b26869e306c6970713a4744e 100644 (file)
@@ -34,7 +34,9 @@
               id="ExternalLine"
               label="Edge"
               tooltip="Select external line."
-              shape_types="edge">
+              shape_types="edge"
+              use_external="false"
+              use_sketch_plane="false">
           <validator id="GeomValidators_ShapeType" parameters="line"/>
           <validator id="SketchPlugin_IntersectionValidator"/>
         </sketch_shape_selector>
index bc4637649c386b2013f4a842c57e4dc4c1ef1a15..9bb1dfa84d357c5c5c3cde1cbdad0019ebbab8ea 100644 (file)
@@ -2,6 +2,11 @@
 
 #include "XGUI_Tools.h"
 
+#include "XGUI_ModuleConnector.h"
+#include "XGUI_Workshop.h"
+
+#include "ModuleBase_IWorkshop.h"
+
 #include <TopoDS_Shape.hxx>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Result.h>
@@ -320,4 +325,10 @@ void refsDirectToFeatureInAllDocuments(const ObjectPtr& theSourceObject, const O
   }
 }
 
+XGUI_Workshop* workshop(ModuleBase_IWorkshop* theWorkshop)
+{
+  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
+  return aConnector->workshop();
+}
+
 }
index b1947fc76e41e6ea70d4ada6bff0282290f2a6eb..da38e87add14de71a9618366bce4e2670c1f052a 100644 (file)
@@ -14,6 +14,8 @@
 #include <memory>
 
 class QWidget;
+class XGUI_Workshop;
+class ModuleBase_IWorkshop;
 
 /*!
  \ingroup GUI
@@ -150,6 +152,14 @@ void XGUI_EXPORT refsToFeatureInAllDocuments(const ObjectPtr& theSourceObject,
 * \returns boolean value
 */
 bool XGUI_EXPORT isSubOfComposite(const ObjectPtr& theObject);
+
+/*!
+ Returns converted workshop
+ \param theWorkshop an interface workshop
+ \return XGUI workshop instance
+*/
+XGUI_EXPORT XGUI_Workshop* workshop(ModuleBase_IWorkshop* theWorkshop);
+
 };
 
 #endif