Salome HOME
Fix for the "0051899: curves are not shown in opened study" issue.
[modules/visu.git] / src / PIPELINE / VISU_CutLinesPL.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File:    VISU_PipeLine.cxx
24 // Author:  Alexey PETROV
25 // Module : VISU
26 //
27 #include "VISU_CutLinesPL.hxx"
28 #include "VISU_FieldTransform.hxx"
29 #include "VISU_PipeLineUtils.hxx"
30 #include "VTKViewer_GeometryFilter.h"
31
32 #include <vtkAppendPolyData.h>
33
34
35 //----------------------------------------------------------------------------
36 vtkStandardNewMacro(VISU_CutLinesPL);
37
38
39 //----------------------------------------------------------------------------
40 VISU_CutLinesPL
41 ::VISU_CutLinesPL()
42 {
43   myCondition = 1;
44   myPosition = 0;
45 }
46
47
48 //----------------------------------------------------------------------------
49 void
50 VISU_CutLinesPL
51 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
52                 bool theIsCopyInput)
53 {
54   Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
55
56   if(VISU_CutLinesPL *aPipeLine = dynamic_cast<VISU_CutLinesPL*>(thePipeLine)){
57     SetOrientation(aPipeLine->GetPlaneOrientation(1),
58                    aPipeLine->GetRotateX(1),aPipeLine->GetRotateY(1),1);
59     SetDisplacement(aPipeLine->GetDisplacement(1),1);
60     if (aPipeLine->IsDefault())
61       SetDefault();
62     else
63       SetPosition(aPipeLine->GetPosition());
64   }
65 }
66
67
68 //----------------------------------------------------------------------------
69 void
70 VISU_CutLinesPL
71 ::Init()
72 {
73   Superclass::Init();
74
75   myBasePlane[0] = XY;
76   myBasePlane[1] = YZ;
77   myDisplacement[0] = myDisplacement[1] = 0.5;
78   myAng[0][0] = myAng[0][1] = myAng[0][2] = 0.0;
79   myAng[1][0] = myAng[1][1] = myAng[1][2] = 0.0;
80
81   myCondition = 1;
82   myPosition = 0;
83 }
84
85
86 //----------------------------------------------------------------------------
87 void
88 VISU_CutLinesPL
89 ::SetPosition(double thePosition)
90 {
91   bool anIsSameValue = VISU::CheckIsSameValue(myPosition, thePosition);
92   anIsSameValue &= (myCondition == 0);
93   if(anIsSameValue)
94     return;
95
96   myPosition = thePosition;
97   myCondition = 0;
98   Modified();
99 }
100
101 vtkAlgorithmOutput* 
102 VISU_CutLinesPL
103 ::InsertCustomPL()
104 {
105   return myAppendPolyData->GetOutputPort();
106 }
107
108 //----------------------------------------------------------------------------
109 double 
110 VISU_CutLinesPL
111 ::GetPosition()
112 {
113   double aPosition = myPosition;
114   if(myCondition){
115       double aBounds[6];
116       GetMergedInput()->GetBounds(aBounds);
117
118       double aDir[3];
119       GetDir(aDir,
120              myAng[0],
121              myBasePlane[0]);
122
123       double aBoundPrj[3];
124       GetBoundProject(aBoundPrj,
125                       aBounds,
126                       aDir);
127
128       aPosition = aBoundPrj[0] + aBoundPrj[2] * myDisplacement[0];
129   }
130   return aPosition;
131 }
132
133
134 //----------------------------------------------------------------------------
135 void
136 VISU_CutLinesPL
137 ::SetDefault()
138 {
139   if(myCondition == 1)
140     return;
141
142   myCondition = 1;
143   Modified();
144 }
145
146
147 //----------------------------------------------------------------------------
148 int
149 VISU_CutLinesPL
150 ::IsDefault()
151 {
152   return myCondition;
153 }
154
155
156 //----------------------------------------------------------------------------
157 void
158 VISU_CutLinesPL
159 ::Update()
160 {
161   vtkDataSet* aMergedInput = GetMergedInput();
162   if(VISU::IsQuadraticData(aMergedInput)) // Bug 0020123, note 0005343
163     throw std::runtime_error("Impossible to build presentation");
164
165   ClearAppendPolyData(myAppendPolyData);
166
167   SetPartPosition(1);
168
169   vtkAppendPolyData *anAppendPolyData = vtkAppendPolyData::New();
170
171   //Build base plane
172   double aBaseBounds[6];
173   GetMergedInput()->GetBounds(aBaseBounds);
174
175   double aDir[2][3];
176   GetDir(aDir[0],
177          myAng[0],
178          myBasePlane[0]);
179
180   CutWithPlanes(anAppendPolyData,
181                 GetMergedInput(),
182                 1,
183                 aDir[0],
184                 aBaseBounds,
185                 myPosition,
186                 myCondition,
187                 myDisplacement[0]);
188   //Build lines
189   vtkDataSet *aDataSet = anAppendPolyData->GetOutput();
190   anAppendPolyData->Update();
191
192   if(aDataSet->GetNumberOfCells() == 0)
193     aDataSet = GetMergedInput();
194
195   double aBounds[6];
196   aDataSet->GetBounds(aBounds);
197
198   GetDir(aDir[1],
199          myAng[1],
200          myBasePlane[1]);
201
202   VISU_CutPlanesPL::CutWithPlanes(myAppendPolyData,
203                                   aDataSet,
204                                   GetNbParts(),
205                                   aDir[1],
206                                   aBounds,
207                                   myPartPosition,
208                                   myPartCondition,
209                                   myDisplacement[1]);
210   //{
211   //  std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myAppendPolyData.vtk";
212   //  VISU::WriteToFile(myAppendPolyData->GetOutput(), aFileName);
213   //}
214   anAppendPolyData->Delete();
215
216   //Calculate values for building of table
217   vtkMath::Cross(aDir[0],aDir[1],myDirLn);
218   for (int i = 0; i<3 ; i++) {
219     myRealDirLn[i] = myDirLn[i];
220     if(myDirLn[i] < 0.0) 
221       myDirLn[i] = -1.0*myDirLn[i];//enk:: correction of bug Bug PAL10401
222   }
223
224   GetBoundProject(myBoundPrjLn, 
225                   aBaseBounds, 
226                   myDirLn);
227
228   VISU::Mul(myDirLn,
229             myBoundPrjLn[0],
230             myBasePnt);
231   
232   CorrectPnt(myBasePnt,
233              aBaseBounds);
234
235   VISU_ScalarMapPL::Update();
236 }
237
238
239 //----------------------------------------------------------------------------
240 void
241 VISU_CutLinesPL
242 ::CutWithPlanes(vtkAppendPolyData* theAppendPolyData, 
243                 vtkDataSet* theDataSet,
244                 int theNbPlanes, 
245                 double theDir[3], 
246                 double theBounds[6],
247                 double thePartPosition, 
248                 int thePartCondition,
249                 double theDisplacement)
250 {
251   std::vector<double> aPartPosition(1,thePartPosition);
252   std::vector<int> aPartCondition(1,thePartCondition);
253   VISU_CutPlanesPL::CutWithPlanes(theAppendPolyData,
254                                   theDataSet,
255                                   theNbPlanes,
256                                   theDir,
257                                   theBounds,
258                                   aPartPosition,
259                                   aPartCondition,
260                                   theDisplacement);
261 }
262
263
264 //----------------------------------------------------------------------------