Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/visu.git] / src / VISU_I / VISU_Mesh_i.cc
index 8459b5bc0faf9e15b1948e1606b73ac9da015803..a38ea37bf2273d9dae712885ff42dd3215a1d232 100644 (file)
@@ -1,33 +1,39 @@
 //  VISU OBJECT : interactive object for VISU entities implementation
 //
 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
 //
 //
 //  File   : VISU_PrsObject_i.cxx
 //  Author : Alexey PETROV
 //  Module : VISU
 
-#include "VISU_MeshPL.hxx"
-#include "VISU_Result_i.hh"
 #include "VISU_Mesh_i.hh"
+
+#include "VISU_Result_i.hh"
+#include "VISU_ViewManager_i.hh"
+
 #include "VISU_MeshAct.h"
+#include "VISU_MeshPL.hxx"
+#include "VISU_Convertor.hxx"
+
+#include "SALOME_Event.hxx"
 
 using namespace VISU;
 using namespace std;
@@ -48,30 +54,64 @@ 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, SALOMEDS::SObject_ptr theSObject) : 
-       PrsObject_i(theResult->GetStudyDocument()), 
-       Prs3d_i(theResult,theSObject)
+VISU::Mesh_i::
+Mesh_i(Result_i* theResult) :
+  PrsObject_i(theResult->GetStudyDocument()),
+  Prs3d_i(theResult,false),
+  myMeshPL(VISU_MeshPL::New())
+{
+  myPipeLine = myMeshPL;
+}
+
+
+VISU::Mesh_i::
+Mesh_i(Result_i* theResult,
+       SALOMEDS::SObject_ptr theSObject) :
+  PrsObject_i(theResult->GetStudyDocument()),
+  Prs3d_i(theResult,theSObject),
+  myMeshPL(VISU_MeshPL::New())
 {
-  myPipeLine = myMeshPL = VISU_MeshPL::New();;
+  myPipeLine = myMeshPL;
 }
 
 
-void VISU::Mesh_i::RemoveFromStudy(){
-  VISU::RemoveFromStudy(mySObject);
+//---------------------------------------------------------------
+void VISU::Mesh_i::RemoveFromStudy()
+{
+  struct TRemoveFromStudy: public SALOME_Event
+  {
+    VISU::Mesh_i* myRemovable;
+    TRemoveFromStudy(VISU::Mesh_i* theRemovable):
+      myRemovable(theRemovable)
+    {}
+    
+    virtual
+    void
+    Execute()
+    {
+      VISU::RemoveFromStudy(myRemovable->GetSObject());
+      myRemovable->TSuperClass::RemoveFromStudy();
+    }
+  };
+
+  ProcessVoidEvent(new TRemoveFromStudy(this));
 }
 
 
-void VISU::Mesh_i::SameAs(const Mesh_i* theOrigin){
+void VISU::Mesh_i::SameAs (const Prs3d_i* theOrigin)
+{
   return; // "SameAs" command for mesh is not valid in current architecture
 }
 
 
 
-int VISU::Mesh_i::IsPossible(Result_i* theResult, const char* theMeshName, Entity theEntity, const char* theFamilyName){
+int VISU::Mesh_i::IsPossible (Result_i* theResult, const char* theMeshName,
+                             Entity theEntity, const char* theFamilyName)
+{
   try{
     MESSAGE("Mesh_i::IsPossible - theMeshName = '"<<theMeshName<<"'; theEntity = "<<theEntity<<"; theFamilyName = '"<<theFamilyName<<"'");
     float aSize = INCMEMORY*
-      theResult->GetInput()->GetMeshOnEntitySize(theMeshName,(VISU::TEntity)theEntity,theFamilyName);
+      theResult->GetInput()->GetMeshOnEntitySize(theMeshName,(VISU::TEntity)theEntity);
     bool aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
     MESSAGE("Mesh_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
     return aResult;
@@ -83,15 +123,20 @@ int VISU::Mesh_i::IsPossible(Result_i* theResult, const char* theMeshName, Entit
   return 0;
 }
 
-VISU::Storable* VISU::Mesh_i::Create(const char* theMeshName, Entity theEntity, const char* theFamilyName){
+VISU::Storable* VISU::Mesh_i::Create (const char* theMeshName,
+                                     Entity theEntity,
+                                     const char* theFamilyName)
+{
   myMeshName = theMeshName;
-  myEntity = VISU::TEntity(theEntity);
+  //jfa IPAL9284:myEntity = VISU::TEntity(theEntity);
+  myEntity = int(theEntity);//jfa IPAL9284
   mySubMeshName = theFamilyName;
   return Build(false);
 }
 
 
-int VISU::Mesh_i::IsPossible(Result_i* theResult, const char* theMeshName, const char* theGroupName){
+int VISU::Mesh_i::IsPossible (Result_i* theResult, const char* theMeshName, const char* theGroupName)
+{
   try{
     MESSAGE("Mesh_i::IsPossible - theMeshName = '"<<theMeshName<<"'; theGroupName = '"<<theGroupName<<"'");
     float aSize = INCMEMORY*
@@ -108,9 +153,12 @@ int VISU::Mesh_i::IsPossible(Result_i* theResult, const char* theMeshName, const
 }
 
 
-VISU::Storable* VISU::Mesh_i::Create(const char* theMeshName, const char* theGroupName){
+VISU::Storable* VISU::Mesh_i::Create (const char* theMeshName,
+                                     const char* theGroupName)
+{
   myMeshName = theMeshName;
-  myEntity = VISU::TEntity(-1);
+  //jfa IPAL9284:myEntity = VISU::TEntity(-1);
+  myEntity = -1;//jfa IPAL9284
   mySubMeshName = theGroupName;
   return Build(false);
 }
@@ -121,7 +169,8 @@ VISU::Storable* VISU::Mesh_i::Restore(const Storable::TRestoringMap& theMap)
   Prs3d_i::Restore(theMap);
 
   myMeshName = VISU::Storable::FindValue(theMap,"myMeshName").latin1();
-  myEntity = (VISU::TEntity)VISU::Storable::FindValue(theMap,"myEntity").toInt();
+  //jfa IPAL9284:myEntity = (VISU::TEntity)VISU::Storable::FindValue(theMap,"myEntity").toInt();
+  myEntity = VISU::Storable::FindValue(theMap,"myEntity").toInt();//jfa IPAL9284
   mySubMeshName = VISU::Storable::FindValue(theMap,"mySubMeshName").latin1();
 
   myPresentType = VISU::PresentationType(VISU::Storable::FindValue(theMap,"myPresentType").toInt());
@@ -170,61 +219,70 @@ VISU::Mesh_i::~Mesh_i(){
 }
 
 
-VISU::Storable* VISU::Mesh_i::Build(int theRestoring){
+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) 
+  try {
+    if (myResult->GetInput() == NULL)
       throw std::runtime_error("Mesh_i::Build - myResult->GetInput() == NULL !!!");
-    if(!theRestoring){
+    if (!theRestoring) {
       myPresentType = VISU::SHADED;
+      if(myEntity == VISU::NODE_ENTITY)
+       myPresentType = VISU::POINT;
       myName = GenerateName().latin1();
       myCellColor.R = 0.0;  myCellColor.G = myCellColor.B = 1.0;
       myNodeColor.R = myNodeColor.G = 1.0;  myNodeColor.B = 1.0;
       myLinkColor.R = myLinkColor.G = myLinkColor.B = 83/255.;
     }
-    if(int(myEntity) >= 0) 
-      if(mySubMeshName == "") 
-       myType = VISU::TENTITY; 
-      else 
+
+    if(myEntity >= 0)
+      if(mySubMeshName == "")
+       myType = VISU::TENTITY;
+      else
        myType = VISU::TFAMILY;
-    else 
+    else
       myType = VISU::TGROUP;
+
     if(MYDEBUG) MESSAGE("Mesh_i::Build - myType = "<<myType);
     QString aComment;
-    
-    VISU_Convertor::TOutput *anOutput;
+
+    VISU::PIDMapper anIDMapper;
     switch(myType){
-    case VISU::TENTITY : 
-      anOutput = myResult->GetInput()->GetMeshOnEntity(myMeshName,myEntity);
+    case VISU::TENTITY :
+      anIDMapper = myResult->GetInput()->GetMeshOnEntity(myMeshName,(VISU::TEntity)myEntity);//jfa IPAL9284
       aComment.sprintf("myComment=ENTITY;myType=%d;myMeshName=%s;myId=%d",
                       VISU::TENTITY,myMeshName.c_str(),myEntity);
       break;
-    case VISU::TFAMILY : 
-      anOutput = myResult->GetInput()->GetMeshOnEntity(myMeshName,myEntity,mySubMeshName);
+    case VISU::TFAMILY :
+      anIDMapper = myResult->GetInput()->GetFamilyOnEntity(myMeshName,(VISU::TEntity)myEntity,mySubMeshName);
       aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s",
                       VISU::TFAMILY,myMeshName.c_str(),myEntity,mySubMeshName.c_str());
       break;
-    case VISU::TGROUP : 
-      anOutput = myResult->GetInput()->GetMeshOnGroup(myMeshName,mySubMeshName);
+    case VISU::TGROUP :
+      anIDMapper = myResult->GetInput()->GetMeshOnGroup(myMeshName,mySubMeshName);
       aComment.sprintf("myComment=GROUP;myType=%d;myMeshName=%s;myName=%s",
                       VISU::TGROUP,myMeshName.c_str(),mySubMeshName.c_str());
       break;
     }
-    if(anOutput == NULL) throw std::runtime_error("Mesh_i::Build - anOutput == NULL !!!");
-    myMeshPL->SetInput(anOutput);
+    if(!anIDMapper) 
+      throw std::runtime_error("Mesh_i::Build - !anIDMapper !!!");
+
+    myMeshPL->SetIDMapper(anIDMapper);
     myMeshPL->Build();
+
     if(!theRestoring) { //Setting IOR on the label
       myMeshPL->Init();
       string aResultEntry = myResult->GetEntry();
       string anEntry = myResult->GetEntry(aComment.latin1());
-      if(anEntry == "") throw std::runtime_error("Mesh_i::Build - anEntry was not found !!!");
+      if(anEntry == "") 
+       throw std::runtime_error("Mesh_i::Build - anEntry was not found !!!");
       mySObject = myStudy->FindObjectID(anEntry.c_str());
       SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
       SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(mySObject,"AttributeIOR");
       SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
       CORBA::String_var aString = GetID();
-      anIOR->SetValue(aString); 
+      anIOR->SetValue(aString);
     }
   }catch(std::exception& exc){
     INFOS("Follow exception was occured :\n"<<exc.what());
@@ -232,13 +290,13 @@ VISU::Storable* VISU::Mesh_i::Build(int theRestoring){
   }catch(...){
     INFOS("Unknown exception was occured!");
     return NULL;
-  } 
+  }
   aStudyBuilder->CommitCommand();
   return this;
 }
 
 
-VISU_Actor* VISU::Mesh_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) 
+VISU_Actor* VISU::Mesh_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO)
 {
   VISU_MeshAct* anActor = VISU_MeshAct::New();
   try{
@@ -250,7 +308,7 @@ VISU_Actor* VISU::Mesh_i::CreateActor(const Handle(SALOME_InteractiveObject)& th
   }
   return anActor;
 }
+
 
 void VISU::Mesh_i::UpdateActor(VISU_Actor* theActor) {
   if(VISU_MeshAct* anActor = dynamic_cast<VISU_MeshAct*>(theActor)){