From de33ce237c314faf27851e0ce555168ef9be39cf Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 17 Mar 2016 17:05:11 +0300 Subject: [PATCH] Issue #1343 Improvement of Extrusion and Revolution operations: extrusion is a composite sketch(to create a new sketch) --- .../FeaturesPlugin_CompositeSketch.cpp | 7 ++- .../FeaturesPlugin_Extrusion.cpp | 37 +++++++++++++++- src/FeaturesPlugin/FeaturesPlugin_Extrusion.h | 17 ++++++- src/FeaturesPlugin/extrusion_widget.xml | 14 ++++-- src/PartSet/CMakeLists.txt | 2 + src/PartSet/PartSet_Module.cpp | 8 +++- .../PartSet_WidgetMultiSelectorComposite.cpp | 42 ++++++++++++++++++ .../PartSet_WidgetMultiSelectorComposite.h | 44 +++++++++++++++++++ 8 files changed, 161 insertions(+), 10 deletions(-) create mode 100755 src/PartSet/PartSet_WidgetMultiSelectorComposite.cpp create mode 100755 src/PartSet/PartSet_WidgetMultiSelectorComposite.h diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp index 628773d41..5f7354120 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp @@ -116,8 +116,11 @@ void FeaturesPlugin_CompositeSketch::execute() return; } - if (!selection(SKETCH_SELECTION_ID())->isInitialized() || selection(SKETCH_SELECTION_ID())->context() != aSketchRes) { - selection(SKETCH_SELECTION_ID())->setValue(aSketchRes, std::shared_ptr()); + /// feature extrusion does not have the next attribute + if (data()->attribute(SKETCH_SELECTION_ID()).get()) { + if (!selection(SKETCH_SELECTION_ID())->isInitialized() || selection(SKETCH_SELECTION_ID())->context() != aSketchRes) { + selection(SKETCH_SELECTION_ID())->setValue(aSketchRes, std::shared_ptr()); + } } int aSketchFacesNum = aConstruction->facesNum(); if(aSketchFacesNum == 0) { diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp index 1a1036a11..36ca2939f 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -34,6 +35,9 @@ 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()); @@ -48,14 +52,28 @@ void FeaturesPlugin_Extrusion::initAttributes() ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID()); + + // Composite Sketch attribute + data()->addAttribute(FeaturesPlugin_CompositeSketch::SKETCH_OBJECT_ID(), + ModelAPI_AttributeReference::typeId()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), + FeaturesPlugin_CompositeSketch::SKETCH_OBJECT_ID()); } //================================================================================================= void FeaturesPlugin_Extrusion::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. ListOfShape aFacesList; - AttributeSelectionListPtr aFacesSelectionList = selectionList(LIST_ID()); + //AttributeSelectionListPtr aFacesSelectionList = selectionList(LIST_ID()); for(int anIndex = 0; anIndex < aFacesSelectionList->size(); anIndex++) { AttributeSelectionPtr aFaceSel = aFacesSelectionList->value(anIndex); std::shared_ptr aFaceShape = aFaceSel->value(); @@ -204,3 +222,20 @@ void FeaturesPlugin_Extrusion::loadNamingDS(GeomAlgoAPI_Prism& thePrismAlgo, theResultBody->generated(aFromFace, aStr.str(), aFromTag++); } } + +//================================================================================================= +void FeaturesPlugin_Extrusion::setSketchObjectToList() +{ + 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_Extrusion.h b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h index 98c9af7c9..cc0005081 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h @@ -8,9 +8,10 @@ #define FeaturesPlugin_Extrusion_H_ #include -#include #include +#include + class GeomAPI_Shape; class ModelAPI_ResultBody; @@ -23,7 +24,7 @@ class ModelAPI_ResultBody; * bounding planes if they were set. Direction of extrusion is taken from the face * plane or if the bounding faces were set then it will be from the bottom to the top plane. */ -class FeaturesPlugin_Extrusion : public ModelAPI_Feature +class FeaturesPlugin_Extrusion : public FeaturesPlugin_CompositeSketch { public: /// Extrusion kind @@ -111,11 +112,23 @@ class FeaturesPlugin_Extrusion : public ModelAPI_Feature /// Use plugin manager for features creation FeaturesPlugin_Extrusion(); + +protected: + /// Init attributes for extrusion. + virtual void initMakeSolidsAttributes() {}; + + /// Create solid from face with extrusion. + virtual void makeSolid(const std::shared_ptr theFace, + std::shared_ptr& theMakeShape) {}; + private: /// Load Naming data structure of the feature to the document void loadNamingDS(GeomAlgoAPI_Prism& thePrismAlgo, std::shared_ptr theResultBody, std::shared_ptr theBasis); + + /// Set the sub-object to list of exturusion base. + void setSketchObjectToList(); }; #endif diff --git a/src/FeaturesPlugin/extrusion_widget.xml b/src/FeaturesPlugin/extrusion_widget.xml index 90a7b7078..82414a999 100644 --- a/src/FeaturesPlugin/extrusion_widget.xml +++ b/src/FeaturesPlugin/extrusion_widget.xml @@ -1,15 +1,21 @@ + + - - + - - + setSketcher(mySketchMgr->activeSketch()); aWgt = aShapeSelectorWgt; - } else if (theType == WDG_DOUBLEVALUE_EDITOR) { + } else if (theType == "composite_multi_selector") { + PartSet_WidgetMultiSelectorComposite* aShapeSelectorWgt = + new PartSet_WidgetMultiSelectorComposite(theParent, aWorkshop, theWidgetApi); + aWgt = aShapeSelectorWgt; + } + else if (theType == WDG_DOUBLEVALUE_EDITOR) { aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi); } else if (theType == "export_file_selector") { aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi); diff --git a/src/PartSet/PartSet_WidgetMultiSelectorComposite.cpp b/src/PartSet/PartSet_WidgetMultiSelectorComposite.cpp new file mode 100755 index 000000000..32bd055cc --- /dev/null +++ b/src/PartSet/PartSet_WidgetMultiSelectorComposite.cpp @@ -0,0 +1,42 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: PartSet_WidgetMultiSelectorComposite.cpp +// Created: 17 Mar 2016 +// Author: Natalia Ermolaeva + +#include "PartSet_WidgetMultiSelectorComposite.h" + +PartSet_WidgetMultiSelectorComposite::PartSet_WidgetMultiSelectorComposite(QWidget* theParent, + ModuleBase_IWorkshop* theWorkshop, + const Config_WidgetAPI* theData) +: ModuleBase_WidgetMultiSelector(theParent, theWorkshop, theData) +{ +} + +PartSet_WidgetMultiSelectorComposite::~PartSet_WidgetMultiSelectorComposite() +{ +} + +bool PartSet_WidgetMultiSelectorComposite::focusTo() +{ + bool aCanSetFocus = true; + CompositeFeaturePtr aComposite = std::dynamic_pointer_cast(myFeature); + if (aComposite.get()) + aCanSetFocus = aComposite->numberOfSubs() == 0; + + // disable widget controls + if (!aCanSetFocus) { + disableControls(); + } + + return aCanSetFocus; +} + +void PartSet_WidgetMultiSelectorComposite::disableControls() +{ + QList aMyControls = getControls(); + foreach(QWidget* eachControl, aMyControls) { + eachControl->setFocusPolicy(Qt::NoFocus); + eachControl->setEnabled(false); + } +} diff --git a/src/PartSet/PartSet_WidgetMultiSelectorComposite.h b/src/PartSet/PartSet_WidgetMultiSelectorComposite.h new file mode 100755 index 000000000..62afac31c --- /dev/null +++ b/src/PartSet/PartSet_WidgetMultiSelectorComposite.h @@ -0,0 +1,44 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: PartSet_WidgetMultiSelectorComposite.h +// Created: 17 Mar 2016 +// Author: Natalia Ermolaeva + +#ifndef PartSet_WidgetMultiSelectorComposite_H +#define PartSet_WidgetMultiSelectorComposite_H + +#include "PartSet.h" + +#include + +#include + +/** +* \ingroup Modules +* Customosation of ModuleBase_WidgetMultiSelector in order to provide +* working with sketch specific objects and creation of external objects. +*/ +class PARTSET_EXPORT PartSet_WidgetMultiSelectorComposite: public ModuleBase_WidgetMultiSelector +{ +Q_OBJECT + public: + /// Constructor + /// \param theParent the parent object + /// \param theWorkshop instance of workshop interface + /// \param theData the widget configuation. The attribute of the model widget is obtained from + PartSet_WidgetMultiSelectorComposite(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, + const Config_WidgetAPI* theData); + + virtual ~PartSet_WidgetMultiSelectorComposite(); + + /// Set focus to the first control of the current widget. The focus policy of the control is checked. + /// If the widget has the NonFocus focus policy, it is skipped. + /// \return the state whether the widget can accept the focus + virtual bool focusTo(); + +private: + /// Disable controls by setting them focus policy NoFocus and disabling them + void disableControls(); +}; + +#endif \ No newline at end of file -- 2.39.2