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