Salome HOME
9a71122e5e8036b9ae58e39effee308c4c478a19
[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
34 using namespace VISU;
35 using namespace std;
36
37 #ifdef _DEBUG_
38 static int MYDEBUG = 0;
39 static int MYDEBUGWITHFILES = 0;
40 #else
41 static int MYDEBUG = 0;
42 static int MYDEBUGWITHFILES = 0;
43 #endif
44
45 VISU::Prs3d_i::Prs3d_i(Result_i* theResult, SALOMEDS::SObject_ptr theSObject) : 
46   PrsObject_i(theResult->GetStudyDocument()), 
47   myResult(theResult) 
48 {
49   myResult->Register();
50   mySObject = SALOMEDS::SObject::_duplicate(theSObject);
51   myAddToStudy = true;
52   myPipeLine = NULL;
53   CORBA::String_var aName = myStudy->Name();
54   if(MYDEBUG) MESSAGE("Prs3d_i - this = "<<this<<"; StudyId = "<<myStudy->StudyId()<<"; Name = '"<<aName.in()<<"'");
55 }
56
57 void VISU::Prs3d_i::SameAs(const Prs3d_i* theOrigin)
58 {
59   Prs3d_i* aOrigin = const_cast<Prs3d_i*>(theOrigin);
60   myPipeLine->ShallowCopy(aOrigin->GetPL());
61 }
62
63 VISU::Prs3d_i::~Prs3d_i() {
64   if(MYDEBUG) MESSAGE("~Prs3d_i() - this = "<<this<<"; GetReferenceCount() = "<<myPipeLine->GetReferenceCount());
65   myPipeLine->Delete();
66   myResult->Destroy();
67 }
68
69 void VISU::Prs3d_i::CreateActor(VISU_Actor* theActor, const Handle(SALOME_InteractiveObject)& theIO)
70 {
71   try{
72     Update();
73     if(myAddToStudy){
74       Handle(SALOME_InteractiveObject) anIO = theIO;
75       if(anIO.IsNull()){
76         CORBA::String_var anEntry = mySObject->GetID();
77         anIO = new SALOME_InteractiveObject(strdup(anEntry.in()),"VISU",strdup(GetName()));
78       }
79       theActor->setIO(anIO); 
80     }
81     theActor->SetPipeLine(GetPipeLine());
82     theActor->SetPrs3d(this);
83   }catch(std::bad_alloc& ex){
84     throw std::runtime_error("CreateActor >> No enough memory");
85     throw ex;
86   } catch(std::exception& ex){
87     throw ex;
88   }catch(...) {
89     throw std::runtime_error("CreateActor >> unexpected exception was caught!!!");
90   } 
91 }
92
93 void VISU::Prs3d_i::UpdateActor(VISU_Actor* theActor) {
94   if(MYDEBUG) MESSAGE("Prs3d_i::UpdateActor() - this = "<<this);
95   theActor->GetMapper()->ShallowCopy(myPipeLine->GetMapper());
96   theActor->Modified();
97 }
98
99 VISU::Storable* VISU::Prs3d_i::Restore(const Storable::TRestoringMap& theMap)
100 {
101   myName = VISU::Storable::FindValue(theMap,"myName").latin1();
102   return this;
103 }
104
105 void VISU::Prs3d_i::ToStream(std::ostringstream& theStr){
106   Storable::DataToStream( theStr, "myName",   myName.c_str() );
107 }
108
109 void VISU::Prs3d_i::Update() {
110   if(MYDEBUG) MESSAGE("Prs3d_i::Update() - this = "<<this);
111   try{
112     myPipeLine->Update();
113   }catch(...){
114     throw std::runtime_error("Prs3d_i::Update >> unexpected exception was caught!!!");
115   }
116 }
117
118 VISU_PipeLine* VISU::Prs3d_i::GetPipeLine(){
119   return GetPL();
120 }
121
122 VISU_PipeLine* VISU::Prs3d_i::GetPL(){
123   return myPipeLine;
124 }
125
126
127 SALOMEDS::SObject_var VISU::Prs3d_i::GetSObject(){
128   return mySObject;
129 }
130
131 void VISU::Prs3d_i::GetBounds(float aBounds[6]){
132   myPipeLine->GetMapper()->GetBounds(aBounds);
133 }
134
135 VISU::Result_i* VISU::GetResult(SALOMEDS::SObject_ptr theSObject){
136   VISU::Result_var aResult = FindResult(theSObject);
137   if(!aResult->_is_nil())
138     return dynamic_cast<VISU::Result_i*>(VISU::GetServant(aResult.in()).in());
139   return NULL;
140 }