Salome HOME
DCQ : Merge with Ecole Ete a6.
[modules/visu.git] / src / VISU_I / VISU_Mesh_i.cc
index 0a5ad229b5f4f95a94cd5de6aa9b967844d6b8a7..c556d1739c6429d4c7016662f9283174a636950b 100644 (file)
@@ -50,33 +50,33 @@ const string VISU::Mesh_i::myComment = "MESH";
 
 const char* VISU::Mesh_i::GetComment() const { return myComment.c_str();}
 
-VISU::Mesh_i::Mesh_i(Result_i* theResult) : 
+VISU::Mesh_i::Mesh_i(Result_i* theResult, SALOMEDS::SObject_ptr theSObject) : 
        PrsObject_i(theResult->GetStudyDocument()), 
-       Prs3d_i(theResult)
+       Prs3d_i(theResult,theSObject)
 {
   myPipeLine = myMeshPL = VISU_MeshPL::New();;
 }
 
+
+void VISU::Mesh_i::RemoveFromStudy(){
+  VISU::RemoveFromStudy(mySObject);
+}
+
+
 void VISU::Mesh_i::SameAs(const Mesh_i* theOrigin){
   return; // "SameAs" command for mesh is not valid in current architecture
 }
 
-void VISU::Mesh_i::Destroy(){
-  SALOMEDS::SObject_var aSObj = myStudy->FindObjectID(GetEntry());
-  if(!aSObj->_is_nil()){
-    SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
-    aStudyBuilder->RemoveAttribute(aSObj,"AttributeIOR");
-  }
-  Prs3d_i::Destroy();
-}
+
 
 int VISU::Mesh_i::IsPossible(Result_i* theResult, const char* theMeshName, Entity theEntity, const char* theFamilyName){
   try{
-    vtkIdType aSize = INCMEMORY*
+    MESSAGE("Mesh_i::IsPossible - theMeshName = '"<<theMeshName<<"'; theEntity = "<<theEntity<<"; theFamilyName = '"<<theFamilyName<<"'");
+    float aSize = INCMEMORY*
       theResult->GetInput()->GetMeshOnEntitySize(theMeshName,(VISU::TEntity)theEntity,theFamilyName);
-    if(MYDEBUG) MESSAGE("Mesh_i::IsPossible - CheckAvailableMemory = "<<aSize);
-    if(VISU_PipeLine::CheckAvailableMemory(aSize)) return true;
-    return false;
+    bool aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
+    MESSAGE("Mesh_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
+    return aResult;
   }catch(std::runtime_error& exc){
     INFOS("Follow exception was accured :\n"<<exc.what());
   }catch(...){
@@ -95,11 +95,12 @@ VISU::Storable* VISU::Mesh_i::Create(const char* theMeshName, Entity theEntity,
 
 int VISU::Mesh_i::IsPossible(Result_i* theResult, const char* theMeshName, const char* theGroupName){
   try{
-    vtkIdType aSize = INCMEMORY*
+    MESSAGE("Mesh_i::IsPossible - theMeshName = '"<<theMeshName<<"'; theGroupName = '"<<theGroupName<<"'");
+    float aSize = INCMEMORY*
       theResult->GetInput()->GetMeshOnGroupSize(theMeshName,theGroupName);
-    if(MYDEBUG) MESSAGE("Mesh_i::IsPossible - CheckAvailableMemory = "<<aSize);
-    if(VISU_PipeLine::CheckAvailableMemory(aSize)) return true;
-    return false;
+    bool aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
+    INFOS("Mesh_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
+    return aResult;
   }catch(std::runtime_error& exc){
     INFOS("Follow exception was accured :\n"<<exc.what());
   }catch(...){
@@ -107,6 +108,8 @@ int VISU::Mesh_i::IsPossible(Result_i* theResult, const char* theMeshName, const
   }
   return 0;
 }
+
+
 VISU::Storable* VISU::Mesh_i::Create(const char* theMeshName, const char* theGroupName){
   myMeshName = theMeshName;
   myEntity = VISU::TEntity(-1);
@@ -114,8 +117,8 @@ VISU::Storable* VISU::Mesh_i::Create(const char* theMeshName, const char* theGro
   return Build(false);
 }
 
+
 VISU::Storable* VISU::Mesh_i::Restore(const Storable::TRestoringMap& theMap)
-     throw(std::logic_error&)
 {
   Prs3d_i::Restore(theMap);
 
@@ -140,6 +143,7 @@ VISU::Storable* VISU::Mesh_i::Restore(const Storable::TRestoringMap& theMap)
   return Build(true);
 }
 
+
 void VISU::Mesh_i::ToStream(std::ostringstream& theStr){
   Prs3d_i::ToStream(theStr);
 
@@ -162,18 +166,6 @@ void VISU::Mesh_i::ToStream(std::ostringstream& theStr){
   Storable::DataToStream( theStr, "myLinkColor.B", myLinkColor.B );
 }
 
-VISU::Storable* VISU::Mesh_i::Restore(SALOMEDS::SObject_ptr theSObject, 
-                                     const string& thePrefix, const Storable::TRestoringMap& theMap)
-  throw(std::logic_error&)
-{
-  VISU::Result_i* pResult = GetResult(theSObject);
-  if(pResult != NULL){
-    VISU::Mesh_i* pResent = new VISU::Mesh_i(pResult);
-    return pResent->Restore(theMap);
-  }
-  return NULL;
-}
-
 
 VISU::Mesh_i::~Mesh_i(){
   if(MYDEBUG) MESSAGE("Mesh_i::~Mesh_i()");
@@ -181,6 +173,8 @@ VISU::Mesh_i::~Mesh_i(){
 
 
 VISU::Storable* VISU::Mesh_i::Build(int theRestoring){
+  SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
+  aStudyBuilder->NewCommand();  // There is a transaction
   try{
     if(myResult->GetInput() == NULL) 
       throw std::runtime_error("Mesh_i::Build - myResult->GetInput() == NULL !!!");
@@ -227,43 +221,45 @@ VISU::Storable* VISU::Mesh_i::Build(int theRestoring){
       string aResultEntry = myResult->GetEntry();
       string anEntry = FindEntryWithComment(myStudy,aResultEntry.c_str(),aComment.latin1());
       if(anEntry == "") throw std::runtime_error("Mesh_i::Build - anEntry was not found !!!");
-      SALOMEDS::SObject_var aSObj = myStudy->FindObjectID(anEntry.c_str());
+      mySObject = myStudy->FindObjectID(anEntry.c_str());
       SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
-      SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSObj,"AttributeIOR");
+      SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(mySObject,"AttributeIOR");
       SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
       CORBA::String_var aString = GetID();
       anIOR->SetValue(aString); 
     }
-    return this;
   }catch(std::runtime_error& exc){
     INFOS("Follow exception was accured :\n"<<exc.what());
+    return NULL;
   }catch(...){
     INFOS("Unknown exception was accured!");
+    return NULL;
   } 
-  return NULL;
+  aStudyBuilder->CommitCommand();
+  return this;
 }
 
 
 VISU_Actor* VISU::Mesh_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) 
-  throw (std::runtime_error&)
 {
   VISU_MeshAct* anActor = VISU_MeshAct::New();
   try{
     VISU::Prs3d_i::CreateActor(anActor,theIO);
     UpdateActor(anActor);
-  }catch(std::runtime_error& exc){
+  }catch (...) {
     anActor->Delete();
-    throw exc;
+    throw ;
   }
   return anActor;
 }
  
-void VISU::Mesh_i::UpdateActor(VISU_Actor* theActor){
+
+void VISU::Mesh_i::UpdateActor(VISU_Actor* theActor) {
   if(VISU_MeshAct* anActor = dynamic_cast<VISU_MeshAct*>(theActor)){
     if(MYDEBUG) MESSAGE("Mesh_i::UpdateActor");
     VISU::Prs3d_i::UpdateActor(anActor);
     anActor->SetRepresentation(myPresentType);
-    anActor->GetProperty()->SetColor(myCellColor.R, myCellColor.G, myCellColor.B);
+    anActor->GetSurfaceProperty()->SetColor(myCellColor.R, myCellColor.G, myCellColor.B);
     anActor->GetEdgeProperty()->SetColor(myLinkColor.R, myLinkColor.G, myLinkColor.B);
     anActor->GetNodeProperty()->SetColor(myNodeColor.R, myNodeColor.G, myNodeColor.B);
   }