Salome HOME
New methods: SetParam(), GetParam(), GetArgsCount() for notebook functionality
[modules/geom.git] / src / GEOM / GEOM_Function.cxx
index 0f42f76c301ee8f99f747b89f0af1935a6d97b3c..142a3a4caffe590d961a37f8de0c1db6516e3bb4 100644 (file)
@@ -1,8 +1,30 @@
-using namespace std;
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+//  Copyright (C) 2003-2007  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.
+//
+//  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_Function.hxx>
+#include <GEOM_Object.hxx>
+#include <GEOM_Solver.hxx>
+#include <GEOM_ISubShape.hxx>
 
 #include "utilities.h"
 
@@ -11,6 +33,7 @@ using namespace std;
 #include <TDF_Data.hxx>
 #include <TDF_ChildIterator.hxx>
 #include <TDF_Reference.hxx>
+#include <TDataStd_AsciiString.hxx>
 #include <TDataStd_Integer.hxx>
 #include <TDataStd_IntegerArray.hxx>
 #include <TDataStd_Real.hxx>
@@ -34,6 +57,7 @@ using namespace std;
 #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
@@ -140,27 +164,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;
+    }
+
+    // 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);
     }
-    catch (Standard_Failure) {
-      Handle(Standard_Failure) aFail = Standard_Failure::Caught();
-      MESSAGE("GEOM_Function::GetValue Error: " << aFail->GetMessageString());
-      return aShape;
+
+    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();
 
@@ -170,7 +225,7 @@ TopoDS_Shape GEOM_Function::GetValue()
 
 //=============================================================================
 /*!
- *  GetValue
+ *  SetValue
  */
 //=============================================================================
 void GEOM_Function::SetValue(TopoDS_Shape& theShape)
@@ -181,6 +236,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;
 }
 
@@ -225,6 +300,52 @@ void GEOM_Function::SetDescription(const TCollection_AsciiString& theDescription
     TDataStd_Comment::Set(aChild, TCollection_ExtendedString(theDescription));
 }
 
+//=============================================================================
+/*!
+ *  GetArgsCount
+ */
+//=============================================================================
+int GEOM_Function::GetArgsCount()
+{
+  return _label.FindChild( ARGUMENT_LABEL ).NbChildren();
+}
+
+//=============================================================================
+/*!
+ *  SetParam
+ */
+//=============================================================================
+void GEOM_Function::SetParam( int thePosition, const TCollection_AsciiString& theParamName )
+{
+  _isDone = false;
+  if( thePosition <= 0 )
+    return;
+
+  TDF_Label anArgLabel = ARGUMENT( thePosition );
+  TDataStd_AsciiString::Set( anArgLabel, theParamName );
+  _isDone = true;
+}
+
+//=============================================================================
+/*!
+ *  GetParam
+ */
+//=============================================================================
+TCollection_AsciiString GEOM_Function::GetParam(int thePosition)
+{
+  _isDone = false;
+  if( thePosition <= 0 )
+    return 0.0;
+
+  Handle( TDataStd_AsciiString ) aParam;
+  TDF_Label anArgLabel = ARGUMENT( thePosition );
+  if( !anArgLabel.FindAttribute( TDataStd_AsciiString::GetID(), aParam ) )
+    return "";
+
+  _isDone = true;
+  return aParam->Get();
+}
+
 //=============================================================================
 /*!
  *  SetReal
@@ -653,10 +774,10 @@ Standard_EXPORT Handle_Standard_Type& GEOM_Function_Type_()
 
   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;
 }