Salome HOME
IMPs 21044, 21057, 21067
[modules/geom.git] / src / GEOM / GEOM_Function.cxx
index d79dd01a3fa0365eed2ed77cfa6ea89f01f3b21e..46da48dfc0b47a5b23b8dc6819fbf36b85bb7f4e 100644 (file)
@@ -1,28 +1,30 @@
-// Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-// 
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either 
-// version 2.1 of the License.
-// 
-// This library is distributed in the hope that it will be useful 
-// but WITHOUT ANY WARRANTY; without even the implied warranty of 
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-// Lesser General Public License for more details.
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-// 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
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
 //
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  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
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 
 #include <Standard_Stream.hxx>
 
 #include <GEOM_Function.hxx>
 #include <GEOM_Object.hxx>
 #include <GEOM_Solver.hxx>
+#include <GEOM_ISubShape.hxx>
 
 #include "utilities.h"
 
@@ -40,6 +42,7 @@
 #include <TDataStd_UAttribute.hxx>
 #include <TDataStd_ChildNodeIterator.hxx>
 #include <TDataStd_ExtStringArray.hxx>
+#include <TDataStd_ExtStringList.hxx>
 #include <TDocStd_Owner.hxx>
 #include <TDocStd_Document.hxx>
 #include <TFunction_Function.hxx>
 #include <TCollection_AsciiString.hxx>
 #include <TCollection_ExtendedString.hxx>
 
+#include <Standard_Failure.hxx>
 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
 
 #define ARGUMENT_LABEL 1
 #define RESULT_LABEL 2
 #define DESCRIPTION_LABEL 3
 #define HISTORY_LABEL 4
+#define SUBSHAPES_LABEL 5 // 0020756: GetGroups
+#define NAMING_LABEL 6 // 002020750: Naming during STEP import
 
 #define ARGUMENTS _label.FindChild((ARGUMENT_LABEL))
 #define ARGUMENT(thePosition) _label.FindChild((ARGUMENT_LABEL)).FindChild((thePosition))
@@ -160,27 +166,58 @@ TopoDS_Shape GEOM_Function::GetValue()
 
   TopoDS_Shape aShape;
   TDF_Label aLabel = GetOwnerEntry();
-  if(aLabel.IsRoot()) return aShape;
+  if (aLabel.IsRoot()) return aShape;
   Handle(GEOM_Object) anObject = GEOM_Object::GetObject(aLabel);
-  if(anObject.IsNull()) return aShape;
-  if(!anObject->IsMainShape()) {
-    try {
-      GEOM_Solver aSolver(GEOM_Engine::GetEngine());
-      if (!aSolver.ComputeFunction(this)) {
-       MESSAGE("GEOM_Object::GetValue Error : Can't build a sub shape");
-       return aShape;
-      }
+  if (anObject.IsNull()) return aShape;
+
+  if (!anObject->IsMainShape()) {
+    bool isResult = false;
+    TDF_Label aResultLabel = _label.FindChild(RESULT_LABEL);
+    if (!aResultLabel.IsNull()) {
+      Handle(TNaming_NamedShape) aNS;
+      if (aResultLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS))
+        isResult = true;
     }
-    catch (Standard_Failure) {
-      Handle(Standard_Failure) aFail = Standard_Failure::Caught();
-      MESSAGE("GEOM_Function::GetValue Error: " << aFail->GetMessageString());
-      return aShape;
+
+    // compare tics
+    if (isResult) {
+      // tic of this
+      Standard_Integer aTic = anObject->GetTic();
+
+      // tic of main shape
+      GEOM_ISubShape aCI (this);
+      TDF_Label aLabelObjMainSh = aCI.GetMainShape()->GetOwnerEntry();
+      if (aLabelObjMainSh.IsRoot()) return aShape;
+      Handle(GEOM_Object) anObjMainSh = GEOM_Object::GetObject(aLabelObjMainSh);
+      if (anObjMainSh.IsNull()) return aShape;
+      Standard_Integer aTicMainSh = anObjMainSh->GetTic();
+
+      // compare
+      isResult = ((aTic == aTicMainSh) ? true : false);
+    }
+
+    if (!isResult) {
+      try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+        OCC_CATCH_SIGNALS;
+#endif
+        GEOM_Solver aSolver(GEOM_Engine::GetEngine());
+        if (!aSolver.ComputeFunction(this)) {
+          MESSAGE("GEOM_Object::GetValue Error : Can't build a sub shape");
+          return aShape;
+        }
+      }
+      catch (Standard_Failure) {
+        Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+        MESSAGE("GEOM_Function::GetValue Error: " << aFail->GetMessageString());
+        return aShape;
+      }
     }
   }
 
   TDF_Label aResultLabel = _label.FindChild(RESULT_LABEL);
   Handle(TNaming_NamedShape) aNS;
-  if(!aResultLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS)) return aShape;
+  if (!aResultLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS)) return aShape;
 
   aShape = aNS->Get();
 
@@ -190,7 +227,7 @@ TopoDS_Shape GEOM_Function::GetValue()
 
 //=============================================================================
 /*!
- *  GetValue
+ *  SetValue
  */
 //=============================================================================
 void GEOM_Function::SetValue(TopoDS_Shape& theShape)
@@ -201,6 +238,26 @@ void GEOM_Function::SetValue(TopoDS_Shape& theShape)
 
   aBuilder.Generated(theShape);
 
+  // synchronisation between main shape and its sub-shapes
+  TDF_Label aLabel = GetOwnerEntry();
+  if (aLabel.IsRoot()) return;
+  Handle(GEOM_Object) anObject = GEOM_Object::GetObject(aLabel);
+  if (anObject.IsNull()) return;
+  if (anObject->IsMainShape()) {
+    // increase modifications counter of this (main) shape
+    anObject->IncrementTic();
+  }
+  else {
+    // update modifications counter of this (sub-) shape to be the same as on main shape
+    GEOM_ISubShape aCI (this);
+    TDF_Label aLabelObjMainSh = aCI.GetMainShape()->GetOwnerEntry();
+    if (aLabelObjMainSh.IsRoot()) return;
+    Handle(GEOM_Object) anObjMainSh = GEOM_Object::GetObject(aLabelObjMainSh);
+    if (anObjMainSh.IsNull()) return;
+
+    anObject->SetTic(anObjMainSh->GetTic());
+  }
+
   _isDone = true;
 }
 
@@ -416,8 +473,8 @@ TCollection_AsciiString GEOM_Function::GetString(int thePosition)
 void GEOM_Function::SetReference(int thePosition, Handle(GEOM_Function) theReference)
 {
   _isDone = false;
-  if(thePosition <= 0) return;
-  if(theReference.IsNull()) return;
+  if (thePosition <= 0) return;
+  if (theReference.IsNull()) return;
   TDF_Label anArgLabel = ARGUMENT(thePosition);
   TDF_Reference::Set(anArgLabel, theReference->GetEntry());
   TDataStd_UAttribute::Set(anArgLabel, GetDependencyID());
@@ -615,6 +672,85 @@ void GEOM_Function::GetDependency(TDF_LabelSequence& theSeq)
   }
 }
 
+//=============================================================================
+/*!
+ *  AddSubShapeReference
+ */
+//=============================================================================
+void GEOM_Function::AddSubShapeReference(Handle(GEOM_Function) theSubShape)
+{
+  _isDone = false;
+
+  TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
+
+  Handle(TDataStd_ExtStringList) aList;
+  if (!aSubShapesLabel.FindAttribute(TDataStd_ExtStringList::GetID(), aList)) {
+    aList = new TDataStd_ExtStringList;
+    aSubShapesLabel.AddAttribute(aList);
+  }
+
+  TCollection_AsciiString anEntry;
+  TDF_Tool::Entry(theSubShape->GetOwnerEntry(), anEntry);
+  aList->Append(anEntry);
+
+  _isDone = true;
+}
+
+//=============================================================================
+/*!
+ *  RemoveSubShapeReference
+ */
+//=============================================================================
+void GEOM_Function::RemoveSubShapeReference(Handle(GEOM_Function) theSubShape)
+{
+  _isDone = false;
+
+  TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
+
+  Handle(TDataStd_ExtStringList) aList;
+  if (aSubShapesLabel.FindAttribute(TDataStd_ExtStringList::GetID(), aList)) {
+    TCollection_AsciiString anEntry;
+    TDF_Tool::Entry(theSubShape->GetOwnerEntry(), anEntry);
+    aList->Remove(anEntry);
+  }
+
+  _isDone = true;
+}
+
+//=============================================================================
+/*!
+ *  HasSubShapeReferences
+ */
+//=============================================================================
+bool GEOM_Function::HasSubShapeReferences()
+{
+  _isDone = true;
+
+  TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
+  return aSubShapesLabel.IsAttribute(TDataStd_ExtStringList::GetID());
+}
+
+//=============================================================================
+/*!
+ *  GetSubShapeReferences
+ */
+//=============================================================================
+const TDataStd_ListOfExtendedString& GEOM_Function::GetSubShapeReferences()
+{
+  _isDone = false;
+
+  TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
+
+  Handle(TDataStd_ExtStringList) aList;
+  if (!aSubShapesLabel.FindAttribute(TDataStd_ExtStringList::GetID(), aList)) {
+    aList = new TDataStd_ExtStringList;
+    aSubShapesLabel.AddAttribute(aList);
+  }
+
+  _isDone = true;
+  return aList->List();
+}
+
 //=============================================================================
 /*!
  *  GetHistoryEntry
@@ -658,6 +794,16 @@ TDF_Label GEOM_Function::GetArgumentHistoryEntry (const TDF_Label&       theArgu
   return aHistoryCurLabel;
 }
 
+//=============================================================================
+/*!
+ *  GetNamingEntry
+ */
+//=============================================================================
+TDF_Label GEOM_Function::GetNamingEntry (const Standard_Boolean create)
+{
+  return _label.FindChild(NAMING_LABEL, create);
+}
+
 //=======================================================================
 //function :  GEOM_Function_Type_
 //purpose  :
@@ -666,17 +812,16 @@ Standard_EXPORT Handle_Standard_Type& GEOM_Function_Type_()
 {
 
   static Handle_Standard_Type aType1 = STANDARD_TYPE(MMgt_TShared);
-  if ( aType1.IsNull()) aType1 = STANDARD_TYPE(MMgt_TShared);
+  if (aType1.IsNull()) aType1 = STANDARD_TYPE(MMgt_TShared);
   static Handle_Standard_Type aType2 = STANDARD_TYPE(Standard_Transient);
-  if ( aType2.IsNull()) aType2 = STANDARD_TYPE(Standard_Transient);
-
+  if (aType2.IsNull()) aType2 = STANDARD_TYPE(Standard_Transient);
 
   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,NULL};
   static Handle_Standard_Type _aType = new Standard_Type("GEOM_Function",
-                                                        sizeof(GEOM_Function),
-                                                        1,
-                                                        (Standard_Address)_Ancestors,
-                                                        (Standard_Address)NULL);
+                                                         sizeof(GEOM_Function),
+                                                         1,
+                                                         (Standard_Address)_Ancestors,
+                                                         (Standard_Address)NULL);
 
   return _aType;
 }
@@ -696,5 +841,5 @@ const Handle(GEOM_Function) Handle(GEOM_Function)::DownCast(const Handle(Standar
      }
   }
 
-  return _anOtherObject ;
+  return _anOtherObject;
 }