Salome HOME
Bug PAL8221 - POST-PRO: Pal/Salome crashes if edit presentation in opened study
[modules/visu.git] / src / VISU_I / VISU_Prs3d_i.cc
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //  File   : VISU_Prs3d_i.cc
24 //  Author : Alexey PETROV
25 //  Module : VISU
26
27 #include "VISU_PipeLine.hxx"
28 #include "VISU_Result_i.hh"
29 #include "VISU_Prs3d_i.hh"
30 #include "VISU_Actor.h"
31
32 #include <vtkGeometryFilter.h>
33 #include <vtkDataSetMapper.h>
34
35 using namespace VISU;
36 using namespace std;
37
38 #ifdef _DEBUG_
39 static int MYDEBUG = 0;
40 #else
41 static int MYDEBUG = 0;
42 #endif
43
44 VISU::Prs3d_i::
45 Prs3d_i(Result_i* theResult, 
46         SALOMEDS::SObject_ptr theSObject) : 
47   PrsObject_i(theResult->GetStudyDocument()), 
48   myResult(theResult),
49   mySObject(SALOMEDS::SObject::_duplicate(theSObject)),
50   myAddToStudy(true),
51   myPipeLine(NULL)
52 {
53   myResult->Register();
54 }
55
56 VISU::Prs3d_i::
57 Prs3d_i(Result_i* theResult, 
58         bool theAddToStudy) : 
59   PrsObject_i(theResult->GetStudyDocument()), 
60   myResult(theResult),
61   mySObject(SALOMEDS::SObject::_nil()),
62   myAddToStudy(theAddToStudy),
63   myPipeLine(NULL)
64 {
65   myResult->Register();
66 }
67
68 void VISU::Prs3d_i::SameAs(const Prs3d_i* theOrigin)
69 {
70   Prs3d_i* aOrigin = const_cast<Prs3d_i*>(theOrigin);
71   myPipeLine->ShallowCopy(aOrigin->GetPL());
72 }
73
74 VISU::Prs3d_i::~Prs3d_i() {
75   if(MYDEBUG) MESSAGE("~Prs3d_i() - this = "<<this<<"; GetReferenceCount() = "<<myPipeLine->GetReferenceCount());
76   myPipeLine->Delete();
77   myResult->Destroy();
78 }
79
80 void VISU::Prs3d_i::CreateActor(VISU_Actor* theActor, const Handle(SALOME_InteractiveObject)& theIO)
81 {
82   try{
83     Update();
84     if(myAddToStudy){
85       Handle(SALOME_InteractiveObject) anIO = theIO;
86       if(anIO.IsNull()){
87         anIO = new SALOME_InteractiveObject(mySObject->GetID(),"VISU",GetName());
88       }
89       theActor->setIO(anIO); 
90     }
91     theActor->SetPipeLine(GetPipeLine());
92     theActor->SetPrs3d(this);
93   }catch(std::bad_alloc& ex){
94     throw std::runtime_error("CreateActor >> No enough memory");
95     throw ex;
96   } catch(std::exception& ex){
97     throw ex;
98   }catch(...) {
99     throw std::runtime_error("CreateActor >> unexpected exception was caught!!!");
100   } 
101 }
102
103 void VISU::Prs3d_i::UpdateActor(VISU_Actor* theActor) {
104   if(MYDEBUG) MESSAGE("Prs3d_i::UpdateActor() - this = "<<this);
105   theActor->GetMapper()->ShallowCopy(myPipeLine->GetMapper());
106   theActor->Modified();
107 }
108
109 VISU::Storable* VISU::Prs3d_i::Restore(const Storable::TRestoringMap& theMap)
110 {
111   myName = VISU::Storable::FindValue(theMap,"myName").latin1();
112   return this;
113 }
114
115 void VISU::Prs3d_i::ToStream(std::ostringstream& theStr){
116   Storable::DataToStream( theStr, "myName",   myName.c_str() );
117 }
118
119 void VISU::Prs3d_i::Update() {
120   if(MYDEBUG) MESSAGE("Prs3d_i::Update() - this = "<<this);
121   try{
122     myPipeLine->Update();
123   }catch(...){
124     throw std::runtime_error("Prs3d_i::Update >> unexpected exception was caught!!!");
125   }
126 }
127
128 VISU_PipeLine* VISU::Prs3d_i::GetPipeLine(){
129   return GetPL();
130 }
131
132 VISU_PipeLine* VISU::Prs3d_i::GetPL(){
133   return myPipeLine;
134 }
135
136
137 SALOMEDS::SObject_var VISU::Prs3d_i::GetSObject(){
138   return mySObject;
139 }
140
141 void VISU::Prs3d_i::GetBounds(float aBounds[6]){
142   myPipeLine->GetMapper()->GetBounds(aBounds);
143 }
144
145 VISU::Result_i* VISU::GetResult(SALOMEDS::SObject_ptr theSObject){
146   VISU::Result_var aResult = FindResult(theSObject);
147   if(!aResult->_is_nil())
148     return dynamic_cast<VISU::Result_i*>(VISU::GetServant(aResult.in()).in());
149   return NULL;
150 }