]> SALOME platform Git repositories - modules/visu.git/blob - src/VISU_I/VISU_CutPlanes_i.cc
Salome HOME
d48d6e0ae621d0fdb593a8e051603cdc4bd3bc4b
[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 static int MYDEBUGWITHFILES = 0;
38 #else
39 static int MYDEBUG = 0;
40 static int MYDEBUGWITHFILES = 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::CutPlanes_i(Result_i* theResult, bool theAddToStudy, SALOMEDS::SObject_ptr theSObject) :
59        PrsObject_i(theResult->GetStudyDocument()), 
60        Prs3d_i(theResult,theSObject),
61        ScalarMap_i(theResult,theAddToStudy,theSObject)
62 {
63   myCutPlanesPL = NULL;
64 }
65
66
67 void VISU::CutPlanes_i::SameAs(const CutPlanes_i* theOrigin){
68   CutPlanes_i* aCutPlanes = const_cast<CutPlanes_i*>(theOrigin);
69   VISU::ScalarMap_i::SameAs(theOrigin);
70 }
71
72
73 VISU::Storable* VISU::CutPlanes_i::Create(const char* theMeshName, VISU::Entity theEntity, 
74                                           const char* theFieldName, int theIteration)
75 {
76   return ScalarMap_i::Create(theMeshName,theEntity,theFieldName,theIteration);
77 }
78
79
80 VISU::Storable* VISU::CutPlanes_i::Restore(const Storable::TRestoringMap& theMap)
81   throw(std::logic_error&)
82 {
83   DoHook();
84   SetNbPlanes(VISU::Storable::FindValue(theMap,"myNbPlanes").toInt());
85   SetDisplacement(VISU::Storable::FindValue(theMap,"myDisplacement").toDouble());
86   SetOrientation(VISU::CutPlanes::Orientation(VISU::Storable::FindValue(theMap,"myBasePlane").toInt()),
87                  Storable::FindValue(theMap,"aRot[0]").toDouble(),
88                  Storable::FindValue(theMap,"aRot[1]").toDouble());
89   QStringList aPosList = QStringList::split("|",VISU::Storable::FindValue(theMap,"myPlanePosition") );
90   QStringList aCondList = QStringList::split("|",VISU::Storable::FindValue(theMap,"myPlaneCondition") );
91   for(int i = 0, iEnd = GetNbPlanes(); i < iEnd; i++)
92     if(aCondList[i].toInt() == 0)
93       SetPlanePosition(i,aPosList[i].toDouble());
94
95   return ScalarMap_i::Restore(theMap);
96 }
97
98
99 void VISU::CutPlanes_i::ToStream(std::ostringstream& theStr){
100   ScalarMap_i::ToStream(theStr);
101
102   int aNbPlanes = GetNbPlanes();
103
104   Storable::DataToStream( theStr, "myNbPlanes", int(GetNbPlanes()));
105   Storable::DataToStream( theStr, "myDisplacement", GetDisplacement());
106   Storable::DataToStream( theStr, "myBasePlane", int(GetOrientationType()));
107   Storable::DataToStream( theStr, "aRot[0]", GetRotateX());
108   Storable::DataToStream( theStr, "aRot[1]", GetRotateY());
109
110   QString aStrPos, aStrCon;
111   for(int i = 0, iEnd = GetNbPlanes(); i < iEnd; i++){
112     aStrPos.append(QString::number(GetPlanePosition(i)) + "|");
113     aStrCon.append(QString::number(IsDefault(i)) + "|");
114   }
115   Storable::DataToStream( theStr, "myPlanePosition",  aStrPos.latin1());
116   Storable::DataToStream( theStr, "myPlaneCondition", aStrCon.latin1());
117 }
118
119
120 VISU::CutPlanes_i::~CutPlanes_i(){
121   if(MYDEBUG) MESSAGE("CutPlanes_i::~CutPlanes_i()");
122 }
123
124
125 void VISU::CutPlanes_i::SetOrientation(VISU::CutPlanes::Orientation theOrient,
126                                        CORBA::Double theXAngle, CORBA::Double theYAngle)
127 {
128   myCutPlanesPL->SetOrientation(VISU_CutPlanesPL::PlaneOrientation(theOrient),
129                                 theXAngle,theYAngle);
130 }
131
132 VISU::CutPlanes::Orientation VISU::CutPlanes_i::GetOrientationType() { 
133   return VISU::CutPlanes::Orientation(myCutPlanesPL->GetPlaneOrientation());
134 }
135 CORBA::Double VISU::CutPlanes_i::GetRotateX(){
136   return myCutPlanesPL->GetRotateX();
137 }
138 CORBA::Double VISU::CutPlanes_i::GetRotateY(){
139   return myCutPlanesPL->GetRotateY();
140 }
141
142
143 void VISU::CutPlanes_i::SetDisplacement(CORBA::Double theDisp) { 
144   myCutPlanesPL->SetDisplacement(theDisp);
145 }
146 CORBA::Double VISU::CutPlanes_i::GetDisplacement() { 
147   return myCutPlanesPL->GetDisplacement();
148 }
149
150
151 void VISU::CutPlanes_i::SetPlanePosition(CORBA::Long thePlaneNumber, CORBA::Double thePlanePosition){
152   myCutPlanesPL->SetPartPosition(thePlaneNumber,thePlanePosition);
153 }
154 CORBA::Double VISU::CutPlanes_i::GetPlanePosition(CORBA::Long thePlaneNumber){ 
155   return myCutPlanesPL->GetPartPosition(thePlaneNumber);
156 }
157
158
159 void VISU::CutPlanes_i::SetDefault(CORBA::Long thePlaneNumber){
160   myCutPlanesPL->SetPartDefault(thePlaneNumber);
161 }
162 CORBA::Boolean VISU::CutPlanes_i::IsDefault(CORBA::Long thePlaneNumber){ 
163   return myCutPlanesPL->IsPartDefault(thePlaneNumber);
164 }
165
166
167 void VISU::CutPlanes_i::SetNbPlanes(CORBA::Long theNb) { 
168   myCutPlanesPL->SetNbParts(theNb);
169 }
170 CORBA::Long VISU::CutPlanes_i::GetNbPlanes() { 
171   return myCutPlanesPL->GetNbParts();
172 }
173
174
175 void VISU::CutPlanes_i::DoHook(){
176   if(!myPipeLine) myPipeLine = VISU_CutPlanesPL::New();
177   myCutPlanesPL = dynamic_cast<VISU_CutPlanesPL*>(myPipeLine);
178
179   ScalarMap_i::DoHook();
180 }