Salome HOME
Updated copyright comment
[modules/shaper.git] / src / Model / Model_Data.cpp
index ecafd0c205aa3ba99940aa7c8651440c12127d6f..28237c24e897b1958993d31f2ca4156525d35dcd 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  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>
@@ -77,7 +80,7 @@ static const int kFlagDisplayed = 1;
 static const int kFlagDeleted = 2;
 // TDataStd_Integer - 0 if the name of the object is generated automatically,
 //                    otherwise the name is defined by user
-Standard_GUID kUSER_DEFINED_NAME("9c694d18-a83c-4a56-bc9b-8020628a8244");
+static const Standard_GUID kUSER_DEFINED_NAME("9c694d18-a83c-4a56-bc9b-8020628a8244");
 
 // invalid data
 const static std::shared_ptr<ModelAPI_Data> kInvalid(new Model_Data());
@@ -85,6 +88,9 @@ const static std::shared_ptr<ModelAPI_Data> kInvalid(new Model_Data());
 static const Standard_GUID kGroupAttributeGroupID("df64ea4c-fc42-4bf8-ad7e-08f7a54bf1b8");
 static const Standard_GUID kGroupAttributeID("ebdcb22a-e045-455b-9a7f-cfd38d68e185");
 
+// id of attribute to store the version of the feature
+static const Standard_GUID kVERSION_ID("61cdb78a-1ba7-4942-976f-63bea7f4a2b1");
+
 
 Model_Data::Model_Data() : mySendAttributeUpdated(true), myWasChangedButBlocked(false)
 {
@@ -103,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());
@@ -133,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) {
@@ -158,6 +164,24 @@ bool Model_Data::hasUserDefinedName() const
   return shapeLab().IsAttribute(kUSER_DEFINED_NAME);
 }
 
+std::string Model_Data::version()
+{
+  Handle(TDataStd_Name) aVersionAttr;
+  std::string aVersion;
+  if (shapeLab().FindAttribute(kVERSION_ID, aVersionAttr))
+    aVersion = TCollection_AsciiString(aVersionAttr->Get()).ToCString();
+  return aVersion;
+}
+
+void Model_Data::setVersion(const std::string& theVersion)
+{
+  Handle(TDataStd_Name) aVersionAttr;
+  std::string aVersion;
+  if (!shapeLab().FindAttribute(kVERSION_ID, aVersionAttr))
+    aVersionAttr = TDataStd_Name::Set(shapeLab(), kVERSION_ID, TCollection_ExtendedString());
+  aVersionAttr->Set(theVersion.c_str());
+}
+
 AttributePtr Model_Data::addAttribute(
   const std::string& theID, const std::string theAttrType, const int theIndex)
 {
@@ -195,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()) {
@@ -247,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());
           }
         }
       }
@@ -352,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)
 {
@@ -438,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() == "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);
     }
@@ -626,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()) {
@@ -650,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
@@ -718,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();
@@ -765,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());