From 031179ada6681b874314c450eeda806f9f8abd28 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 12 Feb 2016 18:45:30 +0300 Subject: [PATCH] "2.11 Constraint with a point from the intersection between an outer edge and plane of sketch" corrections: 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 | 2 +- src/PartSet/PartSet_Module.cpp | 5 ++++- src/PartSet/PartSet_SketcherMgr.cpp | 15 ++++++++++----- src/PartSet/PartSet_SketcherMgr.h | 4 ++++ src/PartSet/PartSet_WidgetShapeSelector.cpp | 15 +++++++++++++++ src/PartSet/PartSet_WidgetShapeSelector.h | 6 ++++++ .../SketchPlugin_IntersectionPoint.cpp | 14 +++++++++----- src/SketchPlugin/SketchPlugin_Validators.cpp | 17 +++++++++-------- src/SketchPlugin/plugin-Sketch.xml | 4 +++- src/XGUI/XGUI_Tools.cpp | 11 +++++++++++ src/XGUI/XGUI_Tools.h | 10 ++++++++++ 11 files changed, 82 insertions(+), 21 deletions(-) diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.h b/src/ModuleBase/ModuleBase_WidgetSelector.h index a73a677c2..58cb33062 100755 --- a/src/ModuleBase/ModuleBase_WidgetSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetSelector.h @@ -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 diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index df2a560b7..641d17ac2 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -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(); } } } diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index eaefdeb4a..936c30afc 100755 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -62,6 +62,7 @@ #include #include #include +#include #include @@ -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 getSumList(const QList& theList1, const QList& 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 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(); diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index 958a7e9a0..f13c3cfdf 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -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(); diff --git a/src/PartSet/PartSet_WidgetShapeSelector.cpp b/src/PartSet/PartSet_WidgetShapeSelector.cpp index 064a29efb..8bc3368bd 100755 --- a/src/PartSet/PartSet_WidgetShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetShapeSelector.cpp @@ -5,6 +5,8 @@ // Author: Vitaly Smetannikov #include "PartSet_WidgetShapeSelector.h" +#include "PartSet_Module.h" +#include "PartSet_SketcherMgr.h" #include #include @@ -22,6 +24,7 @@ #include #include #include +#include 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(aWorkshop->module()); + aModule->sketchMgr()->activatePlaneFilter(false); + } +} + //******************************************************************** bool PartSet_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs) { diff --git a/src/PartSet/PartSet_WidgetShapeSelector.h b/src/PartSet/PartSet_WidgetShapeSelector.h index 0f9a88218..9af349389 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.h +++ b/src/PartSet/PartSet_WidgetShapeSelector.h @@ -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 diff --git a/src/SketchPlugin/SketchPlugin_IntersectionPoint.cpp b/src/SketchPlugin/SketchPlugin_IntersectionPoint.cpp index 8310bccf6..23b4d018d 100644 --- a/src/SketchPlugin/SketchPlugin_IntersectionPoint.cpp +++ b/src/SketchPlugin/SketchPlugin_IntersectionPoint.cpp @@ -52,13 +52,17 @@ void SketchPlugin_IntersectionPoint::computePoint() { AttributeSelectionPtr aLineAttr = std::dynamic_pointer_cast(attribute(EXTERNAL_LINE_ID())); - ResultPtr aLineResult = std::dynamic_pointer_cast(aLineAttr->context()); - if (!aLineResult) + + std::shared_ptr anEdge; + if(aLineAttr && aLineAttr->value() && aLineAttr->value()->isEdge()) { + anEdge = std::shared_ptr(new GeomAPI_Edge(aLineAttr->value())); + } else if(aLineAttr->context() && aLineAttr->context()->shape() && aLineAttr->context()->shape()->isEdge()) { + anEdge = std::shared_ptr(new GeomAPI_Edge(aLineAttr->context()->shape())); + } + if(!anEdge.get()) return; - std::shared_ptr aLinearEdge = - std::dynamic_pointer_cast(aLineResult->shape()); - std::shared_ptr aLine = aLinearEdge->line(); + std::shared_ptr aLine = anEdge->line(); std::shared_ptr aSketchPlane = sketch()->plane(); std::shared_ptr anIntersection = aSketchPlane->intersect(aLine); diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index b07e90ac4..a00da25cb 100755 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -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(theAttribute); - ResultPtr aResult = std::dynamic_pointer_cast(anAttr->context()); - if (!aResult) { - theError = "The attribute " + theAttribute->id() + " should be an object"; - return false; + AttributeSelectionPtr aLineAttr = + std::dynamic_pointer_cast(theAttribute); + std::shared_ptr anEdge; + if(aLineAttr && aLineAttr->value() && aLineAttr->value()->isEdge()) { + anEdge = std::shared_ptr(new GeomAPI_Edge(aLineAttr->value())); + } else if(aLineAttr->context() && aLineAttr->context()->shape() && aLineAttr->context()->shape()->isEdge()) { + anEdge = std::shared_ptr(new GeomAPI_Edge(aLineAttr->context()->shape())); } - std::shared_ptr anEdge = std::dynamic_pointer_cast(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 aSketch; - std::set aRefs = anAttr->owner()->data()->refsToMe(); + std::set aRefs = aLineAttr->owner()->data()->refsToMe(); std::set::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 aPlane = aSketch->plane(); std::shared_ptr aNormal = aPlane->direction(); - return true;//fabs(aNormal->dot(aLineDir)) > tolerance * tolerance; + return fabs(aNormal->dot(aLineDir)) > tolerance * tolerance; } diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index cdcef0155..c654a5535 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -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"> diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index bc4637649..9bb1dfa84 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -2,6 +2,11 @@ #include "XGUI_Tools.h" +#include "XGUI_ModuleConnector.h" +#include "XGUI_Workshop.h" + +#include "ModuleBase_IWorkshop.h" + #include #include #include @@ -320,4 +325,10 @@ void refsDirectToFeatureInAllDocuments(const ObjectPtr& theSourceObject, const O } } +XGUI_Workshop* workshop(ModuleBase_IWorkshop* theWorkshop) +{ + XGUI_ModuleConnector* aConnector = dynamic_cast(theWorkshop); + return aConnector->workshop(); +} + } diff --git a/src/XGUI/XGUI_Tools.h b/src/XGUI/XGUI_Tools.h index b1947fc76..da38e87ad 100644 --- a/src/XGUI/XGUI_Tools.h +++ b/src/XGUI/XGUI_Tools.h @@ -14,6 +14,8 @@ #include 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 -- 2.39.2