From: nds Date: Thu, 27 Aug 2015 17:35:27 +0000 (+0300) Subject: #839 Selection of Part sub-results X-Git-Tag: V_1.4.0_beta4~220 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=febe3af3ac386d908eab536b3fbcf9c65264bf9f;p=modules%2Fshaper.git #839 Selection of Part sub-results Realization for movement feature --- diff --git a/src/FeaturesPlugin/movement_widget.xml b/src/FeaturesPlugin/movement_widget.xml index 96c16cf3a..421a8851d 100644 --- a/src/FeaturesPlugin/movement_widget.xml +++ b/src/FeaturesPlugin/movement_widget.xml @@ -5,8 +5,10 @@ label="Main objects" icon=":icons/cut_shape.png" tooltip="Select a solid objects" - type_choice="Solids" + type_choice="Compounds Solids" + use_choice="false" concealment="true"> + +#include + +#include +#include + +#include +#include +#include + +bool GeomValidators_PartSet::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const +{ + bool aValid = false; + SessionPtr aMgr = ModelAPI_Session::get(); + bool isPartSetDocument = aMgr->activeDocument() == aMgr->moduleDocument(); + + if (theAttribute->attributeType() == ModelAPI_AttributeSelectionList::typeId()) { + AttributeSelectionListPtr aSelectionListAttr = + std::dynamic_pointer_cast(theAttribute); + // all context objects should be sketch entities + for (int i = 0, aSize = aSelectionListAttr->size(); i < aSize; i++) { + AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i); + + GeomShapePtr aShape = aSelectAttr->value(); + if (!aShape.get()) { + ResultPtr aResult = aSelectAttr->context(); + if (aResult.get()) + aShape = aResult->shape(); + } + TopoDS_Shape aTopoShape = aShape->impl(); + TopAbs_ShapeEnum aShapeType = aTopoShape.ShapeType(); + + if (isPartSetDocument) + aValid = aShapeType == TopAbs_COMPOUND; + else { + TopoDS_Shape aTopoShape = aShape->impl(); + aShapeType = GeomValidators_Tools::getCompoundSubType(aTopoShape); + + aValid = aShapeType == TopAbs_SOLID; + } + } + } + + return aValid; +} + diff --git a/src/GeomValidators/GeomValidators_PartSet.h b/src/GeomValidators/GeomValidators_PartSet.h new file mode 100755 index 000000000..dc80cc568 --- /dev/null +++ b/src/GeomValidators/GeomValidators_PartSet.h @@ -0,0 +1,28 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomValidators_Face.h +// Created: 27 Aug 2015 +// Author: Natalia ERMOLAEVA + +#ifndef GeomValidators_PartSet_H +#define GeomValidators_PartSet_H + +#include +#include + +/** +* \ingroup Validators +* A validator for partset objects. +*/ +class GeomValidators_PartSet : public ModelAPI_AttributeValidator +{ +public: + //! returns true if attribute is valid + //! \param theAttribute the checked attribute + //! \param theArguments arguments of the attribute + GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const; +}; + +#endif diff --git a/src/GeomValidators/GeomValidators_Tools.cpp b/src/GeomValidators/GeomValidators_Tools.cpp index 9a78b5016..7f16f0814 100644 --- a/src/GeomValidators/GeomValidators_Tools.cpp +++ b/src/GeomValidators/GeomValidators_Tools.cpp @@ -10,6 +10,8 @@ #include "ModelAPI_AttributeSelection.h" #include "ModelAPI_AttributeReference.h" +#include + namespace GeomValidators_Tools { ObjectPtr getObject(const AttributePtr& theAttribute) @@ -33,4 +35,31 @@ namespace GeomValidators_Tools { } return anObject; } + + TopAbs_ShapeEnum getCompoundSubType(const TopoDS_Shape& theShape) + { + TopAbs_ShapeEnum aShapeType = theShape.ShapeType(); + + // for compounds check sub-shapes: it may be compound of needed type: + // Booleans may produce compounds of Solids + if (aShapeType == TopAbs_COMPOUND) { + for(TopoDS_Iterator aSubs(theShape); aSubs.More(); aSubs.Next()) { + if (!aSubs.Value().IsNull()) { + TopAbs_ShapeEnum aSubType = aSubs.Value().ShapeType(); + if (aSubType == TopAbs_COMPOUND) { // compound of compound(s) + aShapeType = TopAbs_COMPOUND; + break; + } + if (aShapeType == TopAbs_COMPOUND) { + aShapeType = aSubType; + } else if (aShapeType != aSubType) { // compound of shapes of different types + aShapeType = TopAbs_COMPOUND; + break; + } + } + } + } + return aShapeType; + } + } diff --git a/src/GeomValidators/GeomValidators_Tools.h b/src/GeomValidators/GeomValidators_Tools.h index bb1db6644..83a2c3f66 100644 --- a/src/GeomValidators/GeomValidators_Tools.h +++ b/src/GeomValidators/GeomValidators_Tools.h @@ -11,6 +11,8 @@ #include "ModelAPI_Object.h" #include "ModelAPI_Attribute.h" +#include "TopAbs_ShapeEnum.hxx" +#include "TopoDS_Shape.hxx" namespace GeomValidators_Tools { @@ -18,6 +20,10 @@ namespace GeomValidators_Tools /// \param theObj an object GEOMVALIDATORS_EXPORT ObjectPtr getObject(const AttributePtr& theAttribute); + // Returns the object from the attribute + /// \param theObj an object + GEOMVALIDATORS_EXPORT TopAbs_ShapeEnum getCompoundSubType(const TopoDS_Shape& theShape); + }; #endif diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index e1b25b884..b0ee536de 100755 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -216,6 +216,7 @@ TopAbs_ShapeEnum shapeType(const QString& theType) MyShapeTypes["shell"] = TopAbs_SHELL; MyShapeTypes["solid"] = TopAbs_SOLID; MyShapeTypes["solids"] = TopAbs_SOLID; + MyShapeTypes["compounds"] = TopAbs_COMPOUND; } QString aType = theType.toLower(); if (MyShapeTypes.contains(aType)) diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index b83e14576..d58a23633 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -15,8 +15,6 @@ #include #include -#include - #include #include #include diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.cpp b/src/ModuleBase/ModuleBase_WidgetSelector.cpp index 5f57ebb15..6f9076bfb 100755 --- a/src/ModuleBase/ModuleBase_WidgetSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelector.cpp @@ -11,6 +11,8 @@ #include +#include + #include ModuleBase_WidgetSelector::ModuleBase_WidgetSelector(QWidget* theParent, @@ -64,6 +66,8 @@ bool ModuleBase_WidgetSelector::acceptSubShape(const GeomShapePtr& theShape, if (theResult.get()) aShape = theResult->shape(); } + QIntList aShapeTypes = getShapeTypes(); + TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE; if (aShape.get()) { // Check that the selection corresponds to selection type @@ -72,25 +76,13 @@ bool ModuleBase_WidgetSelector::acceptSubShape(const GeomShapePtr& theShape, // for compounds check sub-shapes: it may be compound of needed type: // Booleans may produce compounds of Solids if (aShapeType == TopAbs_COMPOUND) { - for(TopoDS_Iterator aSubs(aTopoShape); aSubs.More(); aSubs.Next()) { - if (!aSubs.Value().IsNull()) { - TopAbs_ShapeEnum aSubType = aSubs.Value().ShapeType(); - if (aSubType == TopAbs_COMPOUND) { // compound of compound(s) - aShapeType = TopAbs_COMPOUND; - break; - } - if (aShapeType == TopAbs_COMPOUND) { - aShapeType = aSubType; - } else if (aShapeType != aSubType) { // compound of shapes of different types - aShapeType = TopAbs_COMPOUND; - break; - } - } - } + if (aShapeTypes.contains(aShapeType)) + return true; + + aShapeType = GeomValidators_Tools::getCompoundSubType(aTopoShape); } } - QIntList aShapeTypes = getShapeTypes(); QIntList::const_iterator anIt = aShapeTypes.begin(), aLast = aShapeTypes.end(); for (; anIt != aLast; anIt++) { if (aShapeType == *anIt) diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 16e0d2a62..84c409d50 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -13,8 +13,6 @@ #include #include -#include - #include #include #include diff --git a/src/PartSet/PartSet_Filters.cpp b/src/PartSet/PartSet_Filters.cpp index d82447430..31f1872c7 100644 --- a/src/PartSet/PartSet_Filters.cpp +++ b/src/PartSet/PartSet_Filters.cpp @@ -10,6 +10,8 @@ #include "ModuleBase_IModule.h" #include +#include +#include #include #include @@ -38,11 +40,20 @@ Standard_Boolean PartSet_GlobalFilter::IsOk(const Handle(SelectMgr_EntityOwner)& } ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj); if (aObj) { - FeaturePtr aFeature = ModelAPI_Feature::feature(aObj); - if (aFeature) { - aValid = aFeature->getKind() != FeaturesPlugin_Group::ID(); - } else - aValid = Standard_True; + ResultPtr aResult = std::dynamic_pointer_cast(aObj); + // result of parts belongs to PartSet document and can be selected only when PartSet is active + // in order to do not select the result of the active part. + if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group()) { + SessionPtr aMgr = ModelAPI_Session::get(); + aValid = aMgr->activeDocument() == aMgr->moduleDocument(); + } + else { + FeaturePtr aFeature = ModelAPI_Feature::feature(aObj); + if (aFeature) { + aValid = aFeature->getKind() != FeaturesPlugin_Group::ID(); + } else + aValid = Standard_True; + } } else // This is not object controlled by the filter aValid = Standard_True; diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 3731b80fd..361e12d5d 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -208,6 +209,8 @@ void PartSet_Module::registerValidators() aFactory->registerValidator("GeomValidators_ShapeType", new GeomValidators_ShapeType); aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face); + aFactory->registerValidator("GeomValidators_PartSet", new GeomValidators_PartSet); + aFactory->registerValidator("GeomValidators_ConstructionComposite", new GeomValidators_ConstructionComposite);