From 7c56b92e97952849c0e9002633ed6f871783ae5c Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 24 Mar 2016 09:29:57 +0300 Subject: [PATCH] Issue #1343 Improvement of Extrusion and Revolution operations: extrusion cut. --- .../FeaturesPlugin_CompositeBoolean.cpp | 36 +++++++++- .../FeaturesPlugin_CompositeBoolean.h | 11 ++++ .../FeaturesPlugin_Extrusion.cpp | 4 -- src/FeaturesPlugin/extrusion_widget.xml | 2 - src/FeaturesPlugin/extrusioncut_widget.xml | 16 ++++- src/GeomValidators/GeomValidators_Face.cpp | 4 +- src/GeomValidators/GeomValidators_Face.h | 6 -- src/ModuleBase/ModuleBase_Tools.cpp | 66 +++++++++++++++++++ src/ModuleBase/ModuleBase_Tools.h | 15 +++++ .../ModuleBase_WidgetMultiSelector.cpp | 31 ++------- .../ModuleBase_WidgetMultiSelector.h | 4 +- .../ModuleBase_WidgetShapeSelector.cpp | 30 +-------- .../ModuleBase_WidgetShapeSelector.h | 4 +- src/PartSet/PartSet_WidgetSketchCreator.cpp | 24 ++++++- src/PartSet/PartSet_WidgetSketchCreator.h | 10 ++- 15 files changed, 183 insertions(+), 80 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp index dc0b3a948..65a6c6a8d 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp @@ -29,11 +29,17 @@ //================================================================================================= void FeaturesPlugin_CompositeBoolean::initAttributes() { + AttributeSelectionListPtr aSelection = + std::dynamic_pointer_cast(data()->addAttribute( + LIST_ID(), ModelAPI_AttributeSelectionList::typeId())); + data()->addAttribute(SKETCH_OBJECT_ID(), ModelAPI_AttributeReference::typeId()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), + SKETCH_OBJECT_ID()); // Boolean works with solids always. data()->addAttribute(BOOLEAN_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId()); - AttributeSelectionListPtr aSelection = data()->selectionList(BOOLEAN_OBJECTS_ID()); + aSelection = data()->selectionList(BOOLEAN_OBJECTS_ID()); aSelection->setSelectionType("SOLID"); initMakeSolidsAttributes(); @@ -96,6 +102,9 @@ bool FeaturesPlugin_CompositeBoolean::isSub(ObjectPtr theObject) const //================================================================================================= void FeaturesPlugin_CompositeBoolean::removeFeature(std::shared_ptr theFeature) { + AttributeSelectionListPtr aFacesSelectionList = selectionList(LIST_ID()); + if (aFacesSelectionList.get() && aFacesSelectionList->size() > 0) + aFacesSelectionList->clear(); } //================================================================================================= @@ -115,6 +124,14 @@ void FeaturesPlugin_CompositeBoolean::erase() //================================================================================================= void FeaturesPlugin_CompositeBoolean::execute() { + /// feature extrusion does not have the next attribute + AttributeSelectionListPtr aFacesSelectionList = selectionList(LIST_ID()); + if (aFacesSelectionList.get() && !aFacesSelectionList->isInitialized()) { + AttributeReferencePtr aSketchAttr = reference(SKETCH_OBJECT_ID()); + if (aSketchAttr.get() && aSketchAttr->isInitialized()) + setSketchObjectToList(); + } + // Getting faces to create solids. std::shared_ptr aSketchFeature = std::dynamic_pointer_cast( reference(SKETCH_OBJECT_ID())->value()); @@ -460,3 +477,20 @@ void FeaturesPlugin_CompositeBoolean::loadNamingDS(std::shared_ptr aSketchFeature = std::dynamic_pointer_cast( + reference(SKETCH_OBJECT_ID())->value()); + + if(aSketchFeature.get() && !aSketchFeature->results().empty()) { + ResultPtr aSketchRes = aSketchFeature->results().front(); + ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aSketchRes); + if(aConstruction.get()) { + AttributeSelectionListPtr aFacesSelectionList = selectionList(LIST_ID()); + if (aFacesSelectionList.get() && aFacesSelectionList->size() == 0) + aFacesSelectionList->append(aSketchRes, std::shared_ptr()); + } + } +} diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.h b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.h index f171bc6e8..7cae61fd9 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.h +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.h @@ -27,6 +27,14 @@ class FeaturesPlugin_CompositeBoolean : public ModelAPI_CompositeFeature return MY_SKETCH_OBJECT_ID; } + /// attribute name of references sketch entities list, it should contain a sketch result or + /// a pair a sketch result to sketch face + inline static const std::string& LIST_ID() + { + static const std::string MY_GROUP_LIST_ID("base"); + return MY_GROUP_LIST_ID; + } + /// Attribute name of sketch feature. inline static const std::string& SKETCH_SELECTION_ID() { @@ -90,6 +98,9 @@ protected: GeomAlgoAPI_MakeShape& theMakeShape, GeomAPI_DataMapOfShapeShape& theMapOfShapes); + /// Set the sub-object to list of exturusion base. + void setSketchObjectToList(); + protected: /// Type of boolean operation. GeomAlgoAPI_Boolean::OperationType myBooleanOperationType; diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp index cd843949f..d38803592 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp @@ -35,9 +35,6 @@ void FeaturesPlugin_Extrusion::initAttributes() LIST_ID(), ModelAPI_AttributeSelectionList::typeId())); // extrusion works with faces always aSelection->setSelectionType("FACE"); - ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), - FeaturesPlugin_Extrusion::LIST_ID()); - data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId()); @@ -73,7 +70,6 @@ void FeaturesPlugin_Extrusion::execute() // Getting faces. ListOfShape aFacesList; - //AttributeSelectionListPtr aFacesSelectionList = selectionList(LIST_ID()); for(int anIndex = 0; anIndex < aFacesSelectionList->size(); anIndex++) { AttributeSelectionPtr aFaceSel = aFacesSelectionList->value(anIndex); std::shared_ptr aFaceShape = aFaceSel->value(); diff --git a/src/FeaturesPlugin/extrusion_widget.xml b/src/FeaturesPlugin/extrusion_widget.xml index 3dc5813d5..63099b851 100644 --- a/src/FeaturesPlugin/extrusion_widget.xml +++ b/src/FeaturesPlugin/extrusion_widget.xml @@ -7,8 +7,6 @@ 1. Planar face of non-sketch object or a plane. Sketch creation will be started.<br /> 2. An existing sketch face or contour. Extrusion will be filled by it.<br /> 3. An existing result shape of kind: wires/edge/vertices.Extrusion will be filled by it." - icon=":icons/sketch.png" - tooltip="Create or edit a sketch" shape_types="face objects"> + attribute_list_id="base" + label="Select:<br /> +1. Planar face of non-sketch object or a plane. Sketch creation will be started.<br /> +2. An existing sketch face or contour. Extrusion will be filled by it.<br /> +3. An existing result shape of kind: wires/edge/vertices.Extrusion will be filled by it." + shape_types="face objects"> + + + diff --git a/src/GeomValidators/GeomValidators_Face.cpp b/src/GeomValidators/GeomValidators_Face.cpp index 51a5012cd..d3b075fde 100644 --- a/src/GeomValidators/GeomValidators_Face.cpp +++ b/src/GeomValidators/GeomValidators_Face.cpp @@ -8,6 +8,8 @@ #include +#include + #include #include @@ -16,7 +18,7 @@ typedef std::map FaceTypes; static FaceTypes MyFaceTypes; -GeomAbs_SurfaceType GeomValidators_Face::faceType(const std::string& theType) +GeomAbs_SurfaceType faceType(const std::string& theType) { if (MyFaceTypes.size() == 0) { MyFaceTypes["plane"] = GeomAbs_Plane; diff --git a/src/GeomValidators/GeomValidators_Face.h b/src/GeomValidators/GeomValidators_Face.h index b10cecff7..f547dbb47 100644 --- a/src/GeomValidators/GeomValidators_Face.h +++ b/src/GeomValidators/GeomValidators_Face.h @@ -10,8 +10,6 @@ #include "GeomValidators.h" #include "ModelAPI_AttributeValidator.h" -#include - /** * \ingroup Validators * A validator of selection @@ -27,10 +25,6 @@ class GeomValidators_Face : public ModelAPI_AttributeValidator GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute, const std::list& theArguments, std::string& theError) const; -protected: - /// Convert string to TypeOfFace value - /// \param theType a string value - GEOMVALIDATORS_EXPORT static GeomAbs_SurfaceType faceType(const std::string& theType); }; #endif diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index 02e774313..1bc60c1ed 100755 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -16,6 +16,10 @@ #include #include #include +#include +#include +#include + #include #include #include @@ -39,6 +43,7 @@ #include #include +#include const double tolerance = 1e-7; @@ -424,6 +429,67 @@ std::string findGreedAttribute(ModuleBase_IWorkshop* theWorkshop, const FeatureP return anAttributeId; } +void setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject, + const GeomShapePtr& theShape, ModuleBase_IWorkshop* theWorkshop, + const bool theTemporarily) +{ + if (!theAttribute.get()) + return; + + std::string aType = theAttribute->attributeType(); + if (aType == ModelAPI_AttributeReference::typeId()) { + AttributeReferencePtr aRef = std::dynamic_pointer_cast(theAttribute); + ObjectPtr aObject = aRef->value(); + if (!(aObject && aObject->isSame(theObject))) { + aRef->setValue(theObject); + } + } else if (aType == ModelAPI_AttributeRefAttr::typeId()) { + AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(theAttribute); + + AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape); + if (anAttribute.get()) + aRefAttr->setAttr(anAttribute); + else { + ObjectPtr aObject = aRefAttr->object(); + if (!(aObject && aObject->isSame(theObject))) { + aRefAttr->setObject(theObject); + } + } + } else if (aType == ModelAPI_AttributeSelection::typeId()) { + AttributeSelectionPtr aSelectAttr = + std::dynamic_pointer_cast(theAttribute); + ResultPtr aResult = std::dynamic_pointer_cast(theObject); + if (aSelectAttr.get() != NULL) { + aSelectAttr->setValue(aResult, theShape, theTemporarily); + } + } + if (aType == ModelAPI_AttributeSelectionList::typeId()) { + AttributeSelectionListPtr aSelectionListAttr = + std::dynamic_pointer_cast(theAttribute); + ResultPtr aResult = std::dynamic_pointer_cast(theObject); + if (!aSelectionListAttr->isInList(aResult, theShape, theTemporarily)) + aSelectionListAttr->append(aResult, theShape, theTemporarily); + } + else if (aType == ModelAPI_AttributeRefList::typeId()) { + AttributeRefListPtr aRefListAttr = std::dynamic_pointer_cast(theAttribute); + if (!aRefListAttr->isInList(theObject)) + aRefListAttr->append(theObject); + } + else if (aType == ModelAPI_AttributeRefAttrList::typeId()) { + AttributeRefAttrListPtr aRefAttrListAttr = std::dynamic_pointer_cast(theAttribute); + AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape); + + if (anAttribute.get()) { + if (!aRefAttrListAttr->isInList(anAttribute)) + aRefAttrListAttr->append(anAttribute); + } + else { + if (!aRefAttrListAttr->isInList(theObject)) + aRefAttrListAttr->append(theObject); + } + } +} + } // namespace ModuleBase_Tools diff --git a/src/ModuleBase/ModuleBase_Tools.h b/src/ModuleBase/ModuleBase_Tools.h index 3e8f3b4d7..594c5ed28 100755 --- a/src/ModuleBase/ModuleBase_Tools.h +++ b/src/ModuleBase/ModuleBase_Tools.h @@ -28,6 +28,8 @@ class ModuleBase_ParamIntSpinBox; class ModuleBase_ParamSpinBox; class ModuleBase_IWorkshop; +class GeomAPI_Shape; + namespace ModuleBase_Tools { /* @@ -176,6 +178,19 @@ MODULEBASE_EXPORT void getParameters(QStringList& theParameters); /// \theParameters a list of parameter names MODULEBASE_EXPORT std::string findGreedAttribute(ModuleBase_IWorkshop* theWorkshop, const FeaturePtr& theFeature); + +/// Set the object to the attribute depending on the attribute type. If it is a list, +/// the values are appended if they are not in the list yet. +/// \param theAttribute an attribute where the object and shape are set +/// \param theObject an object +/// \param theShape a shape +/// \param theWorkshop to find an attribute for the given shape for attribute reference +/// \param theTemporarily if it is true, do not store and name the added in the data framework +/// It is useful for attribute selection +MODULEBASE_EXPORT void setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject, + const std::shared_ptr& theShape, + ModuleBase_IWorkshop* theWorkshop, + const bool theTemporarily = false); } #endif diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 81a5194b5..096adeea6 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -271,36 +272,12 @@ void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool theValid) } //******************************************************************** -void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theSelectedObject, +void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theObject, GeomShapePtr theShape) { DataPtr aData = myFeature->data(); - AttributePtr anAttribute = aData->attribute(attributeID()); - std::string aType = anAttribute->attributeType(); - if (aType == ModelAPI_AttributeSelectionList::typeId()) { - AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID()); - ResultPtr aResult = std::dynamic_pointer_cast(theSelectedObject); - if (!aSelectionListAttr->isInList(aResult, theShape, myIsInValidate)) - aSelectionListAttr->append(aResult, theShape, myIsInValidate); - } - else if (aType == ModelAPI_AttributeRefList::typeId()) { - AttributeRefListPtr aRefListAttr = aData->reflist(attributeID()); - if (!aRefListAttr->isInList(theSelectedObject)) - aRefListAttr->append(theSelectedObject); - } - else if (aType == ModelAPI_AttributeRefAttrList::typeId()) { - AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID()); - AttributePtr anAttribute = myWorkshop->module()->findAttribute(theSelectedObject, theShape); - - if (anAttribute.get()) { - if (!aRefAttrListAttr->isInList(anAttribute)) - aRefAttrListAttr->append(anAttribute); - } - else { - if (!aRefAttrListAttr->isInList(theSelectedObject)) - aRefAttrListAttr->append(theSelectedObject); - } - } + ModuleBase_Tools::setObject(aData->attribute(attributeID()), theObject, theShape, + myWorkshop, myIsInValidate); } //******************************************************************** diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index 81fcbed1d..69ab6e146 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -126,10 +126,10 @@ protected: /// Append the values to the model attribute of the widget. It casts this attribute to /// the specific type and set the given values - /// \param theSelectedObject an object + /// \param theObject an object /// \param theShape a selected shape, which is used in the selection attribute /// \return true if it is succeed - void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape); + void setObject(ObjectPtr theObject, GeomShapePtr theShape); /// Creates a backup of the current values of the attribute /// It should be realized in the specific widget because of different diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 0a3d15bbc..2def57f66 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -107,36 +107,12 @@ bool ModuleBase_WidgetShapeSelector::storeValueCustom() const } //******************************************************************** -void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, +void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObject, GeomShapePtr theShape) { DataPtr aData = myFeature->data(); - std::string aType = aData->attribute(attributeID())->attributeType(); - if (aType == ModelAPI_AttributeReference::typeId()) { - AttributeReferencePtr aRef = aData->reference(attributeID()); - ObjectPtr aObject = aRef->value(); - if (!(aObject && aObject->isSame(theSelectedObject))) { - aRef->setValue(theSelectedObject); - } - } else if (aType == ModelAPI_AttributeRefAttr::typeId()) { - AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); - - AttributePtr anAttribute = myWorkshop->module()->findAttribute(theSelectedObject, theShape); - if (anAttribute.get()) - aRefAttr->setAttr(anAttribute); - else { - ObjectPtr aObject = aRefAttr->object(); - if (!(aObject && aObject->isSame(theSelectedObject))) { - aRefAttr->setObject(theSelectedObject); - } - } - } else if (aType == ModelAPI_AttributeSelection::typeId()) { - AttributeSelectionPtr aSelectAttr = aData->selection(attributeID()); - ResultPtr aResult = std::dynamic_pointer_cast(theSelectedObject); - if (aSelectAttr.get() != NULL) { - aSelectAttr->setValue(aResult, theShape); - } - } + ModuleBase_Tools::setObject(aData->attribute(attributeID()), theObject, theShape, + myWorkshop, myIsInValidate); } //******************************************************************** diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index 4c73b1765..c3e48ab25 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -102,10 +102,10 @@ Q_OBJECT /// Store the values to the model attribute of the widget. It casts this attribute to /// the specific type and set the given values - /// \param theSelectedObject an object + /// \param theObject an object /// \param theShape a selected shape, which is used in the selection attribute /// \return true if it is succeed - virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape); + virtual void setObject(ObjectPtr theObject, GeomShapePtr theShape); /// Get the shape from the attribute if the attribute contains a shape, e.g. selection attribute /// \return a shape diff --git a/src/PartSet/PartSet_WidgetSketchCreator.cpp b/src/PartSet/PartSet_WidgetSketchCreator.cpp index 58c2776d1..8243a253a 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.cpp +++ b/src/PartSet/PartSet_WidgetSketchCreator.cpp @@ -249,7 +249,7 @@ void PartSet_WidgetSketchCreator::onSelectionChanged() for (; anIt != aLast; anIt++) { ModuleBase_ViewerPrs aValue = *anIt; if (isValidInFilters(aValue)) - aProcessed = setSelectionCustom(aValue) || aProcessed; + aProcessed = setBaseAttributeSelection(aValue) || aProcessed; } if (aProcessed) { emit valuesChanged(); @@ -263,10 +263,14 @@ void PartSet_WidgetSketchCreator::onSelectionChanged() } //******************************************************************** -void PartSet_WidgetSketchCreator::setObject(ObjectPtr theSelectedObject, +void PartSet_WidgetSketchCreator::setObject(ObjectPtr theObject, GeomShapePtr theShape) { - // do nothing because all processing is in onSelectionChanged() + DataPtr aData = myFeature->data(); + ModuleBase_Tools::setObject(aData->attribute(attributeID()), theObject, theShape, + myWorkshop, myIsInValidate); + + //::setObject(aData->attribute(attributeID()), theObject, theShape); } bool PartSet_WidgetSketchCreator::startSketchOperation(const QList& theValues) @@ -426,3 +430,17 @@ void PartSet_WidgetSketchCreator::onResumed(ModuleBase_Operation* theOp) } } } + +bool PartSet_WidgetSketchCreator::setBaseAttributeSelection(const ModuleBase_ViewerPrs& theValue) +{ + bool isDone = false; + ObjectPtr anObject; + GeomShapePtr aShape; + getGeomSelection(theValue, anObject, aShape); + + std::string anAttributeId = myAttributeListID; + DataPtr aData = myFeature->data(); + ModuleBase_Tools::setObject(aData->attribute(anAttributeId), anObject, aShape, + myWorkshop, false); + return true; +} diff --git a/src/PartSet/PartSet_WidgetSketchCreator.h b/src/PartSet/PartSet_WidgetSketchCreator.h index 7a341689d..0936eff29 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.h +++ b/src/PartSet/PartSet_WidgetSketchCreator.h @@ -14,6 +14,7 @@ class QLabel; class QLineEdit; class PartSet_Module; +class ModelAPI_Tools; class ModuleBase_Operation; class ModuleBase_IWorkshop; class PartSet_PreviewPlanes; @@ -81,10 +82,10 @@ protected: /// Store the values to the model attribute of the widget. It casts this attribute to /// the specific type and set the given values - /// \param theSelectedObject an object + /// \param theObject an object /// \param theShape a selected shape, which is used in the selection attribute /// \return true if it is succeed - virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape); + virtual void setObject(ObjectPtr theObject, GeomShapePtr theShape); private: /// Returns true if the selection mode is active. This is when composition feature has no @@ -106,6 +107,11 @@ private: /// \return true if the sketch is started bool startSketchOperation(const QList& theValues); + /// Appends the selection to the sketch base attribute + /// \param theValue a selection value from the viewer + /// \return true if the value is set + bool setBaseAttributeSelection(const ModuleBase_ViewerPrs& theValue); + private: std::string myAttributeListID; -- 2.39.2