From: vsv Date: Mon, 19 Nov 2018 08:08:53 +0000 (+0300) Subject: Transfer selected data to a main operation X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4d1800af89d6af71f2ec32c60a376e4798564cfd;p=modules%2Fshaper.git Transfer selected data to a main operation --- diff --git a/src/CollectionPlugin/CollectionPlugin_GroupFilters.h b/src/CollectionPlugin/CollectionPlugin_GroupFilters.h index a7ec756ee..305d179c3 100644 --- a/src/CollectionPlugin/CollectionPlugin_GroupFilters.h +++ b/src/CollectionPlugin/CollectionPlugin_GroupFilters.h @@ -41,6 +41,11 @@ public: return MY_KIND; } + virtual bool isInHistory() + { + return false; + } + /// Creates a new group result if needed COLLECTIONPLUGIN_EXPORT virtual void execute() {} diff --git a/src/Filters/Filters_HorizontalPlane.h b/src/Filters/Filters_HorizontalPlane.h index cca9a8816..6a4365c1a 100644 --- a/src/Filters/Filters_HorizontalPlane.h +++ b/src/Filters/Filters_HorizontalPlane.h @@ -30,13 +30,14 @@ class Filters_HorizontalPlane : public ModelAPI_Filter public: Filters_HorizontalPlane() : ModelAPI_Filter() {} - virtual bool isOk(const GeomShapePtr& theShape) const; - /// Returns list of supported types of shapes (see GeomAPI_Shape::ShapeType) virtual std::list shapeTypes() const; /// Returns name of the filter to represent it in GUI virtual std::string name() const { return "Horizontal faces"; } + +protected: + virtual bool isOk(const GeomShapePtr& theShape) const; }; diff --git a/src/Filters/Filters_VerticalPlane.h b/src/Filters/Filters_VerticalPlane.h index 69fb248b2..8ff822085 100644 --- a/src/Filters/Filters_VerticalPlane.h +++ b/src/Filters/Filters_VerticalPlane.h @@ -30,13 +30,14 @@ class Filters_VerticalPlane : public ModelAPI_Filter public: Filters_VerticalPlane() : ModelAPI_Filter() {} - virtual bool isOk(const GeomShapePtr& theShape) const; - /// Returns list of supported types of shapes (see GeomAPI_Shape::ShapeType) virtual std::list shapeTypes() const; /// Returns name of the filter to represent it in GUI virtual std::string name() const { return "Vertical faces"; } + +protected: + virtual bool isOk(const GeomShapePtr& theShape) const; }; diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 809647521..63dbccc86 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -180,8 +180,6 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen myTypeCtrl->setValue(myDefMode.c_str()); } } - if (myFiltersWgt) - myFiltersWgt->setSelectionType(myTypeCtrl->textValue()); } ModuleBase_WidgetMultiSelector::~ModuleBase_WidgetMultiSelector() @@ -502,9 +500,6 @@ void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged() // Clear current selection in order to avoid updating of object browser with obsolete indexes // which can appear because of results deletetion after changing a type of selection QString aSelectionType = myTypeCtrl->textValue(); - if (myFiltersWgt) - myFiltersWgt->setSelectionType(aSelectionType); - QList aEmptyList; myWorkshop->setSelected(aEmptyList); diff --git a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp index 07d0ff4d5..9148b73a8 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp @@ -26,8 +26,10 @@ #include "ModuleBase_IPropertyPanel.h" #include "ModuleBase_PageWidget.h" #include "ModuleBase_WidgetMultiSelector.h" +#include "ModuleBase_ResultPrs.h" #include +#include #include #include @@ -43,7 +45,33 @@ #include #include -static int SelectionType = 0; +static FeaturePtr SelectorFeature; +static std::string AttributeId; + + +GeomAPI_Shape::ShapeType selectionType(const QString& theType) +{ + QString aType = theType.toUpper(); + if ((aType == "VERTEX") || (aType == "VERTICES")) + return GeomAPI_Shape::VERTEX; + else if ((aType == "EDGE") || (aType == "EDGES")) + return GeomAPI_Shape::EDGE; + else if ((aType == "WIRE") || (aType == "WIRES")) + return GeomAPI_Shape::WIRE; + else if ((aType == "FACE") || (aType == "FACES")) + return GeomAPI_Shape::FACE; + else if ((aType == "SHELL") || (aType == "SHELLS")) + return GeomAPI_Shape::SHELL; + else if ((aType == "SOLID") || (aType == "SOLIDS")) + return GeomAPI_Shape::SOLID; + else if ((aType == "COMPSOLID") || (aType == "COMPSOLIDS")) + return GeomAPI_Shape::COMPSOLID; + else if ((aType == "COMPOUND") || (aType == "COMPOUNDS")) + return GeomAPI_Shape::COMPOUND; + else + return GeomAPI_Shape::SHAPE; +} + ModuleBase_FilterStarter::ModuleBase_FilterStarter(const std::string& theFeature, QWidget* theParent, ModuleBase_IWorkshop* theWorkshop) @@ -74,40 +102,17 @@ ModuleBase_FilterStarter::ModuleBase_FilterStarter(const std::string& theFeature void ModuleBase_FilterStarter::onFiltersLaunch() { - SelectionType = myShapeType; ModuleBase_WidgetMultiSelector* aSelector = dynamic_cast(parent()); - aSelector->onSelectionTypeChanged(); // In order to clear current selection - aSelector->storeValue(); // Store values defined by user + SelectorFeature = aSelector->feature(); + AttributeId = aSelector->attributeID(); + // Launch Filters operation ModuleBase_OperationFeature* aFOperation = dynamic_cast (myWorkshop->module()->createOperation(myFeatureName)); myWorkshop->processLaunchOperation(aFOperation); } -void ModuleBase_FilterStarter::setSelectionType(const QString& theType) -{ - QString aType = theType.toUpper(); - if ((aType == "VERTEX") || (aType == "VERTICES")) - myShapeType = GeomAPI_Shape::VERTEX; - else if ((aType == "EDGE") || (aType == "EDGES")) - myShapeType = GeomAPI_Shape::EDGE; - else if ((aType == "WIRE") || (aType == "WIRES")) - myShapeType = GeomAPI_Shape::WIRE; - else if ((aType == "FACE") || (aType == "FACES")) - myShapeType = GeomAPI_Shape::FACE; - else if ((aType == "SHELL") || (aType == "SHELLS")) - myShapeType = GeomAPI_Shape::SHELL; - else if ((aType == "SOLID") || (aType == "SOLIDS")) - myShapeType = GeomAPI_Shape::SOLID; - else if ((aType == "COMPSOLID") || (aType == "COMPSOLIDS")) - myShapeType = GeomAPI_Shape::COMPSOLID; - else if ((aType == "COMPOUND") || (aType == "COMPOUNDS")) - myShapeType = GeomAPI_Shape::COMPOUND; - else - myShapeType = GeomAPI_Shape::SHAPE; -} - //***************************************************************************** //***************************************************************************** //***************************************************************************** @@ -161,10 +166,18 @@ void ModuleBase_FilterItem::onDelete() ModuleBase_WidgetSelectionFilter::ModuleBase_WidgetSelectionFilter(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData) : ModuleBase_ModelWidget(theParent, theData), - myWorkshop(theWorkshop), mySelectionType(SelectionType) + myWorkshop(theWorkshop), + mySelectorFeature(SelectorFeature), + mySelectorAttribute(AttributeId) { - myOwners = new SelectMgr_IndexedMapOfOwner(); - + // Clear Old selection + AttributePtr aAttr = SelectorFeature->attribute(AttributeId); + AttributeSelectionListPtr aSelListAttr = + std::dynamic_pointer_cast(aAttr); + mySelectionType = selectionType(aSelListAttr->selectionType().c_str()); + aSelListAttr->clear(); + + // Define widgets QVBoxLayout* aMainLayout = new QVBoxLayout(this); ModuleBase_Tools::adjustMargins(aMainLayout); @@ -250,24 +263,27 @@ ModuleBase_WidgetSelectionFilter::ModuleBase_WidgetSelectionFilter(QWidget* theP ModuleBase_WidgetSelectionFilter::~ModuleBase_WidgetSelectionFilter() { - myOwners.Nullify(); - if ((!myPreview.IsNull()) && myShowBtn->isChecked()) { + myValues.clear(); + if (!myPreview.IsNull()) { Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext(); aCtx->Remove(myPreview, false); myPreview.Nullify(); - AIS_ListOfInteractive::const_iterator aIt; - Handle(AIS_Shape) aShapeIO; - for (aIt = myListIO.cbegin(); aIt != myListIO.cend(); aIt++) { - aShapeIO = Handle(AIS_Shape)::DownCast(*aIt); - if (!aShapeIO.IsNull()) { - aCtx->Display(aShapeIO, false); + if (myShowBtn->isChecked()) { + AIS_ListOfInteractive::const_iterator aIt; + Handle(AIS_Shape) aShapeIO; + for (aIt = myListIO.cbegin(); aIt != myListIO.cend(); aIt++) { + aShapeIO = Handle(AIS_Shape)::DownCast(*aIt); + if (!aShapeIO.IsNull()) { + aCtx->Display(aShapeIO, false); + } } } aCtx->UpdateCurrentViewer(); } + SelectorFeature = FeaturePtr(); + AttributeId = ""; } - void ModuleBase_WidgetSelectionFilter::onAddItem() { int aId = myFiltersCombo->currentIndex(); @@ -325,14 +341,15 @@ void ModuleBase_WidgetSelectionFilter::onSelect() aBuilder.MakeCompound(aComp); if (!myShowBtn->isChecked()) { + myListIO.Clear(); aCtx->DisplayedObjects(AIS_KOI_Shape, -1, myListIO); if (!myPreview.IsNull()) myListIO.Remove(myPreview); } AIS_ListOfInteractive::const_iterator aIt; - Handle(AIS_Shape) aShapeIO; + Handle(ModuleBase_ResultPrs) aShapeIO; for (aIt = myListIO.cbegin(); aIt != myListIO.cend(); aIt++) { - aShapeIO = Handle(AIS_Shape)::DownCast(*aIt); + aShapeIO = Handle(ModuleBase_ResultPrs)::DownCast(*aIt); if (!aShapeIO.IsNull()) { GeomShapePtr aShape(new GeomAPI_Shape); aShape->setImpl(new TopoDS_Shape(aShapeIO->Shape())); @@ -352,13 +369,15 @@ void ModuleBase_WidgetSelectionFilter::onSelect() if (isValid) { TopoDS_Shape aTShape = aShape->impl(); Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(aTShape, aShapeIO, true); - myOwners->Add(aOwner); aBuilder.Add(aComp, aTShape); + + ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aShapeIO->getResult(), aShape, aOwner)); + myValues.append(aValue); } } } } - if (myOwners->Size() > 0) + if (myValues.size() > 0) updatePreview(aComp); updateNumberSelected(); } @@ -420,7 +439,7 @@ void ModuleBase_WidgetSelectionFilter::updateSelectBtn() void ModuleBase_WidgetSelectionFilter::updateNumberSelected() { - myNbLbl->setText(QString::number(myOwners->Size())); + myNbLbl->setText(QString::number(myValues.size())); } QList ModuleBase_WidgetSelectionFilter::getControls() const { @@ -429,10 +448,21 @@ QList ModuleBase_WidgetSelectionFilter::getControls() const void ModuleBase_WidgetSelectionFilter::clearCurrentSelection(bool toUpdate) { - myOwners->Clear(); + myValues.clear(); if (!myPreview.IsNull()) { Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext(); aCtx->Remove(myPreview, toUpdate); myPreview.Nullify(); } } + +void ModuleBase_WidgetSelectionFilter::onFeatureAccepted() +{ + AttributePtr aAttr = mySelectorFeature->attribute(mySelectorAttribute); + AttributeSelectionListPtr aSelListAttr = + std::dynamic_pointer_cast(aAttr); + aSelListAttr->clear(); + foreach(ModuleBase_ViewerPrsPtr aPrs, myValues) { + aSelListAttr->append(aPrs->object(), aPrs->shape()); + } +} \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h index 797af8a99..695d94e3d 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h +++ b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h @@ -23,6 +23,7 @@ #include "ModuleBase.h" #include "ModuleBase_ModelWidget.h" +#include "ModuleBase_ViewerPrs.h" #include @@ -31,6 +32,7 @@ #include #include +#include class QLabel; class QComboBox; @@ -50,8 +52,6 @@ public: ~ModuleBase_FilterStarter() {} - void setSelectionType(const QString& theType); - private slots: void onFiltersLaunch(); @@ -61,7 +61,6 @@ private: QLabel* myFilterLbl; QLabel* myModifyLbl; - int myShapeType; }; @@ -98,10 +97,14 @@ public: /// \return a control list virtual QList getControls() const; + /// It is called when user press Ok or OkPlus buttons in the parent property panel + /// By default this slot does nothing + virtual void onFeatureAccepted(); + protected: /// Saves the internal parameters to the given feature (not ussed for this widget) /// \return True in success - virtual bool storeValueCustom() { return true; } + virtual bool storeValueCustom() { return true; } /// Restore value from attribute data to the widget's control (not ussed for this widget) virtual bool restoreValueCustom() { return true; } @@ -132,10 +135,13 @@ private: std::list myFilters; std::list myUseFilters; - Handle(SelectMgr_IndexedMapOfOwner) myOwners; + QList myValues; Handle(AIS_Shape) myPreview; AIS_ListOfInteractive myListIO; + + FeaturePtr mySelectorFeature; + std::string mySelectorAttribute; };