Salome HOME
Updated copyright comment
[modules/shaper.git] / src / Model / Model_Data.cpp
index b78b1c70746fba86e8a6c329ef350c9dfa17cc21..28237c24e897b1958993d31f2ca4156525d35dcd 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -32,6 +32,7 @@
 #include <Model_AttributeSelection.h>
 #include <Model_AttributeSelectionList.h>
 #include <Model_AttributeIntArray.h>
+#include <Model_AttributeImage.h>
 #include <Model_AttributeTables.h>
 #include <Model_Events.h>
 #include <Model_Expression.h>
@@ -58,6 +59,8 @@
 #include <Events_Loop.h>
 #include <Events_InfoMessage.h>
 
+#include <Locale_Convert.h>
+
 #include <TDataStd_Name.hxx>
 #include <TDataStd_AsciiString.hxx>
 #include <TDataStd_UAttribute.hxx>
@@ -106,22 +109,22 @@ void Model_Data::setLabel(TDF_Label theLab)
   }
 }
 
-std::string Model_Data::name()
+std::wstring Model_Data::name()
 {
   Handle(TDataStd_Name) aName;
   if (shapeLab().FindAttribute(TDataStd_Name::GetID(), aName)) {
 #ifdef DEBUG_NAMES
-    myObject->myName = TCollection_AsciiString(aName->Get()).ToCString();
+    myObject->myName = Locale::Convert::toWString(aName->Get().ToExtString());
 #endif
-    return std::string(TCollection_AsciiString(aName->Get()).ToCString());
+    return Locale::Convert::toWString(aName->Get().ToExtString());
   }
-  return "";  // not defined
+  return L"";  // not defined
 }
 
-void Model_Data::setName(const std::string& theName)
+void Model_Data::setName(const std::wstring& theName)
 {
   bool isModified = false;
-  std::string anOldName = name();
+  std::wstring anOldName = name();
   Handle(TDataStd_Name) aName;
   if (!shapeLab().FindAttribute(TDataStd_Name::GetID(), aName)) {
     TDataStd_Name::Set(shapeLab(), theName.c_str());
@@ -136,7 +139,7 @@ void Model_Data::setName(const std::string& theName)
       bool isUserDefined = true;
       ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
       if (aResult) {
-        std::string aDefaultName = ModelAPI_Tools::getDefaultName(aResult, false).first;
+        std::wstring aDefaultName = ModelAPI_Tools::getDefaultName(aResult, false).first;
         isUserDefined = aDefaultName != theName;
       }
       if (isUserDefined) {
@@ -216,6 +219,8 @@ AttributePtr Model_Data::addAttribute(
     anAttr = new Model_AttributeDoubleArray(anAttrLab);
   } else if (theAttrType == ModelAPI_AttributeTables::typeId()) {
     anAttr = new Model_AttributeTables(anAttrLab);
+  } else if (theAttrType == ModelAPI_AttributeImage::typeId()) {
+    anAttr = new Model_AttributeImage(anAttrLab);
   }
   // create also GeomData attributes here because only here the OCAF structure is known
   else if (theAttrType == GeomData_Point::typeId()) {
@@ -268,12 +273,12 @@ AttributePtr Model_Data::addFloatingAttribute(
     for(; anIter.More(); anIter.Next()) {
       TCollection_AsciiString aThisName(Handle(TDataStd_Name)::DownCast(anIter.Value())->Get());
       if (theID == aThisName.ToCString()) {
-        TDF_Label aLab = anIter.Value()->Label();
+        TDF_Label aChildLab = anIter.Value()->Label();
         Handle(TDataStd_Name) aGName;
-        if (aLab.FindAttribute(kGroupAttributeGroupID, aGName)) {
+        if (aChildLab.FindAttribute(kGroupAttributeGroupID, aGName)) {
           TCollection_AsciiString aGroupName(aGName->Get());
           if (theGroup == aGroupName.ToCString()) {
-            return addAttribute(theGroup + "__" + theID, theAttrType, aLab.Tag());
+            return addAttribute(theGroup + "__" + theID, theAttrType, aChildLab.Tag());
           }
         }
       }
@@ -373,6 +378,7 @@ GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefAttrList, refattrlist);
 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeIntArray, intArray);
 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeDoubleArray, realArray);
 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeTables, tables);
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeImage, image);
 
 std::shared_ptr<ModelAPI_Attribute> Model_Data::attribute(const std::string& theID)
 {
@@ -459,7 +465,8 @@ void Model_Data::sendAttributeUpdated(ModelAPI_Attribute* theAttr)
     // trim: need to redisplay or set color in the python script
     if (myObject && (theAttr->attributeType() == "Point2D" || theAttr->id() == "Color" ||
       theAttr->id() == "Transparency" || theAttr->id() == "Deflection" ||
-      theAttr->id() == "Iso_lines" || theAttr->id() == "Show_Iso_lines")) {
+      theAttr->id() == "Iso_lines" || theAttr->id() == "Show_Iso_lines" ||
+      theAttr->id() == "Show_Edges_direction" || theAttr->id() == "Bring_To_Front")) {
       static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
       ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent);
     }
@@ -647,8 +654,10 @@ void Model_Data::updateConcealmentFlag()
     if (aRefsIter->get()) {
       FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRefsIter)->owner());
       if (aFeature.get() && !aFeature->isDisabled() && aFeature->isStable()) {
-        if (ModelAPI_Session::get()->validators()->isConcealed(
-              aFeature->getKind(), (*aRefsIter)->id())) {
+        ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
+        bool isCase = aValidators->isCase(aFeature, (*aRefsIter)->id());
+        bool isConcealed = aValidators->isConcealed(aFeature->getKind(), (*aRefsIter)->id());
+        if (isCase && isConcealed) {
           std::shared_ptr<ModelAPI_Result> aRes =
             std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
           if (aRes.get()) {
@@ -671,38 +680,38 @@ void Model_Data::updateConcealmentFlag()
   }
 }
 
-std::set<std::string> set_union(const std::set<std::string>& theLeft,
-                                const std::set<std::string>& theRight)
+std::set<std::wstring> set_union(const std::set<std::wstring>& theLeft,
+                                 const std::set<std::wstring>& theRight)
 {
-  std::set<std::string> aResult;
+  std::set<std::wstring> aResult;
   aResult.insert(theLeft.begin(), theLeft.end());
   aResult.insert(theRight.begin(), theRight.end());
   return aResult;
 }
 
-std::set<std::string> usedParameters(const AttributePointPtr& theAttribute)
+std::set<std::wstring> usedParameters(const AttributePointPtr& theAttribute)
 {
-  std::set<std::string> anUsedParameters;
+  std::set<std::wstring> anUsedParameters;
   for (int aComponent = 0; aComponent < 3; ++aComponent)
     anUsedParameters = set_union(anUsedParameters, theAttribute->usedParameters(aComponent));
   return anUsedParameters;
 }
 
-std::set<std::string> usedParameters(const AttributePoint2DPtr& theAttribute)
+std::set<std::wstring> usedParameters(const AttributePoint2DPtr& theAttribute)
 {
-  std::set<std::string> anUsedParameters;
+  std::set<std::wstring> anUsedParameters;
   for (int aComponent = 0; aComponent < 2; ++aComponent)
     anUsedParameters = set_union(anUsedParameters, theAttribute->usedParameters(aComponent));
   return anUsedParameters;
 }
 
-std::list<ResultParameterPtr> findVariables(const std::set<std::string>& theParameters,
+std::list<ResultParameterPtr> findVariables(const std::set<std::wstring>& theParameters,
                                             const DocumentPtr& theDocument)
 {
   std::list<ResultParameterPtr> aResult;
-  std::set<std::string>::const_iterator aParamIt = theParameters.cbegin();
+  std::set<std::wstring>::const_iterator aParamIt = theParameters.cbegin();
   for (; aParamIt != theParameters.cend(); ++aParamIt) {
-    const std::string& aName = *aParamIt;
+    const std::wstring& aName = *aParamIt;
     double aValue;
     ResultParameterPtr aParam;
     // theSearcher is not needed here: in expressions
@@ -739,9 +748,9 @@ void Model_Data::referencesToObjects(
       if (aRef->isObject()) {
         aReferenced.push_back(aRef->object());
       } else {
-        AttributePtr anAttr = aRef->attr();
-        if (anAttr.get())
-          aReferenced.push_back(anAttr->owner());
+        AttributePtr aReferredAttr = aRef->attr();
+        if (aReferredAttr.get())
+          aReferenced.push_back(aReferredAttr->owner());
       }
     } else if (aType == ModelAPI_AttributeRefList::typeId()) { // list of references
       aReferenced = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttr)->list();
@@ -786,28 +795,28 @@ void Model_Data::referencesToObjects(
     } else if (aType == ModelAPI_AttributeInteger::typeId()) { // integer attribute
       AttributeIntegerPtr anAttribute =
           std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(anAttr);
-      std::set<std::string> anUsedParameters = anAttribute->usedParameters();
+      std::set<std::wstring> anUsedParameters = anAttribute->usedParameters();
       std::list<ResultParameterPtr> aParameters =
         findVariables(anUsedParameters, owner()->document());
       aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
     } else if (aType == ModelAPI_AttributeDouble::typeId()) { // double attribute
       AttributeDoublePtr anAttribute =
           std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(anAttr);
-      std::set<std::string> anUsedParameters = anAttribute->usedParameters();
+      std::set<std::wstring> anUsedParameters = anAttribute->usedParameters();
       std::list<ResultParameterPtr> aParameters =
         findVariables(anUsedParameters, owner()->document());
       aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
     } else if (aType == GeomDataAPI_Point::typeId()) { // point attribute
       AttributePointPtr anAttribute =
         std::dynamic_pointer_cast<GeomDataAPI_Point>(anAttr);
-      std::set<std::string> anUsedParameters = usedParameters(anAttribute);
+      std::set<std::wstring> anUsedParameters = usedParameters(anAttribute);
       std::list<ResultParameterPtr> aParameters =
         findVariables(anUsedParameters, owner()->document());
       aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
     } else if (aType == GeomDataAPI_Point2D::typeId()) { // point attribute
       AttributePoint2DPtr anAttribute =
         std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr);
-      std::set<std::string> anUsedParameters = usedParameters(anAttribute);
+      std::set<std::wstring> anUsedParameters = usedParameters(anAttribute);
       std::list<ResultParameterPtr> aParameters =
         findVariables(anUsedParameters, owner()->document());
       aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());