From 36c83ebade90867a88f2e1c1b0989625e6d6a505 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 22 May 2015 15:19:43 +0300 Subject: [PATCH] multi selector controls for boolean feature --- src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp | 51 ++++++++++++++++++- src/FeaturesPlugin/FeaturesPlugin_Boolean.h | 12 +++++ src/FeaturesPlugin/boolean_widget.xml | 22 ++++++-- src/GeomAPI/GeomAPI_Face.cpp | 6 +-- src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp | 11 ++-- 5 files changed, 91 insertions(+), 11 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp index 2932d5e5c..f52353397 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp @@ -11,9 +11,12 @@ #include #include #include +#include #include using namespace std; +//#define DEBUG_ONE_OBJECT + #define FACE 4 #define _MODIFY_TAG 1 #define _DELETED_TAG 2 @@ -24,8 +27,25 @@ FeaturesPlugin_Boolean::FeaturesPlugin_Boolean() void FeaturesPlugin_Boolean::initAttributes() { data()->addAttribute(FeaturesPlugin_Boolean::TYPE_ID(), ModelAPI_AttributeInteger::typeId()); + +#ifdef DEBUG_ONE_OBJECT data()->addAttribute(FeaturesPlugin_Boolean::OBJECT_ID(), ModelAPI_AttributeReference::typeId()); +#else + AttributeSelectionListPtr aSelection = + std::dynamic_pointer_cast(data()->addAttribute( + FeaturesPlugin_Boolean::OBJECT_LIST_ID(), ModelAPI_AttributeSelectionList::typeId())); + // extrusion works with faces always + aSelection->setSelectionType("SOLID"); +#endif + +#ifdef DEBUG_ONE_OBJECT data()->addAttribute(FeaturesPlugin_Boolean::TOOL_ID(), ModelAPI_AttributeReference::typeId()); +#else + aSelection = std::dynamic_pointer_cast(data()->addAttribute( + FeaturesPlugin_Boolean::TOOL_LIST_ID(), ModelAPI_AttributeSelectionList::typeId())); + // extrusion works with faces always + aSelection->setSelectionType("SOLID"); +#endif } std::shared_ptr FeaturesPlugin_Boolean::getShape(const std::string& theAttrName) @@ -49,12 +69,41 @@ void FeaturesPlugin_Boolean::execute() if (!aTypeAttr) return; int aType = aTypeAttr->value(); - +#ifdef DEBUG_ONE_OBJECT std::shared_ptr anObject = this->getShape(FeaturesPlugin_Boolean::OBJECT_ID()); +#else + std::shared_ptr anObject; + { + AttributeSelectionListPtr anObjects = selectionList(FeaturesPlugin_Boolean::OBJECT_LIST_ID()); + if (anObjects->size() == 0) + return; + + // Getting bounding planes. + std::shared_ptr anObjRef = anObjects->value(0); + if (!anObjRef.get()) + return; + anObject = std::dynamic_pointer_cast(anObjRef->value()); + } +#endif if (!anObject) return; +#ifdef DEBUG_ONE_OBJECT std::shared_ptr aTool = this->getShape(FeaturesPlugin_Boolean::TOOL_ID()); +#else + std::shared_ptr aTool; + { + AttributeSelectionListPtr anObjects = selectionList(FeaturesPlugin_Boolean::TOOL_LIST_ID()); + if (anObjects->size() == 0) + return; + + // Getting bounding planes. + std::shared_ptr anObjRef = anObjects->value(0); + if (!anObjRef.get()) + return; + aTool = std::dynamic_pointer_cast(anObjRef->value()); + } +#endif if (!aTool) return; diff --git a/src/FeaturesPlugin/FeaturesPlugin_Boolean.h b/src/FeaturesPlugin/FeaturesPlugin_Boolean.h index 65ad15d2e..53023300a 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Boolean.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Boolean.h @@ -29,6 +29,12 @@ public: return MY_ID; } /// attribute name of referenced object + inline static const std::string& OBJECT_LIST_ID() + { + static const std::string MY_OBJECT_LIST_ID("main_objects"); + return MY_OBJECT_LIST_ID; + } + /// attribute name of referenced object inline static const std::string& OBJECT_ID() { static const std::string MY_OBJECT_ID("main_object"); @@ -40,6 +46,12 @@ public: static const std::string MY_TOOL_ID("tool_object"); return MY_TOOL_ID; } + /// attribute name of tool object + inline static const std::string& TOOL_LIST_ID() + { + static const std::string MY_TOOL_LIST_ID("tool_objects"); + return MY_TOOL_LIST_ID; + } /// attribute name of operation type inline static const std::string& TYPE_ID() { diff --git a/src/FeaturesPlugin/boolean_widget.xml b/src/FeaturesPlugin/boolean_widget.xml index 9a6e83da9..e1443e531 100644 --- a/src/FeaturesPlugin/boolean_widget.xml +++ b/src/FeaturesPlugin/boolean_widget.xml @@ -1,24 +1,40 @@ - --> + - + + + diff --git a/src/GeomAPI/GeomAPI_Face.cpp b/src/GeomAPI/GeomAPI_Face.cpp index 2055bdc6d..b9dbd45df 100644 --- a/src/GeomAPI/GeomAPI_Face.cpp +++ b/src/GeomAPI/GeomAPI_Face.cpp @@ -16,6 +16,7 @@ #include #include #include +#include GeomAPI_Face::GeomAPI_Face() : GeomAPI_Shape() @@ -64,9 +65,8 @@ bool GeomAPI_Face::isPlanar() const { const TopoDS_Shape& aShape = const_cast(this)->impl(); Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aShape)); - if (aSurf->IsKind(STANDARD_TYPE(Geom_Plane))) - return true; - return false; + GeomLib_IsPlanarSurface isPlanar(aSurf); + return isPlanar.IsPlanar(); } std::shared_ptr GeomAPI_Face::getPlane() const diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp index fab62c181..d03b76169 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp @@ -11,6 +11,7 @@ #include #include #include +#include std::shared_ptr GeomAlgoAPI_FaceBuilder::square( @@ -70,11 +71,13 @@ std::shared_ptr GeomAlgoAPI_FaceBuilder::plane( Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace); if (aSurf.IsNull()) return aResult; // no surface - Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(aSurf); - if (aPlane.IsNull()) - return aResult; // not planar + GeomLib_IsPlanarSurface isPlanar(aSurf); + if(!isPlanar.IsPlanar()) { + return aResult; + } + gp_Pln aPln = isPlanar.Plan(); double aA, aB, aC, aD; - aPlane->Coefficients(aA, aB, aC, aD); + aPln.Coefficients(aA, aB, aC, aD); aResult = std::shared_ptr(new GeomAPI_Pln(aA, aB, aC, aD)); return aResult; } -- 2.39.2