From: vsv Date: Mon, 14 Jul 2014 11:11:53 +0000 (+0400) Subject: ModuleBase adapted to new model structure X-Git-Tag: V_0.4.4~194 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b2fed461882656495c33d4fec61e2ec22d9cf80a;p=modules%2Fshaper.git ModuleBase adapted to new model structure --- diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index b21756a5c..350af8c02 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -25,6 +25,7 @@ SET(PROJECT_HEADERS ModuleBase_SelectionValidator.h ModuleBase_ISelection.h ModuleBase_ViewerPrs.h + ModuleBase_Tools.h ) SET(PROJECT_SOURCES @@ -44,6 +45,7 @@ SET(PROJECT_SOURCES ModuleBase_WidgetPoint2dDistance.cpp ModuleBase_WidgetValue.cpp ModuleBase_WidgetValueFeature.cpp + ModuleBase_Tools.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/ModuleBase/ModuleBase_ISelection.h b/src/ModuleBase/ModuleBase_ISelection.h index 051998502..9a9e52ed7 100644 --- a/src/ModuleBase/ModuleBase_ISelection.h +++ b/src/ModuleBase/ModuleBase_ISelection.h @@ -33,7 +33,12 @@ public: /** * Returns list of features currently selected in 3d viewer */ - virtual QFeatureList selectedFeatures() const = 0; + virtual QList selectedObjects() const = 0; + + /** + * Returns list of currently selected results + */ + virtual QResultList selectedResults() const = 0; //! Returns list of currently selected QModelIndexes virtual QModelIndexList selectedIndexes() const = 0; diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index 720f08933..178eb5d63 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -17,9 +17,9 @@ ModuleBase_ModelWidget::ModuleBase_ModelWidget(QObject* theParent, const Config_ myAttributeID = theData ? theData->widgetId() : ""; } -bool ModuleBase_ModelWidget::isInitialized(FeaturePtr theFeature) const +bool ModuleBase_ModelWidget::isInitialized(ObjectPtr theObject) const { - return theFeature->data()->attribute(attributeID())->isInitialized(); + return theObject->data()->attribute(attributeID())->isInitialized(); } bool ModuleBase_ModelWidget::focusTo() diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 96154b37c..8e4b010f6 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -43,15 +43,15 @@ public: virtual bool setValue(ModuleBase_WidgetValue* theValue) { return false; }; /// Returns the state whether the attribute of the feature is initialized - /// \param theFeature a model feature to be checked + /// \param theObject a model feature to be checked /// \return the boolean result - bool isInitialized(FeaturePtr theFeature) const; + bool isInitialized(ObjectPtr theObject) const; /// Saves the internal parameters to the given feature - /// \param theFeature a model feature to be changed - virtual bool storeValue(FeaturePtr theFeature) const = 0; + /// \param theObject a model feature to be changed + virtual bool storeValue(ObjectPtr theObject) const = 0; - virtual bool restoreValue(FeaturePtr theFeature) = 0; + virtual bool restoreValue(ObjectPtr theObject) = 0; /// 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. diff --git a/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp b/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp index 58a7f371d..81be8438b 100644 --- a/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp @@ -40,9 +40,9 @@ QWidget* ModuleBase_WidgetBoolValue::getControl() const return myCheckBox; } -bool ModuleBase_WidgetBoolValue::storeValue(FeaturePtr theFeature) const +bool ModuleBase_WidgetBoolValue::storeValue(ObjectPtr theObject) const { - DataPtr aData = theFeature->data(); + DataPtr aData = theObject->data(); boost::shared_ptr aBool = aData->boolean(attributeID()); if (aBool->value() != myCheckBox->isChecked()) { @@ -52,9 +52,9 @@ bool ModuleBase_WidgetBoolValue::storeValue(FeaturePtr theFeature) const return true; } -bool ModuleBase_WidgetBoolValue::restoreValue(FeaturePtr theFeature) +bool ModuleBase_WidgetBoolValue::restoreValue(ObjectPtr theObject) { - DataPtr aData = theFeature->data(); + DataPtr aData = theObject->data(); boost::shared_ptr aRef = aData->boolean(attributeID()); bool isBlocked = myCheckBox->blockSignals(true); diff --git a/src/ModuleBase/ModuleBase_WidgetBoolValue.h b/src/ModuleBase/ModuleBase_WidgetBoolValue.h index 6f32ef3ef..3969e643e 100644 --- a/src/ModuleBase/ModuleBase_WidgetBoolValue.h +++ b/src/ModuleBase/ModuleBase_WidgetBoolValue.h @@ -24,10 +24,10 @@ public: virtual ~ModuleBase_WidgetBoolValue(); /// Saves the internal parameters to the given feature - /// \param theFeature a model feature to be changed - virtual bool storeValue(FeaturePtr theFeature) const; + /// \param theObject a model feature to be changed + virtual bool storeValue(ObjectPtr theObject) const; - virtual bool restoreValue(FeaturePtr theFeature); + virtual bool restoreValue(ObjectPtr theObject); /// Returns list of widget controls /// \return a control list diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp index 19828f008..587e1e041 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp @@ -88,9 +88,9 @@ ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue() { } -bool ModuleBase_WidgetDoubleValue::storeValue(FeaturePtr theFeature) const +bool ModuleBase_WidgetDoubleValue::storeValue(ObjectPtr theObject) const { - DataPtr aData = theFeature->data(); + DataPtr aData = theObject->data(); AttributeDoublePtr aReal = aData->real(attributeID()); if (aReal->value() != mySpinBox->value()) { aReal->setValue(mySpinBox->value()); @@ -99,9 +99,9 @@ bool ModuleBase_WidgetDoubleValue::storeValue(FeaturePtr theFeature) const return true; } -bool ModuleBase_WidgetDoubleValue::restoreValue(FeaturePtr theFeature) +bool ModuleBase_WidgetDoubleValue::restoreValue(ObjectPtr theObject) { - DataPtr aData = theFeature->data(); + DataPtr aData = theObject->data(); AttributeDoublePtr aRef = aData->real(attributeID()); bool isBlocked = mySpinBox->blockSignals(true); diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.h b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h index 2a5b6c2a1..909855d18 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.h +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h @@ -25,10 +25,10 @@ public: virtual ~ModuleBase_WidgetDoubleValue(); /// Saves the internal parameters to the given feature - /// \param theFeature a model feature to be changed - virtual bool storeValue(FeaturePtr theFeature) const; + /// \param theObject a model feature to be changed + virtual bool storeValue(ObjectPtr theObject) const; - virtual bool restoreValue(FeaturePtr theFeature); + virtual bool restoreValue(ObjectPtr theObject); /// Returns list of widget controls /// \return a control list diff --git a/src/ModuleBase/ModuleBase_WidgetFeature.cpp b/src/ModuleBase/ModuleBase_WidgetFeature.cpp index bfcc1956e..160965a1e 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeature.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFeature.cpp @@ -70,7 +70,7 @@ bool ModuleBase_WidgetFeature::setValue(ModuleBase_WidgetValue* theValue) bool ModuleBase_WidgetFeature::setFeature(const FeaturePtr& theFeature) { - if (!theFeature || !myFeatureKinds.contains(theFeature->getKind().c_str())) + if (!myFeatureKinds.contains(theFeature->getKind().c_str())) return false; myFeature = theFeature; @@ -79,29 +79,36 @@ bool ModuleBase_WidgetFeature::setFeature(const FeaturePtr& theFeature) return true; } -bool ModuleBase_WidgetFeature::storeValue(FeaturePtr theFeature) const +bool ModuleBase_WidgetFeature::storeValue(ObjectPtr theObject) const { - boost::shared_ptr aData = theFeature->data(); + FeaturePtr aFeature = boost::dynamic_pointer_cast(theObject); + if (!aFeature) + return false; + boost::shared_ptr aData = aFeature->data(); boost::shared_ptr aRef = boost::dynamic_pointer_cast(aData->attribute(attributeID())); ModuleBase_WidgetFeature* that = (ModuleBase_WidgetFeature*) this; - aRef->setFeature(myFeature); - theFeature->execute(); + aRef->setObject(myFeature); + aFeature->execute(); Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); return true; } -bool ModuleBase_WidgetFeature::restoreValue(FeaturePtr theFeature) +bool ModuleBase_WidgetFeature::restoreValue(ObjectPtr theObject) { - boost::shared_ptr aData = theFeature->data(); + boost::shared_ptr aData = theObject->data(); boost::shared_ptr aRef = boost::dynamic_pointer_cast(aData->attribute(attributeID())); - myFeature = aRef->feature(); - myEditor->setText(myFeature ? myFeature->data()->name().c_str() : ""); - return true; + FeaturePtr aFeature = boost::dynamic_pointer_cast(aRef->object()); + if (aFeature) { + myFeature = aFeature; + myEditor->setText(myFeature ? myFeature->data()->name().c_str() : ""); + return true; + } + return false; } QWidget* ModuleBase_WidgetFeature::getControl() const diff --git a/src/ModuleBase/ModuleBase_WidgetFeature.h b/src/ModuleBase/ModuleBase_WidgetFeature.h index 329079118..c57bd531e 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeature.h +++ b/src/ModuleBase/ModuleBase_WidgetFeature.h @@ -40,9 +40,9 @@ public: /// Saves the internal parameters to the given feature /// \param theFeature a model feature to be changed - virtual bool storeValue(FeaturePtr theFeature) const; + virtual bool storeValue(ObjectPtr theObject) const; - virtual bool restoreValue(FeaturePtr theFeature); + virtual bool restoreValue(ObjectPtr theObject); /// Returns the internal parent wiget control, that can be shown anywhere /// \returns the widget @@ -56,11 +56,11 @@ protected: /// Fill the widget values by given point /// \param thePoint the point /// \return the boolean result of the feature set - bool setFeature(const FeaturePtr& theFeature); + bool setFeature(const FeaturePtr& theObject); /// Returns current widget feature /// \return the feature - const FeaturePtr& feature() const { return myFeature; } + const FeaturePtr feature() const { return myFeature; } /// Returns the widget editor /// \return the editor diff --git a/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp b/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp index b3165fbf0..c275f2238 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp @@ -80,7 +80,7 @@ bool ModuleBase_WidgetFeatureOrAttribute::storeValue(FeaturePtr theFeature) cons ModuleBase_WidgetFeatureOrAttribute* that = (ModuleBase_WidgetFeatureOrAttribute*) this; if (feature()) - aRef->setFeature(feature()); + aRef->setObject(feature()); else if (myAttribute) aRef->setAttr(myAttribute); @@ -96,18 +96,21 @@ bool ModuleBase_WidgetFeatureOrAttribute::restoreValue(FeaturePtr theFeature) boost::shared_ptr aRef = boost::dynamic_pointer_cast(aData->attribute(attributeID())); - FeaturePtr aFeature = aRef->feature(); - setFeature(aFeature); - myAttribute = aRef->attr(); + FeaturePtr aFeature = boost::dynamic_pointer_cast(aRef->object()); + if (aFeature) { + setFeature(aFeature); + myAttribute = aRef->attr(); - std::string aText = ""; - if (aFeature) - aText = aFeature->data()->name().c_str(); - else if (myAttribute) - aText = myAttribute->attributeType().c_str(); + std::string aText = ""; + if (aFeature) + aText = aFeature->data()->name().c_str(); + else if (myAttribute) + aText = myAttribute->attributeType().c_str(); - editor()->setText(aText.c_str()); - return true; + editor()->setText(aText.c_str()); + return true; + } + return false; } bool ModuleBase_WidgetFeatureOrAttribute::setAttribute(const boost::shared_ptr& theAttribute) diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp index 8407084ed..51db5770b 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp @@ -101,9 +101,9 @@ void ModuleBase_WidgetPoint2D::setPoint(const boost::shared_ptr& emit valuesChanged(); } -bool ModuleBase_WidgetPoint2D::storeValue(FeaturePtr theFeature) const +bool ModuleBase_WidgetPoint2D::storeValue(ObjectPtr theObject) const { - boost::shared_ptr aData = theFeature->data(); + boost::shared_ptr aData = theObject->data(); boost::shared_ptr aPoint = boost::dynamic_pointer_cast(aData->attribute(attributeID())); @@ -116,9 +116,9 @@ bool ModuleBase_WidgetPoint2D::storeValue(FeaturePtr theFeature) const return true; } -bool ModuleBase_WidgetPoint2D::restoreValue(FeaturePtr theFeature) +bool ModuleBase_WidgetPoint2D::restoreValue(ObjectPtr theObject) { - boost::shared_ptr aData = theFeature->data(); + boost::shared_ptr aData = theObject->data(); boost::shared_ptr aPoint = boost::dynamic_pointer_cast(aData->attribute(attributeID())); @@ -158,11 +158,11 @@ bool ModuleBase_WidgetPoint2D::eventFilter(QObject *theObject, QEvent *theEvent) return ModuleBase_ModelWidget::eventFilter(theObject, theEvent); } -bool ModuleBase_WidgetPoint2D::initFromPrevious(FeaturePtr theFeature) +bool ModuleBase_WidgetPoint2D::initFromPrevious(ObjectPtr theObject) { if (myOptionParam.length() == 0) return false; - boost::shared_ptr aData = theFeature->data(); + boost::shared_ptr aData = theObject->data(); boost::shared_ptr aPoint = boost::dynamic_pointer_cast(aData->attribute(myOptionParam)); if (aPoint) { @@ -172,7 +172,7 @@ bool ModuleBase_WidgetPoint2D::initFromPrevious(FeaturePtr theFeature) this->blockSignals(isBlocked); emit valuesChanged(); - emit storedPoint2D(theFeature, myOptionParam); + emit storedPoint2D(theObject, myOptionParam); return true; } return false; diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.h b/src/ModuleBase/ModuleBase_WidgetPoint2D.h index 4a34641a7..5c7269520 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.h +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.h @@ -39,10 +39,10 @@ public: virtual bool setValue(ModuleBase_WidgetValue* theValue); /// Saves the internal parameters to the given feature - /// \param theFeature a model feature to be changed - virtual bool storeValue(FeaturePtr theFeature) const; + /// \param theObject a model feature to be changed + virtual bool storeValue(ObjectPtr theObject) const; - virtual bool restoreValue(FeaturePtr theFeature); + virtual bool restoreValue(ObjectPtr theObject); /// Returns the internal parent wiget control, that can be shown anywhere /// \returns the widget @@ -57,13 +57,13 @@ public: /// \param theEvent the processed event virtual bool eventFilter(QObject *theObject, QEvent *theEvent); - bool initFromPrevious(FeaturePtr theFeature); + bool initFromPrevious(ObjectPtr theObject); signals: /// Signal about the point 2d set to the feature /// \param the feature /// \param the attribute of the feature - void storedPoint2D(FeaturePtr theFeature, const std::string& theAttribute); + void storedPoint2D(ObjectPtr theObject, const std::string& theAttribute); protected: /// Fill the widget values by given point diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.cpp b/src/ModuleBase/ModuleBase_WidgetSelector.cpp index 36f6af51f..88aa9c381 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelector.cpp @@ -99,14 +99,14 @@ ModuleBase_WidgetSelector::~ModuleBase_WidgetSelector() } //******************************************************************** -bool ModuleBase_WidgetSelector::storeValue(FeaturePtr theFeature) const +bool ModuleBase_WidgetSelector::storeValue(ObjectPtr theObject) const { - DataPtr aData = theFeature->data(); + DataPtr aData = theObject->data(); boost::shared_ptr aRef = boost::dynamic_pointer_cast(aData->attribute(attributeID())); - FeaturePtr aFeature = aRef->value(); - if (!(aFeature && aFeature->isSame(mySelectedObject))) { + ObjectPtr aObject = aRef->value(); + if (!(aObject && aObject->isSame(mySelectedObject))) { aRef->setValue(mySelectedObject); Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); } @@ -114,9 +114,9 @@ bool ModuleBase_WidgetSelector::storeValue(FeaturePtr theFeature) const } //******************************************************************** -bool ModuleBase_WidgetSelector::restoreValue(FeaturePtr theFeature) +bool ModuleBase_WidgetSelector::restoreValue(ObjectPtr theObject) { - DataPtr aData = theFeature->data(); + DataPtr aData = theObject->data(); boost::shared_ptr aRef = aData->reference(attributeID()); bool isBlocked = this->blockSignals(true); diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.h b/src/ModuleBase/ModuleBase_WidgetSelector.h index 61fba0049..b1782d072 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetSelector.h @@ -33,10 +33,10 @@ public: virtual ~ModuleBase_WidgetSelector(); /// Saves the internal parameters to the given feature - /// \param theFeature a model feature to be changed - virtual bool storeValue(FeaturePtr theFeature) const; + /// \param theObject a model feature to be changed + virtual bool storeValue(ObjectPtr theObject) const; - virtual bool restoreValue(FeaturePtr theFeature); + virtual bool restoreValue(ObjectPtr theObject); /// Returns the internal parent wiget control, that can be shown anywhere /// \returns the widget @@ -66,7 +66,7 @@ private: void enableOthersControls(bool toEnable) const; void updateSelectionName(); void raisePanel() const; - bool isAccepted(const ObjectPtr theFeature) const; + bool isAccepted(const ObjectPtr theObject) const; static TopAbs_ShapeEnum shapeType(const QString& theType); diff --git a/src/PartSet/PartSet_TestOCC.cpp b/src/PartSet/PartSet_TestOCC.cpp index f447f5966..4cc60a5c4 100644 --- a/src/PartSet/PartSet_TestOCC.cpp +++ b/src/PartSet/PartSet_TestOCC.cpp @@ -18,7 +18,7 @@ #include static double myTestDelta; -static FeaturePtr myTestFeature; +static ResultPtr myTestObject; #include #include @@ -31,13 +31,13 @@ static FeaturePtr myTestFeature; void PartSet_TestOCC::testSelection(XGUI_Workshop* theWorkshop) { - if (!myTestFeature) { + if (!myTestObject) { PartSet_TestOCC::createTestLine(theWorkshop); PartSet_TestOCC::moveMouse(theWorkshop->viewer()->AISContext(), theWorkshop->viewer()->activeView()); PartSet_TestOCC::changeTestLine(theWorkshop); } - boost::shared_ptr anIO = theWorkshop->displayer()->getAISObject(myTestFeature); + boost::shared_ptr anIO = theWorkshop->displayer()->getAISObject(myTestObject); if (!anIO->empty()) { theWorkshop->viewer()->AISContext()->MoveTo(0, 0, theWorkshop->viewer()->activeView()); theWorkshop->viewer()->AISContext()->Select(0, 0, 2500, 2500, theWorkshop->viewer()->activeView()); @@ -182,10 +182,10 @@ void PartSet_TestOCC::createTestLine(XGUI_Workshop* theWorkshop) //aModes.push_back(TopAbs_VERTEX); //aModes.push_back(TopAbs_EDGE); //aDisplayer->activateInLocalContext(aFeature, aModes, true); - myTestFeature = aFeature; + myTestObject = aFeature; QFeatureList aFeatureList; - aFeatureList.append(myTestFeature); + aFeatureList.append(myTestObject); aDisplayer->setSelected(aFeatureList, true); } } @@ -193,9 +193,9 @@ void PartSet_TestOCC::createTestLine(XGUI_Workshop* theWorkshop) void PartSet_TestOCC::changeTestLine(XGUI_Workshop* theWorkshop) { // change the line - if (!myTestFeature) + if (!myTestObject) return; - FeaturePtr aFeature = myTestFeature; + FeaturePtr aFeature = myTestObject; myTestDelta = myTestDelta - 50; double aDelta = myTestDelta; @@ -216,7 +216,7 @@ void PartSet_TestOCC::changeTestLine(XGUI_Workshop* theWorkshop) //aDisplayer->activateInLocalContext(aFeature, aModes, true); /*QFeatureList aFeatureList; - aFeatureList.append(myTestFeature); + aFeatureList.append(myTestObject); theWorkshop->displayer()->setSelected(aFeatureList, true);*/ theWorkshop->displayer()->updateViewer(); diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index ee9370825..d7dcfce78 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -99,27 +100,30 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const { QMenu* aMenu = new QMenu(); XGUI_SelectionMgr* aSelMgr = myWorkshop->selector(); - QList aFeatures = aSelMgr->selection()->selectedObjects(); - if (aFeatures.size() == 1) { + QList aObjects = aSelMgr->selection()->selectedObjects(); + if (aObjects.size() == 1) { PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); - FeaturePtr aFeature = aFeatures.first(); + ObjectPtr aObject = aObjects.first(); //Process Feature - if (aFeature) { - if (aFeature->getKind() == PARTSET_PART_KIND) { - ObjectPtr aObject = boost::dynamic_pointer_cast(aFeature); - DocumentPtr aFeaDoc = aObject->featureRef()->data()->docRef("PartDocument")->value(); + if (aObject) { + ResultPartPtr aPart = boost::dynamic_pointer_cast(aObject); + if (aPart) { + DocumentPtr aFeaDoc = aPart->document(); if (aMgr->currentDocument() == aFeaDoc) aMenu->addAction(action("DEACTIVATE_PART_CMD")); else aMenu->addAction(action("ACTIVATE_PART_CMD")); } else { - aMenu->addAction(action("EDIT_CMD")); - - XGUI_Displayer* aDisplayer = myWorkshop->displayer(); - if (aDisplayer->isVisible(aFeature)) - aMenu->addAction(action("HIDE_CMD")); - else - aMenu->addAction(action("SHOW_CMD")); + ResultPtr aResult = boost::dynamic_pointer_cast(aObject); + if (aResult) { + aMenu->addAction(action("EDIT_CMD")); + + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + if (aDisplayer->isVisible(aResult)) + aMenu->addAction(action("HIDE_CMD")); + else + aMenu->addAction(action("SHOW_CMD")); + } } aMenu->addAction(action("DELETE_CMD")); aMenu->addSeparator(); diff --git a/src/XGUI/XGUI_DataTreeModel.h b/src/XGUI/XGUI_DataTreeModel.h index ece7040f6..0b8844e2f 100644 --- a/src/XGUI/XGUI_DataTreeModel.h +++ b/src/XGUI/XGUI_DataTreeModel.h @@ -7,6 +7,7 @@ #include #include +#include #include #include diff --git a/src/XGUI/XGUI_DocumentDataModel.h b/src/XGUI/XGUI_DocumentDataModel.h index 225a7108f..c49c66965 100644 --- a/src/XGUI/XGUI_DocumentDataModel.h +++ b/src/XGUI/XGUI_DocumentDataModel.h @@ -4,10 +4,11 @@ #include "XGUI.h" #include +#include -#include #include +#include #include class ModelAPI_Document; @@ -52,22 +53,22 @@ public: Qt::ItemFlags flags(const QModelIndex& theIndex) const; - //! Returns Feature object by the given Model index. - //! Returns 0 if the given index is not index of a feature + //! Returns an object by the given Model index. + //! Returns 0 if the given index is not index of an object ObjectPtr object(const QModelIndex& theIndex) const; - QModelIndex featureIndex(const ObjectPtr theFeature) const; + QModelIndex objectIndex(const ObjectPtr theObject) const; - //! Returns QModelIndex which corresponds to the given feature if this is a part - //! If the feature is not found then index is not valid - QModelIndex partIndex(const ObjectPtr& theFeature) const; + //! Returns QModelIndex which corresponds to the given part + //! If the object is not found then index is not valid + QModelIndex partIndex(const ResultPartPtr& thePart) const; //! Activates a part data model if the index is a Part node index. //! Returns true if active part changed. bool activatedIndex(const QModelIndex& theIndex); - //! Retrurns Feature which corresponds to active part - ObjectPtr activePart() const; + //! Retrurns active part + ResultPartPtr activePart() const; //! Retrurns QModelIndex of active part QModelIndex activePartIndex() const { return myActivePartIndex; } diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 27b927562..5d9d000e3 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -46,7 +46,7 @@ void XGUI_DataTree::onSelectionChanged(const QItemSelection& theSelected, XGUI_DocumentDataModel* aModel = dataModel(); QModelIndexList::const_iterator aIt; for (aIt = aIndexes.constBegin(); aIt != aIndexes.constEnd(); ++aIt) { - FeaturePtr aFeature = aModel->feature(*aIt); + ObjectPtr aFeature = aModel->feature(*aIt); if (aFeature) mySelectedData.append(aFeature); } @@ -83,7 +83,7 @@ void XGUI_DataTree::commitData(QWidget* theEditor) QLineEdit* aEditor = dynamic_cast(theEditor); if (aEditor) { QString aRes = aEditor->text(); - FeaturePtr aFeature = mySelectedData.first(); + ObjectPtr aFeature = mySelectedData.first(); PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); aMgr->rootDocument()->startOperation(); if (!XGUI_Tools::isModelObject(aFeature)) @@ -147,15 +147,15 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent) aLabelWgt->setFrameShadow(myTreeView->frameShadow()); connect(myTreeView, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); - connect(myTreeView, SIGNAL(activePartChanged(FeaturePtr)), this, SLOT(onActivePartChanged(FeaturePtr))); - connect(myTreeView, SIGNAL(activePartChanged(FeaturePtr)), this, SIGNAL(activePartChanged(FeaturePtr))); + connect(myTreeView, SIGNAL(activePartChanged(ObjectPtr)), this, SLOT(onActivePartChanged(ObjectPtr))); + connect(myTreeView, SIGNAL(activePartChanged(ObjectPtr)), this, SIGNAL(activePartChanged(ObjectPtr))); connect(myActiveDocLbl, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(onLabelContextMenuRequested(const QPoint&))); connect(myTreeView, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this, SLOT(onContextMenuRequested(QContextMenuEvent*))); - onActivePartChanged(FeaturePtr()); + onActivePartChanged(ObjectPtr()); // Create internal actions QAction* aAction = new QAction(QIcon(":pictures/rename_edit.png"), tr("Rename"), this); @@ -170,7 +170,7 @@ XGUI_ObjectsBrowser::~XGUI_ObjectsBrowser() } //*************************************************** -void XGUI_ObjectsBrowser::onActivePartChanged(FeaturePtr thePart) +void XGUI_ObjectsBrowser::onActivePartChanged(ObjectPtr thePart) { QPalette aPalet = myActiveDocLbl->palette(); if (thePart) { @@ -191,8 +191,8 @@ bool XGUI_ObjectsBrowser::eventFilter(QObject* obj, QEvent* theEvent) myTreeView->setExpanded(myDocModel->activePartIndex(), false); } myDocModel->deactivatePart(); - onActivePartChanged(FeaturePtr()); - emit activePartChanged(FeaturePtr()); + onActivePartChanged(ObjectPtr()); + emit activePartChanged(ObjectPtr()); } } else { // End of editing by mouse click @@ -235,7 +235,7 @@ void XGUI_ObjectsBrowser::closeDocNameEditing(bool toSave) } //*************************************************** -void XGUI_ObjectsBrowser::activatePart(const FeaturePtr& thePart) +void XGUI_ObjectsBrowser::activatePart(const ObjectPtr& thePart) { if (thePart) { QModelIndex aIndex = myDocModel->partIndex(thePart); @@ -250,7 +250,7 @@ void XGUI_ObjectsBrowser::activatePart(const FeaturePtr& thePart) myTreeView->setExpanded(aIndex, true); onActivePartChanged(myDocModel->feature(aIndex)); } else { - onActivePartChanged(FeaturePtr()); + onActivePartChanged(ObjectPtr()); } } } else { @@ -258,7 +258,7 @@ void XGUI_ObjectsBrowser::activatePart(const FeaturePtr& thePart) if (aIndex.isValid()) { myDocModel->activatedIndex(aIndex); myTreeView->setExpanded(aIndex, false); - onActivePartChanged(FeaturePtr()); + onActivePartChanged(ObjectPtr()); } } } @@ -266,8 +266,8 @@ void XGUI_ObjectsBrowser::activatePart(const FeaturePtr& thePart) //*************************************************** void XGUI_ObjectsBrowser::onContextMenuRequested(QContextMenuEvent* theEvent) { - myFeaturesList = myTreeView->selectedFeatures(); - bool toEnable = myFeaturesList.size() > 0; + myObjectsList = myTreeView->selectedFeatures(); + bool toEnable = myObjectsList.size() > 0; foreach(QAction* aCmd, actions()) { aCmd->setEnabled(toEnable); } @@ -277,9 +277,9 @@ void XGUI_ObjectsBrowser::onContextMenuRequested(QContextMenuEvent* theEvent) //*************************************************** void XGUI_ObjectsBrowser::onLabelContextMenuRequested(const QPoint& thePnt) { - myFeaturesList.clear(); + myObjectsList.clear(); //Empty feature pointer means that selected root document - myFeaturesList.append(FeaturePtr()); + myObjectsList.append(ObjectPtr()); foreach(QAction* aCmd, actions()) { aCmd->setEnabled(true); @@ -291,14 +291,14 @@ void XGUI_ObjectsBrowser::onLabelContextMenuRequested(const QPoint& thePnt) //*************************************************** void XGUI_ObjectsBrowser::onEditItem() { - if (myFeaturesList.size() > 0) { - FeaturePtr aFeature = myFeaturesList.first(); + if (myObjectsList.size() > 0) { + ObjectPtr aFeature = myObjectsList.first(); if (aFeature) { // Selection happens in TreeView // Find index which corresponds the feature QModelIndex aIndex; foreach(QModelIndex aIdx, selectedIndexes()) { - FeaturePtr aFea = dataModel()->feature(aIdx); - if (dataModel()->feature(aIdx)->isSame(aFeature)) { + ObjectPtr aFea = dataModel()->object(aIdx); + if (dataModel()->object(aIdx)->isSame(aFeature)) { aIndex = aIdx; break; } @@ -320,7 +320,7 @@ void XGUI_ObjectsBrowser::onEditItem() //*************************************************** void XGUI_ObjectsBrowser::onSelectionChanged() { - myFeaturesList = myTreeView->selectedFeatures(); + myObjectsList = myTreeView->selectedObjects(); emit selectionChanged(); } @@ -332,14 +332,14 @@ void XGUI_ObjectsBrowser::rebuildDataTree() } //*************************************************** -void XGUI_ObjectsBrowser::setFeaturesSelected(const QFeatureList& theFeatures) +void XGUI_ObjectsBrowser::setObjectsSelected(const QList& theObjects) { QList theIndexes; QItemSelectionModel* aSelectModel = myTreeView->selectionModel(); aSelectModel->clear(); - foreach(FeaturePtr aFeature, theFeatures) { - QModelIndex aIndex = myDocModel->featureIndex(aFeature); + foreach(ObjectPtr aFeature, theObjects) { + QModelIndex aIndex = myDocModel->objectIndex(aFeature); if (aIndex.isValid()) { aSelectModel->select(aIndex, QItemSelectionModel::Select); } diff --git a/src/XGUI/XGUI_ObjectsBrowser.h b/src/XGUI/XGUI_ObjectsBrowser.h index 0924af4b5..edcddc628 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.h +++ b/src/XGUI/XGUI_ObjectsBrowser.h @@ -20,15 +20,15 @@ public: XGUI_DataTree(QWidget* theParent); virtual ~XGUI_DataTree(); - //! Returns list of currently selected features - QList selectedFeatures() const { return mySelectedData; } + //! Returns list of currently selected objects + QList selectedObjects() const { return mySelectedData; } XGUI_DocumentDataModel* dataModel() const; signals: //! Emited when selection is changed void selectionChanged(); - void activePartChanged(FeaturePtr thePart); + void activePartChanged(ObjectPtr thePart); //! Emited on context menu request void contextMenuRequested(QContextMenuEvent* theEvent); @@ -64,10 +64,10 @@ public: //! Returns Model which provides access to data objects XGUI_DocumentDataModel* dataModel() const { return myDocModel; } - //! Returns list of currently selected features + //! Returns list of currently selected objects QList selectedObjects() const { return myObjectsList; } - void setFeaturesSelected(const QFeatureList& theFeatures); + void setObjectsSelected(const QList& theObjects); //! Returns currently selected indexes QModelIndexList selectedIndexes() const { return myTreeView->selectionModel()->selectedIndexes(); } @@ -76,7 +76,7 @@ public: XGUI_DataTree* treeView() const { return myTreeView; } //! Activates currently selected part. Signal activePartChanged will not be sent - void activatePart(const FeaturePtr& thePart); + void activatePart(const ObjectPtr& thePart); void rebuildDataTree(); @@ -85,7 +85,7 @@ signals: void selectionChanged(); //! Emited when current active document is changed - void activePartChanged(FeaturePtr thePart); + void activePartChanged(ObjectPtr thePart); //! Emited on context menu request void contextMenuRequested(QContextMenuEvent* theEvent); @@ -94,7 +94,7 @@ protected: virtual bool eventFilter(QObject* obj, QEvent* theEvent); private slots: - void onActivePartChanged(FeaturePtr thePart); + void onActivePartChanged(ObjectPtr thePart); void onContextMenuRequested(QContextMenuEvent* theEvent); void onLabelContextMenuRequested(const QPoint& thePnt); diff --git a/src/XGUI/XGUI_PartDataModel.h b/src/XGUI/XGUI_PartDataModel.h index b1f808995..b170ec1cd 100644 --- a/src/XGUI/XGUI_PartDataModel.h +++ b/src/XGUI/XGUI_PartDataModel.h @@ -103,7 +103,7 @@ public: virtual QModelIndex findGroup(const std::string& theGroup) const; //! Return a Part object - virtual ObjectPtr part() const; + virtual ResultPartPtr part() const; private: diff --git a/src/XGUI/XGUI_Selection.h b/src/XGUI/XGUI_Selection.h index 84b73f0f7..9202e97bb 100644 --- a/src/XGUI/XGUI_Selection.h +++ b/src/XGUI/XGUI_Selection.h @@ -28,31 +28,31 @@ public: /// Returns a list of viewer selected presentations /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build /// \return list of presentations - std::list getSelected(int theShapeTypeToSkip = -1) const; + virtual std::list getSelected(int theShapeTypeToSkip = -1) const; /// Returns a list of viewer highlited presentations /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build /// \return list of presentations - std::list getHighlighted(int theShapeTypeToSkip = -1) const; + virtual std::list getHighlighted(int theShapeTypeToSkip = -1) const; /** * Returns list of currently selected objects */ - QList selectedObjects() const; + virtual QList selectedObjects() const; /** * Returns list of currently selected results */ - QResultList selectedResults() const; + virtual QResultList selectedResults() const; //! Returns list of currently selected QModelIndexes - QModelIndexList selectedIndexes() const; + virtual QModelIndexList selectedIndexes() const; //! Returns list of currently selected AIS objects - void selectedAISObjects(AIS_ListOfInteractive& theList) const; + virtual void selectedAISObjects(AIS_ListOfInteractive& theList) const; //! Returns list of currently selected shapes - void selectedShapes(NCollection_List& theList) const; + virtual void selectedShapes(NCollection_List& theList) const; private: XGUI_Workshop* myWorkshop; diff --git a/src/XGUI/XGUI_SelectionMgr.cpp b/src/XGUI/XGUI_SelectionMgr.cpp index d1d9f83a0..dc5db4e2b 100644 --- a/src/XGUI/XGUI_SelectionMgr.cpp +++ b/src/XGUI/XGUI_SelectionMgr.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include @@ -40,24 +42,30 @@ void XGUI_SelectionMgr::connectViewers() //************************************************************** void XGUI_SelectionMgr::onObjectBrowserSelection() { - QFeatureList aFeatures = myWorkshop->objectBrowser()->selectedFeatures(); + QList aObjects = myWorkshop->objectBrowser()->selectedObjects(); + QResultList aResults; + foreach(ObjectPtr aObject, aObjects) { + ResultPtr aRes = boost::dynamic_pointer_cast(aObject); + if (aRes) + aResults.append(aRes); + } XGUI_Displayer* aDisplayer = myWorkshop->displayer(); - aDisplayer->setSelected(aFeatures); + aDisplayer->setSelected(aResults); emit selectionChanged(); } //************************************************************** void XGUI_SelectionMgr::onViewerSelection() { - QFeatureList aFeatures; + QList aFeatures; Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) { Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive(); - FeaturePtr aFeature = myWorkshop->displayer()->getFeature(anIO); - if (aFeature) - aFeatures.append(aFeature); + ResultPtr aResult = myWorkshop->displayer()->getResult(anIO); + if (aResult) + aFeatures.append(aResult); } - myWorkshop->objectBrowser()->setFeaturesSelected(aFeatures); + myWorkshop->objectBrowser()->setObjectsSelected(aFeatures); emit selectionChanged(); }