Salome HOME
bos #26449: SHAPER: save imported images
[modules/shaper.git] / src / Model / Model_Data.cpp
index f667942f8ba721310b5fff9d4398d9926e495111..599c65086de002cf852adf1a1cfbbabb7747bca0 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2021  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
@@ -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>
@@ -113,7 +114,7 @@ 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 Locale::Convert::toWString(aName->Get().ToExtString());
   }
@@ -218,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()) {
@@ -270,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());
           }
         }
       }
@@ -375,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)
 {
@@ -649,8 +653,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()) {
@@ -673,38 +679,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
@@ -741,9 +747,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();
@@ -788,28 +794,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());