ModuleBase_IWorkshop* aWork = workshop();
ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResObj);
if (aCompRes.get()) {
- VisibilityState aState = aCompRes->numberOfSubs(true) == 0 ?
- (aWork->isVisible(aCompRes) ? Visible : Hidden) : NoneState;
std::list<ResultPtr> aResultsList;
ModelAPI_Tools::allSubs(aCompRes, aResultsList);
+ VisibilityState aState = aResultsList.size() == 0 ?
+ (aWork->isVisible(aCompRes) ? Visible : Hidden) : NoneState;
std::list<ResultPtr>::const_iterator aIt;
- //for (int i = 0; i < aCompRes->numberOfSubs(true); i++) {
+ ResultBodyPtr aCompSub;
for (aIt = aResultsList.cbegin(); aIt != aResultsList.cend(); aIt++) {
- ResultPtr aSubRes = (*aIt); // aCompRes->subResult(i, true);
- VisibilityState aS = aWork->isVisible(aSubRes) ? Visible : Hidden;
- if (aState == NoneState)
- aState = aS;
- else if (aState != aS) {
- aState = SemiVisible;
- break;
+ ResultPtr aSubRes = (*aIt);
+ aCompSub = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aSubRes);
+ if (!(aCompSub.get() && aCompSub->numberOfSubs() > 0)) {
+ VisibilityState aS = aWork->isVisible(aSubRes) ? Visible : Hidden;
+ if (aState == NoneState)
+ aState = aS;
+ else if (aState != aS) {
+ aState = SemiVisible;
+ break;
+ }
}
}
return aState;
return NoneState;
}
-void PartSet_ObjectNode::update()
+int PartSet_ObjectNode::numberOfSubs() const
{
ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
- if (aCompRes.get()) {
- int aNb = aCompRes->numberOfSubs(true);
+ if (aCompRes.get())
+ return aCompRes->numberOfSubs(true);
+ else {
+ CompositeFeaturePtr aCompFeature =
+ std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myObject);
+ if (aCompFeature.get() && aCompFeature->data()->isValid())
+ return aCompFeature->numberOfSubs(true);
+ else {
+ ResultFieldPtr aFieldRes = std::dynamic_pointer_cast<ModelAPI_ResultField>(myObject);
+ if (aFieldRes.get())
+ return aFieldRes->stepsSize();
+ }
+ }
+ return 0;
+}
+
+
+ObjectPtr PartSet_ObjectNode::subObject(int theId) const
+{
+ ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
+ if (aCompRes.get())
+ return aCompRes->subResult(theId, true);
+ else {
+ CompositeFeaturePtr aCompFeature =
+ std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myObject);
+ if (aCompFeature.get())
+ return aCompFeature->subFeature(theId, true);
+ }
+ return ObjectPtr();
+}
+
+void PartSet_ObjectNode::update()
+{
+ int aNb = numberOfSubs();
+ if (aNb > 0) {
+ ResultFieldPtr aFieldRes = std::dynamic_pointer_cast<ModelAPI_ResultField>(myObject);
+
+ // If the object is a field result then delete extra sub-objects
+ if (aFieldRes.get()) {
+ while (myChildren.size() > aNb) {
+ ModuleBase_ITreeNode* aNode = myChildren.last();
+ myChildren.removeAll(aNode);
+ delete aNode;
+ }
+ }
+ else {
+ ObjectPtr aObj;
+ ModuleBase_ITreeNode* aNode;
+ int aId = 0;
+ while (aId < myChildren.size()) {
+ aNode = myChildren.at(aId);
+ aObj = subObject(aId);
+ if (aNode->object() != aObj) {
+ myChildren.removeAll(aNode);
+ delete aNode;
+ }
+ else
+ aId++;
+ }
+ }
+
ModuleBase_ITreeNode* aNode;
- ResultBodyPtr aBody;
+ ObjectPtr 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);
+ aBody = subObject(i);
+ if (aBody.get()) {
+ 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);
+ }
+ }
+ else if (aFieldRes.get()) {
+ ModelAPI_ResultField::ModelAPI_FieldStep* aStep = aFieldRes->step(i);
+ if (i < myChildren.size()) {
+ PartSet_StepNode* aStepNode = static_cast<PartSet_StepNode*>(myChildren.at(i));
+ if (aStepNode->entity() != aStep) {
+ aStepNode->setEntity(aStep);
+ }
+ }
+ else {
+ aNode = new PartSet_StepNode(aStep, this);
+ myChildren.append(aNode);
}
- } else {
- aNode = new PartSet_ObjectNode(aBody, this);
- myChildren.append(aNode);
}
}
// Delete extra objects
aNode->update();
}
}
+ else {
+ deleteChildren();
+ }
}
QTreeNodesList PartSet_ObjectNode::objectCreated(const QObjectPtrList& theObjects)
{
QTreeNodesList aResult;
-
- ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
- if (aCompRes.get()) {
- int aNb = aCompRes->numberOfSubs(true);
+ int aNb = numberOfSubs();
+ if (aNb > 0) {
ModuleBase_ITreeNode* aNode;
- ResultBodyPtr aBody;
+ ResultFieldPtr aFieldRes = std::dynamic_pointer_cast<ModelAPI_ResultField>(myObject);
+ ObjectPtr 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);
+ aBody = subObject(i);
+ if (aBody.get()) {
+ 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);
+ aNode->update();
+ }
+ }
+ else {
+ ModelAPI_ResultField::ModelAPI_FieldStep* aStep = aFieldRes->step(i);
+ if (i < myChildren.size()) {
+ PartSet_StepNode* aStepNode = static_cast<PartSet_StepNode*>(myChildren.at(i));
+ if (aStepNode->entity() != aStep) {
+ aStepNode->setEntity(aStep);
+ }
+ }
+ else {
+ aNode = new PartSet_StepNode(aStep, this);
+ myChildren.append(aNode);
}
- } else {
- aNode = new PartSet_ObjectNode(aBody, this);
- myChildren.append(aNode);
- aResult.append(aNode);
}
}
foreach(ModuleBase_ITreeNode* aNode, myChildren) {
return aResult;
}
-QTreeNodesList PartSet_ObjectNode::objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup)
+QTreeNodesList PartSet_ObjectNode::objectsDeleted(
+ const DocumentPtr& theDoc, const QString& theGroup)
{
QTreeNodesList aResult;
- ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(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)
+ int aNb = numberOfSubs();
+ if (aNb != myChildren.size()) {
+ if (aNb == 0) {
+ deleteChildren();
aResult.append(this);
- int i = 0;
- foreach(ModuleBase_ITreeNode* aNode, myChildren) {
- ((PartSet_ObjectNode*)aNode)->setObject(aCompRes->subResult(i, true));
- aResult.append(aNode->objectsDeleted(theDoc, theGroup));
- i++;
+ }
+ else {
+ // Delete extra objects
+ bool isDeleted = false;
+ ObjectPtr aObj;
+ ModuleBase_ITreeNode* aNode;
+ int aId = 0;
+ while (aId < myChildren.size()) {
+ aNode = myChildren.at(aId);
+ aObj = subObject(aId);
+ if (aNode->object() != aObj) {
+ myChildren.removeAll(aNode);
+ delete aNode;
+ isDeleted = true;
+ }
+ else
+ aId++;
+ }
+ if (isDeleted)
+ aResult.append(this);
+ int i = 0;
+ ObjectPtr aBody;
+ foreach(ModuleBase_ITreeNode* aNode, myChildren) {
+ aBody = subObject(i);
+ ((PartSet_ObjectNode*)aNode)->setObject(aBody);
+ aResult.append(aNode->objectsDeleted(theDoc, theGroup));
+ i++;
+ }
}
}
return aResult;
ModuleBase_ITreeNode* aNode = createNode(aObj);
aNewNodes[aIdx] = aNode;
aResult.append(aNode);
+ aNode->update();
}
}
}
int aIndex;
int aId = 0;
bool aRemoved = false;
+ bool aToSort = false;
while (aId < myChildren.size()) {
ModuleBase_ITreeNode* aNode = myChildren.at(aId);
aIndex = aDoc->index(aNode->object(), true);
- if ((aIndex == -1) || (aId != aIndex)) {
+ aToSort |= ((aIndex != -1) && (aId != aIndex));
+ if (aIndex == -1) {
myChildren.removeAll(aNode);
delete aNode;
aRemoved = true;
- } else
+ }
+ else
aId++;
}
if (aRemoved)
aResult.append(this);
-
+ if (aToSort)
+ sortChildren();
foreach(ModuleBase_ITreeNode* aNode, myChildren) {
aResult.append(aNode->objectsDeleted(theDoc, theGroup));
}
QTreeNodesList PartSet_FeatureFolderNode::objectCreated(const QObjectPtrList& theObjects)
{
QTreeNodesList aResult;
- // Process all folders
- foreach(ModuleBase_ITreeNode* aNode, myChildren) {
- if (aNode->type() == PartSet_FolderNode::typeId()) { // aFolder node
- aResult.append(aNode->objectCreated(theObjects));
- }
- }
// Process the root sub-objects
DocumentPtr aDoc = document();
int aIdx = -1;
if (aDoc == aObj->document()) {
if ((aObj->groupName() == ModelAPI_Feature::group()) ||
(aObj->groupName() == ModelAPI_Folder::group())){
- ModuleBase_ITreeNode* aNode = createNode(aObj);
aIdx = aDoc->index(aObj, true);
if (aIdx != -1) {
+ ModuleBase_ITreeNode* aNode = createNode(aObj);
aIdx += aNb;
bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
if (!aHasObject) {
aNewNodes[aIdx] = aNode;
aResult.append(aNode);
+ aNode->update();
}
}
}
// Update sub-folders
foreach(ModuleBase_ITreeNode* aNode, myChildren) {
- if ((aNode->type() == PartSet_ObjectFolderNode::typeId()) ||
- (aNode->type() == PartSet_PartRootNode::typeId()))
- aResult.append(aNode->objectCreated(theObjects));
+ aResult.append(aNode->objectCreated(theObjects));
}
return aResult;
}
int aIndex;
int aId = 0;
bool aRemoved = false;
+ bool aToSort = false;
while (aId < myChildren.size()) {
ModuleBase_ITreeNode* aNode = myChildren.at(aId);
if (aNode->object().get()) {
aIndex = aDoc->index(aNode->object(), true);
- if ((aIndex == -1) || (aId != (aIndex + aNb))) {
+ aToSort |= ((aIndex != -1) && (aId != (aIndex + aNb)));
+ if (aIndex == -1) {
myChildren.removeAll(aNode);
delete aNode;
aRemoved = true;
}
if (aRemoved)
aResult.append(this);
+ if (aToSort)
+ sortChildren();
}
return aResult;
}
//////////////////////////////////////////////////////////////////////////////////
-//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
+QVariant PartSet_StepNode::data(int theColumn, int theRole) const
+{
+ if ((theColumn == 1) && (theRole == Qt::DisplayRole)) {
+ ModelAPI_ResultField::ModelAPI_FieldStep* aStep =
+ dynamic_cast<ModelAPI_ResultField::ModelAPI_FieldStep*>(myEntity);
+
+ return "Step " + QString::number(aStep->id() + 1) + " " +
+ aStep->field()->textLine(aStep->id()).c_str();
+ }
+ return PartSet_TreeNode::data(theColumn, theRole);
+}