From: vsv Date: Mon, 24 Jun 2019 13:17:49 +0000 (+0300) Subject: Make step as Object X-Git-Tag: VEDF2019Lot4~103^2~15 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=616dc5cdcfe074aa484a261b03f6763928d6e829;p=modules%2Fshaper.git Make step as Object --- diff --git a/src/Model/Model_ResultField.cpp b/src/Model/Model_ResultField.cpp index 7eaa8b2b4..f345f733f 100644 --- a/src/Model/Model_ResultField.cpp +++ b/src/Model/Model_ResultField.cpp @@ -37,7 +37,7 @@ Model_ResultField::Model_ResultField(std::shared_ptr theOwnerData Model_ResultField::~Model_ResultField() { while(mySteps.size() > 0) { - delete mySteps.back(); + //delete mySteps.back(); mySteps.pop_back(); } } @@ -106,11 +106,11 @@ void Model_ResultField::updateSteps() int aNbSteps = stepsSize(); if (mySteps.size() != aNbSteps) { while(mySteps.size() > aNbSteps) { - delete mySteps.back(); + //delete mySteps.back(); mySteps.pop_back(); } while(mySteps.size() < aNbSteps) { - mySteps.push_back(new Model_ResultField::Model_FieldStep(this, int(mySteps.size()))); + mySteps.push_back(FieldStepPtr(new Model_ResultField::Model_FieldStep(this, int(mySteps.size())))); } } } @@ -143,7 +143,7 @@ std::string Model_ResultField::textLine(int theLine) const // used by GUI only // LCOV_EXCL_START -ModelAPI_ResultField::ModelAPI_FieldStep* Model_ResultField::step(int theId) const +std::shared_ptr Model_ResultField::step(int theId) const { if (theId < mySteps.size()) { return mySteps[theId]; diff --git a/src/Model/Model_ResultField.h b/src/Model/Model_ResultField.h index 52d0b82aa..307861c34 100644 --- a/src/Model/Model_ResultField.h +++ b/src/Model/Model_ResultField.h @@ -39,12 +39,14 @@ public: { public: Model_FieldStep(ModelAPI_ResultField* theParent, int theId) - : myParent(theParent), myId(theId) {}; + : ModelAPI_ResultField::ModelAPI_FieldStep(), myParent(theParent), myId(theId) {}; virtual ModelAPI_ResultField* field() const { return myParent; } virtual int id() const { return myId; } + virtual std::shared_ptr document() const { return myParent->document(); } + private: ModelAPI_ResultField* myParent; int myId; @@ -66,7 +68,7 @@ public: /// Returns step object /// \param theId an id of the object - MODEL_EXPORT virtual ModelAPI_ResultField::ModelAPI_FieldStep* step(int theId) const; + MODEL_EXPORT virtual std::shared_ptr step(int theId) const; /// Removes the stored builders MODEL_EXPORT virtual ~Model_ResultField(); @@ -80,7 +82,7 @@ protected: private: void updateSteps(); - std::vector mySteps; + std::vector mySteps; }; #endif diff --git a/src/ModelAPI/ModelAPI_ResultField.cpp b/src/ModelAPI/ModelAPI_ResultField.cpp index 760887376..15f8bba96 100644 --- a/src/ModelAPI/ModelAPI_ResultField.cpp +++ b/src/ModelAPI/ModelAPI_ResultField.cpp @@ -18,6 +18,8 @@ // #include "ModelAPI_ResultField.h" +#include "ModelAPI_Events.h" +#include ModelAPI_ResultField::~ModelAPI_ResultField() { @@ -28,3 +30,12 @@ std::string ModelAPI_ResultField::groupName() { return group(); } + +void ModelAPI_ResultField::ModelAPI_FieldStep::setDisplayed(const bool theDisplay) +{ + myIsDisplayed = theDisplay; + //static Events_Loop* aLoop = Events_Loop::loop(); + //static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + //static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); + //aECreator->sendUpdated(FieldStepPtr(this), EVENT_DISP); +} diff --git a/src/ModelAPI/ModelAPI_ResultField.h b/src/ModelAPI/ModelAPI_ResultField.h index eb9d4a7b6..2393be2bf 100644 --- a/src/ModelAPI/ModelAPI_ResultField.h +++ b/src/ModelAPI/ModelAPI_ResultField.h @@ -35,12 +35,45 @@ class ModelAPI_ResultField : public ModelAPI_Result { public: - class ModelAPI_FieldStep : public ModelAPI_Entity + class ModelAPI_FieldStep : public ModelAPI_Object { public: virtual ModelAPI_ResultField* field() const = 0; virtual int id() const = 0; + + /// Returns the group identifier of this result + inline static std::string group() + { + static std::string MY_GROUP = "FieldRersultStep"; + return MY_GROUP; + } + + /// Returns the group identifier of this object + virtual std::string groupName() { return group(); } + + /// Request for initialization of data model of the object: adding all attributes + virtual void initAttributes() {} + + /// Returns the feature is disabled or not. + virtual bool isDisabled() { return false; } + + /// Returns true if object must be displayed in the viewer: flag is stored in the + /// data model, so on undo/redo, open/save or recreation of object by history-playing it keeps + /// the original state in the current transaction. + virtual bool isDisplayed() { return myIsDisplayed; } + + /// Sets the displayed/hidden state of the object. If it is changed, sends the "redisplay" + /// signal. + MODELAPI_EXPORT virtual void setDisplayed(const bool theDisplay); + + protected: + /// This method is called just after creation of the object: it must initialize + /// all fields, normally initialized in the constructor + MODELAPI_EXPORT virtual void init() {} + + private: + bool myIsDisplayed; }; MODELAPI_EXPORT virtual ~ModelAPI_ResultField(); @@ -70,7 +103,7 @@ public: /// Returns step object /// \param theId an id of the object - virtual ModelAPI_FieldStep* step(int theId) const = 0; + virtual std::shared_ptr step(int theId) const = 0; }; //! Pointer on feature object diff --git a/src/PartSet/PartSet_TreeNodes.cpp b/src/PartSet/PartSet_TreeNodes.cpp index c08539925..b49acbb10 100644 --- a/src/PartSet/PartSet_TreeNodes.cpp +++ b/src/PartSet/PartSet_TreeNodes.cpp @@ -273,11 +273,11 @@ void PartSet_ObjectNode::update() } } else if (aFieldRes.get()) { - ModelAPI_ResultField::ModelAPI_FieldStep* aStep = aFieldRes->step(i); + FieldStepPtr aStep = aFieldRes->step(i); if (i < myChildren.size()) { PartSet_StepNode* aStepNode = static_cast(myChildren.at(i)); - if (aStepNode->entity() != aStep) { - aStepNode->setEntity(aStep); + if (aStepNode->object() != aStep) { + aStepNode->setObject(aStep); } } else { @@ -327,11 +327,11 @@ QTreeNodesList PartSet_ObjectNode::objectCreated(const QObjectPtrList& theObject } } else { - ModelAPI_ResultField::ModelAPI_FieldStep* aStep = aFieldRes->step(i); + FieldStepPtr aStep = aFieldRes->step(i); if (i < myChildren.size()) { PartSet_StepNode* aStepNode = static_cast(myChildren.at(i)); - if (aStepNode->entity() != aStep) { - aStepNode->setEntity(aStep); + if (aStepNode->object() != aStep) { + aStepNode->setObject(aStep); } } else { @@ -1194,11 +1194,24 @@ QTreeNodesList PartSet_ObjectFolderNode::objectsDeleted(const DocumentPtr& theDo QVariant PartSet_StepNode::data(int theColumn, int theRole) const { if ((theColumn == 1) && (theRole == Qt::DisplayRole)) { - ModelAPI_ResultField::ModelAPI_FieldStep* aStep = - dynamic_cast(myEntity); + FieldStepPtr aStep = + std::dynamic_pointer_cast(myObject); return "Step " + QString::number(aStep->id() + 1) + " " + aStep->field()->textLine(aStep->id()).c_str(); } - return PartSet_TreeNode::data(theColumn, theRole); + return PartSet_ObjectNode::data(theColumn, theRole); +} + +ModuleBase_ITreeNode::VisibilityState PartSet_StepNode::visibilityState() const +{ + Qt::ItemFlags aFlags = flags(1); + if (aFlags == Qt::ItemFlags()) + return NoneState; + + ModuleBase_IWorkshop* aWork = workshop(); + if (aWork->isVisible(myObject)) + return Visible; + else + return Hidden; } diff --git a/src/PartSet/PartSet_TreeNodes.h b/src/PartSet/PartSet_TreeNodes.h index 014c5895d..9167859c1 100644 --- a/src/PartSet/PartSet_TreeNodes.h +++ b/src/PartSet/PartSet_TreeNodes.h @@ -333,11 +333,11 @@ public: * \ingroup Modules * Implementation of a node for compsolid representation */ -class PartSet_StepNode : public PartSet_TreeNode +class PartSet_StepNode : public PartSet_ObjectNode { public: - PartSet_StepNode(ModelAPI_Entity* theEnt, ModuleBase_ITreeNode* theParent) : - PartSet_TreeNode(theParent), myEntity(theEnt) {} + PartSet_StepNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent) : + PartSet_ObjectNode(theObj, theParent) {} static std::string typeId() { @@ -350,16 +350,7 @@ public: /// Returns the node representation according to theRole. virtual QVariant data(int theColumn, int theRole) const; - ModelAPI_Entity* entity() const { - return myEntity; - } - - void setEntity(ModelAPI_Entity* theEnt) { - myEntity = theEnt; - } - -private: - ModelAPI_Entity* myEntity; + virtual VisibilityState visibilityState() const; }; #endif diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 82f6e74e4..e3dfb0935 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -252,6 +253,24 @@ void XGUI_DataTree::processEyeClick(const QModelIndex& theIndex) Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); update(theIndex); } + else { + FieldStepPtr aStep = + std::dynamic_pointer_cast(aObj); + if (aStep.get()) { + // Only one step from a field can be visible at once + int aId = aStep->id(); + ModelAPI_ResultField* aField = aStep->field(); + aField->setDisplayed(false); + for (int i = 0; i < aField->stepsSize(); i++) { + aField->step(i)->setDisplayed(i == aId); + static Events_Loop* aLoop = Events_Loop::loop(); + static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); + aECreator->sendUpdated(aField->step(i), EVENT_DISP); + } + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + } + } // Update list of selected objects because this event happens after // selection event in object browser if (aObjBrowser) {