Salome HOME
Merge from OCC_development_generic_2006
[modules/visu.git] / src / VISU_I / VISU_CutPlanes_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_PrsObject_i.cxx
24 //  Author : Alexey PETROV
25 //  Module : VISU
26
27 #include "VISU_CutPlanesPL.hxx"
28 #include "VISU_Result_i.hh"
29 #include "VISU_CutPlanes_i.hh"
30 #include "VISU_Actor.h"
31
32 using namespace VISU;
33 using namespace std;
34
35 #ifdef _DEBUG_
36 static int MYDEBUG = 0;
37 #else
38 static int MYDEBUG = 0;
39 #endif
40
41 int VISU::CutPlanes_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, 
42                                   const char* theFieldName, int theIteration, int isMemoryCheck)
43 {
44   return VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration,isMemoryCheck);
45 }
46
47
48 int VISU::CutPlanes_i::myNbPresent = 0;
49 QString VISU::CutPlanes_i::GenerateName() { return VISU::GenerateName("CutPlanes",myNbPresent++);}
50
51
52 const string VISU::CutPlanes_i::myComment = "CUTPLANES";
53 const char* VISU::CutPlanes_i::GetComment() const { return myComment.c_str();}
54
55
56 VISU::CutPlanes_i::
57 CutPlanes_i(Result_i* theResult, 
58             bool theAddToStudy) :
59   PrsObject_i(theResult->GetStudyDocument()), 
60   Prs3d_i(theResult,theAddToStudy),
61   ColoredPrs3d_i(theResult,theAddToStudy),
62   ScalarMap_i(theResult,theAddToStudy),
63   myCutPlanesPL(NULL)
64 {}
65
66
67 VISU::CutPlanes_i::
68 CutPlanes_i(Result_i* theResult, 
69             SALOMEDS::SObject_ptr theSObject) :
70   PrsObject_i(theResult->GetStudyDocument()), 
71   Prs3d_i(theResult,theSObject),
72   ColoredPrs3d_i(theResult,theSObject),
73   ScalarMap_i(theResult,theSObject),
74   myCutPlanesPL(NULL)
75 {
76 }
77
78
79 VISU::Storable* VISU::CutPlanes_i::Create(const char* theMeshName, VISU::Entity theEntity, 
80                                           const char* theFieldName, int theIteration)
81 {
82   return ScalarMap_i::Create(theMeshName,theEntity,theFieldName,theIteration);
83 }
84
85
86 VISU::Storable* VISU::CutPlanes_i::Restore(const Storable::TRestoringMap& theMap)
87 {
88   TSuperClass::Restore(theMap);
89
90   SetNbPlanes(VISU::Storable::FindValue(theMap,"myNbPlanes").toInt());
91   SetDisplacement(VISU::Storable::FindValue(theMap,"myDisplacement").toDouble());
92   SetOrientation(VISU::CutPlanes::Orientation(VISU::Storable::FindValue(theMap,"myBasePlane").toInt()),
93                  Storable::FindValue(theMap,"aRot[0]").toDouble(),
94                  Storable::FindValue(theMap,"aRot[1]").toDouble());
95   QStringList aPosList = QStringList::split("|",VISU::Storable::FindValue(theMap,"myPlanePosition") );
96   QStringList aCondList = QStringList::split("|",VISU::Storable::FindValue(theMap,"myPlaneCondition") );
97   for(int i = 0, iEnd = GetNbPlanes(); i < iEnd; i++)
98     if(aCondList[i].toInt() == 0)
99       SetPlanePosition(i,aPosList[i].toDouble());
100
101   return this;
102 }
103
104
105 void VISU::CutPlanes_i::ToStream(std::ostringstream& theStr){
106   ScalarMap_i::ToStream(theStr);
107
108   Storable::DataToStream( theStr, "myNbPlanes", int(GetNbPlanes()));
109   Storable::DataToStream( theStr, "myDisplacement", GetDisplacement());
110   Storable::DataToStream( theStr, "myBasePlane", int(GetOrientationType()));
111   Storable::DataToStream( theStr, "aRot[0]", GetRotateX());
112   Storable::DataToStream( theStr, "aRot[1]", GetRotateY());
113
114   QString aStrPos, aStrCon;
115   for(int i = 0, iEnd = GetNbPlanes(); i < iEnd; i++){
116     aStrPos.append(QString::number(GetPlanePosition(i)) + "|");
117     aStrCon.append(QString::number(IsDefault(i)) + "|");
118   }
119   Storable::DataToStream( theStr, "myPlanePosition",  aStrPos.latin1());
120   Storable::DataToStream( theStr, "myPlaneCondition", aStrCon.latin1());
121 }
122
123
124 VISU::CutPlanes_i::~CutPlanes_i(){
125   if(MYDEBUG) MESSAGE("CutPlanes_i::~CutPlanes_i()");
126 }
127
128
129 void VISU::CutPlanes_i::SetOrientation(VISU::CutPlanes::Orientation theOrient,
130                                        CORBA::Double theXAngle, CORBA::Double theYAngle)
131 {
132   myCutPlanesPL->SetOrientation(VISU_CutPlanesPL::PlaneOrientation(theOrient),
133                                 theXAngle,theYAngle);
134 }
135
136 VISU::CutPlanes::Orientation VISU::CutPlanes_i::GetOrientationType() { 
137   return VISU::CutPlanes::Orientation(myCutPlanesPL->GetPlaneOrientation());
138 }
139 CORBA::Double VISU::CutPlanes_i::GetRotateX(){
140   return myCutPlanesPL->GetRotateX();
141 }
142 CORBA::Double VISU::CutPlanes_i::GetRotateY(){
143   return myCutPlanesPL->GetRotateY();
144 }
145
146
147 void VISU::CutPlanes_i::SetDisplacement(CORBA::Double theDisp) { 
148   myCutPlanesPL->SetDisplacement(theDisp);
149 }
150 CORBA::Double VISU::CutPlanes_i::GetDisplacement() { 
151   return myCutPlanesPL->GetDisplacement();
152 }
153
154
155 void VISU::CutPlanes_i::SetPlanePosition(CORBA::Long thePlaneNumber, CORBA::Double thePlanePosition){
156   myCutPlanesPL->SetPartPosition(thePlaneNumber,thePlanePosition);
157 }
158 CORBA::Double VISU::CutPlanes_i::GetPlanePosition(CORBA::Long thePlaneNumber){ 
159   return myCutPlanesPL->GetPartPosition(thePlaneNumber);
160 }
161
162
163 void VISU::CutPlanes_i::SetDefault(CORBA::Long thePlaneNumber){
164   myCutPlanesPL->SetPartDefault(thePlaneNumber);
165 }
166 CORBA::Boolean VISU::CutPlanes_i::IsDefault(CORBA::Long thePlaneNumber){ 
167   return myCutPlanesPL->IsPartDefault(thePlaneNumber);
168 }
169
170
171 void VISU::CutPlanes_i::SetNbPlanes(CORBA::Long theNb) { 
172   myCutPlanesPL->SetNbParts(theNb);
173 }
174 CORBA::Long VISU::CutPlanes_i::GetNbPlanes() { 
175   return myCutPlanesPL->GetNbParts();
176 }
177
178
179 void VISU::CutPlanes_i::DoHook(){
180   if(!myPipeLine) myPipeLine = VISU_CutPlanesPL::New();
181   myCutPlanesPL = dynamic_cast<VISU_CutPlanesPL*>(myPipeLine);
182
183   ScalarMap_i::DoHook();
184 }
185
186 VISU_Actor* 
187 VISU::CutPlanes_i
188 ::CreateActor(const Handle(SALOME_InteractiveObject)& theIO)
189 {
190   if(VISU_Actor* anActor = ScalarMap_i::CreateActor(theIO)){
191     anActor->SetVTKMapping(true);
192     return anActor;
193   }
194   return NULL;
195 }
196