From 0dfd4418a9449cfd521cbdc486ea11588f42d7f3 Mon Sep 17 00:00:00 2001 From: vsv Date: Tue, 31 Jul 2018 18:14:19 +0300 Subject: [PATCH] Show Complex nodes --- src/PartSet/PartSet_TreeNodes.cpp | 230 ++++++++++++++++++++---------- src/PartSet/PartSet_TreeNodes.h | 68 +++++---- 2 files changed, 191 insertions(+), 107 deletions(-) diff --git a/src/PartSet/PartSet_TreeNodes.cpp b/src/PartSet/PartSet_TreeNodes.cpp index 6219084db..415f1a44f 100644 --- a/src/PartSet/PartSet_TreeNodes.cpp +++ b/src/PartSet/PartSet_TreeNodes.cpp @@ -182,7 +182,81 @@ PartSet_ObjectNode::VisibilityState PartSet_ObjectNode::visibilityState() const return NoneState; } +void PartSet_ObjectNode::update() +{ + ResultBodyPtr aCompRes = std::dynamic_pointer_cast(myObject); + if (aCompRes.get()) { + 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_ObjectNode::objectCreated(const QObjectPtrList& theObjects) +{ + QTreeNodesList aResult; + + ResultBodyPtr aCompRes = std::dynamic_pointer_cast(myObject); + if (aCompRes.get()) { + 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_ObjectNode::objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup) +{ + QTreeNodesList aResult; + ResultBodyPtr aCompRes = std::dynamic_pointer_cast(myObject); + if (aCompRes.get()) { + 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; +} ////////////////////////////////////////////////////////////////////////////////// PartSet_FolderNode::PartSet_FolderNode(ModuleBase_ITreeNode* theParent, FolderType theType) @@ -252,9 +326,9 @@ Qt::ItemFlags PartSet_FolderNode::flags(int theColumn) const ModuleBase_ITreeNode* PartSet_FolderNode::createNode(const ObjectPtr& theObj) { - ResultBodyPtr aCompRes = std::dynamic_pointer_cast(theObj); - if (aCompRes.get()) - return new PartSet_CompsolidNode(theObj, this); + //ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast(theObj); + //if (aCompRes.get()) + // return new PartSet_CompsolidNode(theObj, this); return new PartSet_ObjectNode(theObj, this); } @@ -922,78 +996,78 @@ void PartSet_ObjectFolderNode::getFirstAndLastIndex(int& theFirst, int& theLast) ////////////////////////////////////////////////////////////////////////////////// -PartSet_CompsolidNode::PartSet_CompsolidNode(const ObjectPtr& theObj, - ModuleBase_ITreeNode* theParent) : PartSet_ObjectNode(theObj, theParent) -{ - update(); -} - -void PartSet_CompsolidNode::update() -{ - ResultBodyPtr 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; - - ResultBodyPtr 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; - ResultBodyPtr 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 +//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 7ab9337ad..8a78317ea 100644 --- a/src/PartSet/PartSet_TreeNodes.h +++ b/src/PartSet/PartSet_TreeNodes.h @@ -71,10 +71,20 @@ public: /// theObj a new object void setObject(ObjectPtr theObj) { myObject = theObj; } + virtual VisibilityState visibilityState() const; + /// Updates sub-nodes of the node - virtual void update() {} + virtual void update(); - virtual VisibilityState visibilityState() const; + /// 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); protected: ObjectPtr myObject; @@ -324,32 +334,32 @@ private: * \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); - -}; +//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 -- 2.39.2