-// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#include "PartSet_TreeNodes.h"
#include <ModelAPI_Folder.h>
#include <ModelAPI_AttributeReference.h>
+#include <Config_PropManager.h>
+
#include <QBrush>
#include <QMap>
+#include <QPalette>
#define ACTIVE_COLOR QColor(Qt::black)
return QBrush(DISABLED_COLOR);
if (!aFlags.testFlag(Qt::ItemIsEditable))
return QBrush(SELECTABLE_COLOR);
- return ACTIVE_COLOR;
+ return activeItemColor();
}
return ModuleBase_ITreeNode::data(theColumn, theRole);
}
+QColor PartSet_TreeNode::activeItemColor() const
+{
+ // instead of ACTIVE_COLOR (black),
+ // use the color text of the current theme (white or black or other)
+ // to make it readable in dark theme (and light theme as well)
+ QColor color = QPalette().text().color() ;
+ return color;
+}
+
//////////////////////////////////////////////////////////////////////////////////
QVariant PartSet_ObjectNode::data(int theColumn, int theRole) const
AttributeDoublePtr aValueAttribute =
aParam->data()->real(ModelAPI_ResultParameter::VALUE());
QString aVal = QString::number(aValueAttribute->value());
- QString aTitle = QString(myObject->data()->name().c_str());
+ QString aTitle = QString::fromStdWString(myObject->data()->name());
return aTitle + " = " + aVal;
}
- return myObject->data()->name().c_str();
+ return QString::fromStdWString(myObject->data()->name());
}
break;
case Qt::DecorationRole:
return PartSet_TreeNode::data(theColumn, theRole);
}
+QColor PartSet_ObjectNode::activeItemColor() const
+{
+ if (myObject.get() && myObject->groupName() == ModelAPI_Feature::group()) {
+ std::vector<int> aColor =
+ Config_PropManager::color("Visualization", "feature_objectbrowser_color");
+ return QColor(aColor[0], aColor[1], aColor[2]);
+ }
+ return PartSet_TreeNode::activeItemColor();
+}
+
+
Qt::ItemFlags PartSet_ObjectNode::flags(int theColumn) const
{
if (myObject->isDisabled()) {
} else {
DocumentPtr aDoc = myObject->document();
SessionPtr aSession = ModelAPI_Session::get();
+
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(myObject);
+ if (aFeature.get() && aFeature->getKind() == "Group")
+ {
+ std::shared_ptr<ModelAPI_CompositeFeature> anOwner =
+ ModelAPI_Tools::compositeOwner (aFeature);
+
+ if (anOwner.get() && anOwner->getKind() == "ImportResult")
+ return aDefaultFlag;
+ }
+
if (aSession->activeDocument() == aDoc)
return aEditingFlag;
}
// If the object is a field result then delete extra sub-objects
if (aFieldRes.get()) {
+ // Call shape in order to update content of Field.
+ // It is necessary to do for cases when field was created by script when module is inactive.
+ aFieldRes->shape();
while (myChildren.size() > aNb) {
ModuleBase_ITreeNode* aNode = myChildren.last();
myChildren.removeAll(aNode);
else {
aNode = new PartSet_ObjectNode(aBody, this);
myChildren.append(aNode);
+ aNode->update();
}
}
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);
+ FieldStepPtr aStep = aFieldRes->step(i);
+ if (aStep.get()) {
+ if (i < myChildren.size()) {
+ PartSet_StepNode* aStepNode = static_cast<PartSet_StepNode*>(myChildren.at(i));
+ if (aStepNode->object() != aStep) {
+ aStepNode->setObject(aStep);
+ }
+ }
+ else {
+ aNode = new PartSet_StepNode(aStep, this);
+ myChildren.append(aNode);
}
- }
- else {
- aNode = new PartSet_StepNode(aStep, this);
- myChildren.append(aNode);
}
}
}
aNode = myChildren.takeLast();
delete aNode;
}
- foreach(ModuleBase_ITreeNode* aNode, myChildren) {
- aNode->update();
+ foreach(ModuleBase_ITreeNode* aChildNode, myChildren) {
+ aChildNode->update();
}
}
else {
ResultFieldPtr aFieldRes = std::dynamic_pointer_cast<ModelAPI_ResultField>(myObject);
ObjectPtr aBody;
int i;
+ // Call shape in order to update content of Field.
+ // It is necessary to do for cases when field was created by script when module is inactive.
+ if (aFieldRes.get())
+ aFieldRes->shape();
for (i = 0; i < aNb; i++) {
aBody = subObject(i);
if (aBody.get()) {
}
}
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);
+ FieldStepPtr aStep = aFieldRes->step(i);
+ if (aStep.get()) {
+ if (i < myChildren.size()) {
+ PartSet_StepNode* aStepNode = static_cast<PartSet_StepNode*>(myChildren.at(i));
+ if (aStepNode->object() != aStep) {
+ aStepNode->setObject(aStep);
+ }
+ }
+ else {
+ aNode = new PartSet_StepNode(aStep, this);
+ myChildren.append(aNode);
}
- }
- else {
- aNode = new PartSet_StepNode(aStep, this);
- myChildren.append(aNode);
}
}
}
- foreach(ModuleBase_ITreeNode* aNode, myChildren) {
- aResult.append(aNode->objectCreated(theObjects));
+ foreach(ModuleBase_ITreeNode* aChildNode, myChildren) {
+ aResult.append(aChildNode->objectCreated(theObjects));
}
}
return aResult;
aResult.append(this);
int i = 0;
ObjectPtr aBody;
- foreach(ModuleBase_ITreeNode* aNode, myChildren) {
+ foreach(ModuleBase_ITreeNode* aChildNode, myChildren) {
aBody = subObject(i);
- ((PartSet_ObjectNode*)aNode)->setObject(aBody);
- aResult.append(aNode->objectsDeleted(theDoc, theGroup));
+ ((PartSet_ObjectNode*)aChildNode)->setObject(aBody);
+ aResult.append(aChildNode->objectsDeleted(theDoc, theGroup));
i++;
}
}
//ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObj);
//if (aCompRes.get())
// return new PartSet_CompsolidNode(theObj, this);
- return new PartSet_ObjectNode(theObj, this);
+ ModuleBase_ITreeNode* aNode = new PartSet_ObjectNode(theObj, this);
+ aNode->update();
+ return aNode;
}
void PartSet_FolderNode::update()
}
}
// Add nodes in correct order
- int i;
- for (i = 0; i < myChildren.size(); i++) {
- if (aNewNodes.contains(i)) {
- myChildren.insert(i, aNewNodes[i]);
+ if (aNewNodes.size() > 0) {
+ int i;
+ for (i = 0; i < myChildren.size(); i++) {
+ if (aNewNodes.contains(i)) {
+ myChildren.insert(i, aNewNodes[i]);
+ aNewNodes.remove(i);
+ }
+ }
+ while (aNewNodes.size()) {
+ i = myChildren.size();
+ myChildren.append(aNewNodes[i]);
aNewNodes.remove(i);
}
}
- while (aNewNodes.size()) {
- i = myChildren.size();
- myChildren.append(aNewNodes[i]);
- aNewNodes.remove(i);
- }
foreach(ModuleBase_ITreeNode* aNode, myChildren) {
aResult.append(aNode->objectCreated(theObjects));
}
}
}
// To add in correct order
- int i;
- for (i = 0; i < myChildren.size(); i++) {
- if (aNewNodes.contains(i)) {
- myChildren.insert(i, aNewNodes[i]);
- aNewNodes.remove(i);
+ if (aNewNodes.size() > 0) {
+ int i;
+ for (i = 0; i < myChildren.size(); i++) {
+ if (aNewNodes.contains(i)) {
+ myChildren.insert(i, aNewNodes[i]);
+ aNewNodes.remove(i);
+ }
+ }
+ while (aNewNodes.size()) {
+ i = myChildren.size();
+ if (aNewNodes.contains(i)) {
+ myChildren.append(aNewNodes[i]);
+ aNewNodes.remove(i);
+ }
}
}
- while (aNewNodes.size()) {
- i = myChildren.size();
- myChildren.append(aNewNodes[i]);
- aNewNodes.remove(i);
- }
-
// Update sub-folders
foreach(ModuleBase_ITreeNode* aNode, myChildren) {
aResult.append(aNode->objectCreated(theObjects));
if (aFeature->getKind() == PartSetPlugin_Part::ID())
return new PartSet_PartRootNode(theObj, this);
- return new PartSet_ObjectNode(theObj, this);
+ PartSet_ObjectNode* aNode = new PartSet_ObjectNode(theObj, this);
+ aNode->update();
+ return aNode;
}
//////////////////////////////////////////////////////////////////////////////////
// Remove extra sub-nodes
int aIndex = -1;
int aId = aRows;
+ QMap<int, ModuleBase_ITreeNode*> aExistingNodes;
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 + aRows))) {
myChildren.removeAll(aNode);
- delete aNode;
+ if (aIndex == -1)
+ delete aNode;
+ else
+ aExistingNodes[aIndex + aRows] = aNode;
continue;
}
}
aId = i + aRows; // Take into account existing folders
if (aId < myChildren.size()) {
if (myChildren.at(aId)->object() != aObj) {
- ModuleBase_ITreeNode* aNode = createNode(aObj);
- myChildren.insert(aId, aNode);
+ if (aExistingNodes.contains(aId)) {
+ myChildren.insert(aId, aExistingNodes[aId]);
+ aExistingNodes.remove(aId);
+ }
+ else {
+ myChildren.insert(aId, createNode(aObj));
+ }
}
} else {
- ModuleBase_ITreeNode* aNode = createNode(aObj);
- myChildren.append(aNode);
+ if (aExistingNodes.contains(myChildren.size()))
+ myChildren.append(aExistingNodes[myChildren.size()]);
+ else
+ myChildren.append(createNode(aObj));
}
}
// Update sub-folders
ResultPartPtr aPartRes = getPartResult(myObject);
if (aPartRes.get()) {
if (aPartRes->partDoc().get() == NULL)
- return QString(myObject->data()->name().c_str()) + " (Not loaded)";
+ return QString::fromStdWString(myObject->data()->name()) + " (Not loaded)";
}
- return QString(myObject->data()->name().c_str());
+ return QString::fromStdWString(myObject->data()->name());
}
case Qt::DecorationRole:
return ModuleBase_IconFactory::get()->getIcon(myObject);
{
if (theObj->groupName() == ModelAPI_Folder::group())
return new PartSet_ObjectFolderNode(theObj, this);
- return new PartSet_ObjectNode(theObj, this);
+ PartSet_ObjectNode* aNode = new PartSet_ObjectNode(theObj, this);
+ aNode->update();
+ return aNode;
}
int PartSet_PartRootNode::numberOfFolders() const
int aNbOfFeatures = aDoc->size(ModelAPI_Feature::group(), true);
while (aId < myChildren.size()) {
ModuleBase_ITreeNode* aNode = myChildren.at(aId);
- if ((aFirst + aId) < aNbOfFeatures) {
+ if ((aId < aNbItems) && ((aFirst + aId) < aNbOfFeatures)) {
if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
myChildren.removeAll(aNode);
delete aNode;
if (aObj != myChildren.at(i)->object()) {
aNode = new PartSet_ObjectNode(aObj, this);
myChildren.insert(i, aNode);
+ aNode->update();
}
}
else {
aNode = new PartSet_ObjectNode(aObj, this);
myChildren.append(aNode);
+ aNode->update();
}
}
}
}
-QTreeNodesList PartSet_ObjectFolderNode::objectCreated(const QObjectPtrList& theObjects)
+QTreeNodesList PartSet_ObjectFolderNode::objectCreated(const QObjectPtrList& /*theObjects*/)
{
QTreeNodesList aResult;
int aFirst = -1, aLast = -1;
aNode = new PartSet_ObjectNode(aObj, this);
myChildren.insert(i, aNode);
aResult.append(aNode);
+ aNode->update();
}
} else {
aNode = new PartSet_ObjectNode(aObj, this);
myChildren.append(aNode);
aResult.append(aNode);
+ aNode->update();
}
}
return aResult;
}
-QTreeNodesList PartSet_ObjectFolderNode::objectsDeleted(const DocumentPtr& theDoc,
- const QString& theGroup)
+QTreeNodesList PartSet_ObjectFolderNode::objectsDeleted(const DocumentPtr& /*theDoc*/,
+ const QString& /*theGroup*/)
{
QTreeNodesList aResult;
int aFirst = -1, aLast = -1;
return aResult;
}
+QVariant PartSet_ObjectFolderNode::data(int theColumn, int theRole) const
+{
+ if (theRole == Qt::ForegroundRole) {
+ if (!myObject->isDisabled()) {
+ std::vector<int> aColor =
+ Config_PropManager::color("Visualization", "feature_objectbrowser_color");
+ return QColor(aColor[0], aColor[1], aColor[2]);
+ }
+ }
+ return PartSet_ObjectNode::data(theColumn, theRole);
+}
//////////////////////////////////////////////////////////////////////////////////
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);
+ FieldStepPtr aStep =
+ std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(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;
}