From 2e688609a4fa5428edd3700f1bce92406d3ade18 Mon Sep 17 00:00:00 2001 From: vsv Date: Tue, 24 Jul 2018 12:14:06 +0300 Subject: [PATCH] Compsolid nodes added --- src/PartSet/PartSet_TreeNodes.cpp | 111 +++++++++++++++++++++++++++--- src/PartSet/PartSet_TreeNodes.h | 42 ++++++++++- src/XGUI/XGUI_DataModel.cpp | 8 ++- 3 files changed, 148 insertions(+), 13 deletions(-) diff --git a/src/PartSet/PartSet_TreeNodes.cpp b/src/PartSet/PartSet_TreeNodes.cpp index 0e5b92ecf..38a8e6e2b 100644 --- a/src/PartSet/PartSet_TreeNodes.cpp +++ b/src/PartSet/PartSet_TreeNodes.cpp @@ -249,6 +249,14 @@ Qt::ItemFlags PartSet_FolderNode::flags(int theColumn) const return aDefaultFlag; } +ModuleBase_ITreeNode* PartSet_FolderNode::createNode(const ObjectPtr& theObj) +{ + ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast(theObj); + if (aCompRes.get()) + return new PartSet_CompsolidNode(theObj, this); + return new PartSet_ObjectNode(theObj, this); +} + void PartSet_FolderNode::update() { DocumentPtr aDoc = document(); @@ -275,14 +283,18 @@ void PartSet_FolderNode::update() ObjectPtr aObj = aDoc->object(aGroup, i, true); if (i < myChildren.size()) { if (myChildren.at(i)->object() != aObj) { - PartSet_ObjectNode* aNode = new PartSet_ObjectNode(aObj, this); + ModuleBase_ITreeNode* aNode = createNode(aObj); myChildren.insert(i, aNode); } } else { - PartSet_ObjectNode* aNode = new PartSet_ObjectNode(aObj, this); + ModuleBase_ITreeNode* aNode = createNode(aObj); myChildren.append(aNode); } } + + foreach(ModuleBase_ITreeNode* aNode, myChildren) { + aNode->update(); + } } std::string PartSet_FolderNode::groupName() const @@ -316,7 +328,7 @@ QTreeNodesList PartSet_FolderNode::objectCreated(const QObjectPtrList& theObject if (aIdx != -1) { bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj); if (!aHasObject) { - PartSet_ObjectNode* aNode = new PartSet_ObjectNode(aObj, this); + ModuleBase_ITreeNode* aNode = createNode(aObj); aResult.append(aNode); if (aIdx < myChildren.size()) myChildren.insert(aIdx, aNode); @@ -326,6 +338,9 @@ QTreeNodesList PartSet_FolderNode::objectCreated(const QObjectPtrList& theObject } } } + foreach(ModuleBase_ITreeNode* aNode, myChildren) { + aResult.append(aNode->objectCreated(theObjects)); + } return aResult; } @@ -351,6 +366,10 @@ QTreeNodesList PartSet_FolderNode::objectsDeleted(const DocumentPtr& theDoc, } if (aRemoved) aResult.append(this); + + foreach(ModuleBase_ITreeNode* aNode, myChildren) { + aResult.append(aNode->objectsDeleted(theDoc, theGroup)); + } } return aResult; } @@ -360,13 +379,9 @@ QTreeNodesList PartSet_FeatureFolderNode::objectCreated(const QObjectPtrList& th { QTreeNodesList aResult; // Process all folders - ModuleBase_ITreeNode* aFoder = 0; foreach(ModuleBase_ITreeNode* aNode, myChildren) { - if ((aNode->type() == PartSet_FolderNode::typeId()) || - (aNode->type() == PartSet_PartRootNode::typeId())) { // aFolder node - QTreeNodesList aList = aNode->objectCreated(theObjects); - if (aList.size() > 0) - aResult.append(aList); + if (aNode->type() == PartSet_FolderNode::typeId()) { // aFolder node + aResult.append(aNode->objectCreated(theObjects)); } } // Process the root sub-objects @@ -880,3 +895,81 @@ void PartSet_ObjectFolderNode::getFirstAndLastIndex(int& theFirst, int& theLast) theFirst = aDoc->index(aFirstFeatureInFolder); theLast = aDoc->index(aLastFeatureInFolder); } + + +////////////////////////////////////////////////////////////////////////////////// +PartSet_CompsolidNode::PartSet_CompsolidNode(const ObjectPtr& theObj, + ModuleBase_ITreeNode* theParent) : PartSet_ObjectNode(theObj, theParent) +{ + update(); +} + +void PartSet_CompsolidNode::update() +{ + ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast(myObject); + int aNb = aCompRes->numberOfSubs(true); + ModuleBase_ITreeNode* aNode; + ResultBodyPtr aBody; + int i; + for (i = 0; i < aNb; i++) { + aBody = aCompRes->subResult(i, true); + if (i < myChildren.size()) { + aNode = myChildren.at(i); + if (aNode->object() != aBody) { + ((PartSet_ObjectNode*)aNode)->setObject(aBody); + } + } else { + aNode = new PartSet_ObjectNode(aBody, this); + myChildren.append(aNode); + } + } + // Delete extra objects + while (myChildren.size() > aNb) { + aNode = myChildren.takeLast(); + delete aNode; + } +} + +QTreeNodesList PartSet_CompsolidNode::objectCreated(const QObjectPtrList& theObjects) +{ + QTreeNodesList aResult; + + ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast(myObject); + int aNb = aCompRes->numberOfSubs(true); + ModuleBase_ITreeNode* aNode; + ResultBodyPtr aBody; + int i; + for (i = 0; i < aNb; i++) { + aBody = aCompRes->subResult(i, true); + if (i < myChildren.size()) { + aNode = myChildren.at(i); + if (aNode->object() != aBody) { + ((PartSet_ObjectNode*)aNode)->setObject(aBody); + aResult.append(aNode); + } + } else { + aNode = new PartSet_ObjectNode(aBody, this); + myChildren.append(aNode); + aResult.append(aNode); + } + } + return aResult; +} + +QTreeNodesList PartSet_CompsolidNode::objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup) +{ + QTreeNodesList aResult; + ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast(myObject); + int aNb = aCompRes->numberOfSubs(true); + ModuleBase_ITreeNode* aNode; + // Delete extra objects + bool isDeleted = false; + while (myChildren.size() > aNb) { + aNode = myChildren.takeLast(); + delete aNode; + isDeleted = true; + } + if (isDeleted) + aResult.append(this); + return aResult; +} \ No newline at end of file diff --git a/src/PartSet/PartSet_TreeNodes.h b/src/PartSet/PartSet_TreeNodes.h index 56aada4d8..7ab9337ad 100644 --- a/src/PartSet/PartSet_TreeNodes.h +++ b/src/PartSet/PartSet_TreeNodes.h @@ -67,6 +67,10 @@ public: /// Returns object referenced by the node (can be null) virtual ObjectPtr object() const { return myObject; } + /// Sets an object to the node + /// theObj a new object + void setObject(ObjectPtr theObj) { myObject = theObj; } + /// Updates sub-nodes of the node virtual void update() {} @@ -137,6 +141,8 @@ public: private: std::string groupName() const; + ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj); + FolderType myType; }; @@ -312,4 +318,38 @@ private: void getFirstAndLastIndex(int& theFirst, int& theLast) const; }; -#endif \ No newline at end of file + +///////////////////////////////////////////////////////////////////// +/** +* \ingroup Modules +* Implementation of a node for compsolid representation +*/ +class PartSet_CompsolidNode : public PartSet_ObjectNode +{ +public: + PartSet_CompsolidNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent); + + static std::string typeId() + { + static std::string myType = "CompSolid"; + return myType; + } + + virtual std::string type() const { return typeId(); } + + /// Updates sub-nodes of the node + virtual void update(); + + /// Process creation of objects. + /// \param theObjects a list of created objects + /// \return a list of nodes which corresponds to the created objects + virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects); + + /// Process deletion of objects. + /// \param theDoc a document where objects were deleted + /// \param theGroup a name of group where objects were deleted + virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup); + +}; + +#endif diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp index d677b8d94..5cfb09304 100644 --- a/src/XGUI/XGUI_DataModel.cpp +++ b/src/XGUI/XGUI_DataModel.cpp @@ -70,12 +70,14 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess QTreeNodesList aNodes = myRoot->objectCreated(aCreated); ModuleBase_ITreeNode* aParent; int aRow = 0; - QModelIndex aParentIndex; + QModelIndex aParentIndex1, aParentIndex2; foreach(ModuleBase_ITreeNode* aNode, aNodes) { aParent = aNode->parent(); aRow = aParent->nodeRow(aNode); - aParentIndex = getParentIndex(aNode, 0); - insertRows(aRow, 1, aParentIndex); + aParentIndex1 = getParentIndex(aNode, 0); + aParentIndex2 = getParentIndex(aNode, 2); + insertRows(aRow, 1, aParentIndex1); + dataChanged(aParentIndex1, aParentIndex2); } } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) { -- 2.39.2