return aDefaultFlag;
}
+ModuleBase_ITreeNode* PartSet_FolderNode::createNode(const ObjectPtr& theObj)
+{
+ ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObj);
+ if (aCompRes.get())
+ return new PartSet_CompsolidNode(theObj, this);
+ return new PartSet_ObjectNode(theObj, this);
+}
+
void PartSet_FolderNode::update()
{
DocumentPtr aDoc = document();
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
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);
}
}
}
+ foreach(ModuleBase_ITreeNode* aNode, myChildren) {
+ aResult.append(aNode->objectCreated(theObjects));
+ }
return aResult;
}
}
if (aRemoved)
aResult.append(this);
+
+ foreach(ModuleBase_ITreeNode* aNode, myChildren) {
+ aResult.append(aNode->objectsDeleted(theDoc, theGroup));
+ }
}
return aResult;
}
{
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
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<ModelAPI_ResultCompSolid>(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<ModelAPI_ResultCompSolid>(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<ModelAPI_ResultCompSolid>(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
/// 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() {}
private:
std::string groupName() const;
+ ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
+
FolderType myType;
};
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
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)) {