Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/visu.git] / src / VISU_I / VISU_CutLines_i.cc
1 //  Copyright (C) 2007-2008  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 //  VISU OBJECT : interactive object for VISU entities implementation
23 //  File   : VISU_PrsObject_i.cxx
24 //  Author : Alexey PETROV
25 //  Module : VISU
26 //
27 #include "VISU_CutLines_i.hh"
28 #include "VISU_Prs3dUtils.hh"
29 #include "VISU_Result_i.hh"
30
31 #include "VISU_Actor.h"
32 #include "VISU_CutLinesPL.hxx"
33 #include "VISU_Convertor.hxx"
34 #include "VISU_PipeLineUtils.hxx"
35
36 #include "SUIT_ResourceMgr.h"
37 #include "SALOME_Event.h"
38
39 #include <vtkAppendPolyData.h>
40
41 static vtkFloatingPointType EPS_machine = 1.0E-7;
42
43 #ifdef _DEBUG_
44 static int MYDEBUG = 0;
45 #else
46 static int MYDEBUG = 0;
47 #endif
48
49 using namespace std;
50
51 //---------------------------------------------------------------
52 size_t
53 VISU::CutLines_i
54 ::IsPossible(Result_i* theResult, 
55              const std::string& theMeshName, 
56              VISU::Entity theEntity, 
57              const std::string& theFieldName, 
58              CORBA::Long theTimeStampNumber, 
59              bool theIsMemoryCheck)
60 {
61   return TSuperClass::IsPossible(theResult,
62                                  theMeshName,
63                                  theEntity,
64                                  theFieldName,
65                                  theTimeStampNumber,
66                                  theIsMemoryCheck);
67 }
68
69 //---------------------------------------------------------------
70 int VISU::CutLines_i::myNbPresent = 0;
71
72 //---------------------------------------------------------------
73 QString 
74 VISU::CutLines_i::GenerateName() 
75
76   return VISU::GenerateName("CutLines",myNbPresent++);
77 }
78
79 //---------------------------------------------------------------
80 const string VISU::CutLines_i::myComment = "CUTLINES";
81
82 //---------------------------------------------------------------
83 const char* 
84 VISU::CutLines_i
85 ::GetComment() const 
86
87   return myComment.c_str();
88 }
89
90 //----------------------------------------------------------------------------
91 const char*
92 VISU::CutLines_i
93 ::GetIconName()
94 {
95   if (!IsGroupsUsed())
96     return "ICON_TREE_CUT_LINES";
97   else
98     return "ICON_TREE_CUT_LINES_GROUPS";
99 }
100
101 //---------------------------------------------------------------
102 VISU::CutLines_i::
103 CutLines_i(EPublishInStudyMode thePublishInStudyMode) :
104   ColoredPrs3d_i(thePublishInStudyMode),
105   ScalarMap_i(thePublishInStudyMode),
106   myUseAbsLength( false ),
107   myCutLinesPL(NULL)
108 {}
109
110
111 //---------------------------------------------------------------
112 void
113 VISU::CutLines_i
114 ::SameAs(const Prs3d_i* theOrigin)
115 {
116   TSuperClass::SameAs(theOrigin);
117
118   if(const CutLines_i* aPrs3d = dynamic_cast<const CutLines_i*>(theOrigin)){
119     CutLines_i* anOrigin = const_cast<CutLines_i*>(aPrs3d);
120     myUseAbsLength = anOrigin->IsUseAbsoluteLength();
121     CopyCurvesInverted(anOrigin->GetCurvesInverted());
122   }
123 }
124
125
126 //---------------------------------------------------------------
127 /*! Copy map to /a myMapCurvesInverted.
128  * \param theCurves - map
129  */
130 void 
131 VISU::CutLines_i
132 ::CopyCurvesInverted(const TCurvesInv& theCurves)
133 {
134   myMapCurvesInverted = theCurves;
135 }
136
137
138 //---------------------------------------------------------------
139 VISU::Storable* 
140 VISU::CutLines_i
141 ::Create(const std::string& theMeshName, 
142          VISU::Entity theEntity,
143          const std::string& theFieldName, 
144          CORBA::Long theTimeStampNumber)
145 {
146   SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
147   SetUseAbsoluteLength( aResourceMgr->booleanValue( "VISU", "use_absolute_length", false ) );
148   SetAllCurvesInverted( aResourceMgr->booleanValue( "VISU", "invert_all_curves", false ) );
149   return TSuperClass::Create(theMeshName,theEntity,theFieldName,theTimeStampNumber);
150 }
151
152
153 //---------------------------------------------------------------
154 VISU::Storable* 
155 VISU::CutLines_i
156 ::Restore(SALOMEDS::SObject_ptr theSObject,
157           const Storable::TRestoringMap& theMap)
158 {
159   if(!TSuperClass::Restore(theSObject, theMap))
160     return NULL;
161
162   SetNbLines(VISU::Storable::FindValue(theMap,"myNbLines").toInt());
163   SetDisplacement(VISU::Storable::FindValue(theMap,"myDisplacement[0]").toDouble());
164   SetDisplacement2(VISU::Storable::FindValue(theMap,"myDisplacement[1]").toDouble());
165   SetOrientation(CutPlanes::Orientation(VISU::Storable::FindValue(theMap,"myBasePlane[0]").toInt()),
166                  Storable::FindValue(theMap,"aRot[0][0]").toDouble(),
167                  Storable::FindValue(theMap,"aRot[0][1]").toDouble());
168   SetOrientation2(CutPlanes::Orientation(VISU::Storable::FindValue(theMap,"myBasePlane[1]").toInt()),
169                   Storable::FindValue(theMap,"aRot[1][0]").toDouble(),
170                   Storable::FindValue(theMap,"aRot[1][1]").toDouble());
171   SetUseAbsoluteLength(VISU::Storable::FindValue(theMap,"myUseAbsLength").toInt());
172
173   if (VISU::Storable::FindValue(theMap,"myBasePlaneCondition").toInt())
174     SetDefault();
175   else
176     SetBasePlanePosition(VISU::Storable::FindValue(theMap,"myBasePlanePosition").toDouble());
177   
178   QStringList aPosList = VISU::Storable::FindValue(theMap,"myLinePosition").split("|", QString::SkipEmptyParts );
179   QStringList aCondList = VISU::Storable::FindValue(theMap,"myLineCondition").split("|",QString::SkipEmptyParts );
180   for(int i = 0, iEnd = GetNbLines(); i < iEnd; i++)
181     if(aCondList[i].toInt() == 0)
182       SetLinePosition(i,aPosList[i].toDouble());
183
184   // Restoring the map - \a myMapCurvesInverted
185   QStringList aMapCurvesInverted = VISU::Storable::FindValue(theMap,"myMapCurvesInverted").split("|",QString::SkipEmptyParts );
186   if (aMapCurvesInverted.count() == GetNbLines()){
187     for(int i = 0, iEnd = GetNbLines(); i < iEnd ; i++){
188       if(aMapCurvesInverted[i].toInt())
189         SetCurveInverted(i,true);
190       else
191         SetCurveInverted(i,false);
192     }
193   } else {
194     for(int i = 0, iEnd = GetNbLines(); i < iEnd ; i++)
195       SetCurveInverted(i,false);
196   }
197       
198   return this;
199 }
200
201
202 //---------------------------------------------------------------
203 void
204 VISU::CutLines_i
205 ::ToStream(std::ostringstream& theStr)
206 {
207   TSuperClass::ToStream(theStr);
208
209   int aNbLines = GetNbLines();
210   
211   Storable::DataToStream( theStr, "myNbLines",         aNbLines );
212   Storable::DataToStream( theStr, "myDisplacement[0]", GetDisplacement() );
213   Storable::DataToStream( theStr, "myDisplacement[1]", GetDisplacement2() );
214   Storable::DataToStream( theStr, "myBasePlane[0]",    int(GetOrientationType()) );
215   Storable::DataToStream( theStr, "myBasePlane[1]",    int(GetOrientationType2()) );
216   Storable::DataToStream( theStr, "aRot[0][0]",        GetRotateX() );
217   Storable::DataToStream( theStr, "aRot[0][1]",        GetRotateY() );
218   Storable::DataToStream( theStr, "aRot[1][0]",        GetRotateX2() );
219   Storable::DataToStream( theStr, "aRot[1][1]",        GetRotateY2() );
220   Storable::DataToStream( theStr, "myBasePlanePosition", GetBasePlanePosition() );
221   Storable::DataToStream( theStr, "myBasePlaneCondition", IsDefault() );
222
223   QString aStrPos, aStrCon;
224   for(int i = 0, iEnd = GetNbLines(); i < iEnd; i++){
225     aStrPos.append(QString::number(GetLinePosition(i)) + "|");
226     aStrCon.append(QString::number(IsDefaultPosition(i)) + "|");
227   }
228
229   Storable::DataToStream( theStr, "myLinePosition",  (const char*)aStrPos.toLatin1());
230   Storable::DataToStream( theStr, "myLineCondition", (const char*)aStrCon.toLatin1());
231   Storable::DataToStream( theStr,"myUseAbsLength", IsUseAbsoluteLength());
232
233   // Storing the map - \a myMapCurvesInverted
234   QString aStrCurvesInverted;
235   for(int i = 0, iEnd = GetNbLines(); i < iEnd; i++) 
236     aStrCurvesInverted.append(QString::number(IsCurveInverted(i)) + "|");
237   Storable::DataToStream( theStr, "myMapCurvesInverted", (const char*)aStrCurvesInverted.toLatin1());
238 }
239
240
241 //---------------------------------------------------------------
242 VISU::CutLines_i
243 ::~CutLines_i()
244 {
245   if(MYDEBUG) MESSAGE("CutLines_i::~CutLines_i()");
246 }
247
248
249 //---------------------------------------------------------------
250 void
251 VISU::CutLines_i
252 ::SetOrientation(VISU::CutPlanes::Orientation theOrient,
253                  CORBA::Double theXAngle, 
254                  CORBA::Double theYAngle)
255 {
256   struct TEvent: public SALOME_Event 
257   {
258     VISU_CutLinesPL* myCutLinesPL;
259     CORBA::Double myXAngle, myYAngle;
260     VISU::CutPlanes::Orientation myOrient;
261     TEvent(VISU_CutLinesPL* theCutLines, 
262            VISU::CutPlanes::Orientation theOrient,
263            CORBA::Double theXAngle, 
264            CORBA::Double theYAngle):
265       myCutLinesPL(theCutLines), 
266       myOrient(theOrient), 
267       myXAngle(theXAngle), 
268       myYAngle(theYAngle)
269     {}
270
271     virtual
272     void
273     Execute()
274     {
275       myCutLinesPL->SetOrientation(VISU_CutPlanesPL::PlaneOrientation(myOrient),
276                                    myXAngle, 
277                                    myYAngle);
278     }
279   };
280
281   VISU::TSetModified aModified(this);
282
283   ProcessVoidEvent(new TEvent(myCutLinesPL, theOrient, theXAngle, theYAngle));
284 }
285
286 //---------------------------------------------------------------
287 void 
288 VISU::CutLines_i
289 ::SetOrientation2(VISU::CutPlanes::Orientation theOrient,
290                   CORBA::Double theXAngle, 
291                   CORBA::Double theYAngle)
292 {
293   struct TEvent: public SALOME_Event 
294   {
295     VISU_CutLinesPL* myCutLinesPL;
296     CORBA::Double myXAngle, myYAngle;
297     VISU::CutPlanes::Orientation myOrient;
298     TEvent(VISU_CutLinesPL* theCutLines, 
299            VISU::CutPlanes::Orientation theOrient,
300            CORBA::Double theXAngle, 
301            CORBA::Double theYAngle):
302       myCutLinesPL(theCutLines), 
303       myOrient(theOrient), 
304       myXAngle(theXAngle), 
305       myYAngle(theYAngle)
306     {}
307
308     virtual
309     void
310     Execute()
311     {
312       myCutLinesPL->SetOrientation(VISU_CutPlanesPL::PlaneOrientation(myOrient),
313                                    myXAngle, 
314                                    myYAngle,
315                                    1);
316     }
317   };
318
319   VISU::TSetModified aModified(this);
320
321   ProcessVoidEvent(new TEvent(myCutLinesPL, theOrient, theXAngle, theYAngle));
322 }
323
324 //---------------------------------------------------------------
325 VISU::CutPlanes::Orientation 
326 VISU::CutLines_i
327 ::GetOrientationType() 
328
329   return VISU::CutPlanes::Orientation(myCutLinesPL->GetPlaneOrientation());
330 }
331
332 //---------------------------------------------------------------
333 VISU::CutPlanes::Orientation 
334 VISU::CutLines_i
335 ::GetOrientationType2() 
336
337   return VISU::CutPlanes::Orientation(myCutLinesPL->GetPlaneOrientation(1));
338 }
339
340 //---------------------------------------------------------------
341 CORBA::Double
342 VISU::CutLines_i
343 ::GetRotateX()
344 {
345   return myCutLinesPL->GetRotateX();
346 }
347
348 //---------------------------------------------------------------
349 CORBA::Double 
350 VISU::CutLines_i
351 ::GetRotateY()
352 {
353   return myCutLinesPL->GetRotateY();
354 }
355
356
357 //---------------------------------------------------------------
358 CORBA::Double 
359 VISU::CutLines_i
360 ::GetRotateX2()
361 {
362   return myCutLinesPL->GetRotateX(1);
363 }
364
365 //---------------------------------------------------------------
366 CORBA::Double 
367 VISU::CutLines_i
368 ::GetRotateY2()
369 {
370   return myCutLinesPL->GetRotateY(1);
371 }
372
373
374 //---------------------------------------------------------------
375 void
376 VISU::CutLines_i
377 ::SetDisplacement(CORBA::Double theDisp) 
378
379   VISU::TSetModified aModified(this);
380
381   ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_CutLinesPL, vtkFloatingPointType, int>
382                    (GetSpecificPL(), &VISU_CutLinesPL::SetDisplacement, theDisp, 0));
383 }
384
385 //---------------------------------------------------------------
386 void
387 VISU::CutLines_i
388 ::SetDisplacement2(CORBA::Double theDisp) 
389
390   VISU::TSetModified aModified(this);
391
392   ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_CutLinesPL, vtkFloatingPointType, int>
393                    (GetSpecificPL(), &VISU_CutLinesPL::SetDisplacement, theDisp, 1));
394 }
395
396
397 //---------------------------------------------------------------
398 CORBA::Double 
399 VISU::CutLines_i
400 ::GetDisplacement() 
401
402   return myCutLinesPL->GetDisplacement();
403 }
404
405 //---------------------------------------------------------------
406 CORBA::Double 
407 VISU::CutLines_i
408 ::GetDisplacement2() 
409
410   return myCutLinesPL->GetDisplacement(1);
411 }
412
413
414 //---------------------------------------------------------------
415 void 
416 VISU::CutLines_i
417 ::SetBasePlanePosition(CORBA::Double thePlanePosition)
418 {
419   VISU::TSetModified aModified(this);
420
421   ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_CutLinesPL, vtkFloatingPointType>
422                    (GetSpecificPL(), &VISU_CutLinesPL::SetPosition, thePlanePosition));
423 }
424
425 //---------------------------------------------------------------
426 CORBA::Double 
427 VISU::CutLines_i
428 ::GetBasePlanePosition()
429
430   return myCutLinesPL->GetPosition();
431 }
432
433 //---------------------------------------------------------------
434 void 
435 VISU::CutLines_i
436 ::SetLinePosition(CORBA::Long thePlaneNumber, 
437                   CORBA::Double thePlanePosition)
438 {
439   VISU::TSetModified aModified(this);
440
441   ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_CutLinesPL, int, vtkFloatingPointType>
442                    (GetSpecificPL(), &VISU_CutLinesPL::SetPartPosition, thePlaneNumber, thePlanePosition));
443 }
444
445 //---------------------------------------------------------------
446 CORBA::Double 
447 VISU::CutLines_i
448 ::GetLinePosition(CORBA::Long thePlaneNumber)
449
450   return myCutLinesPL->GetPartPosition(thePlaneNumber,1);
451 }
452
453
454 //---------------------------------------------------------------
455 void
456 VISU::CutLines_i
457 ::SetDefault()
458 {
459   VISU::TSetModified aModified(this);
460
461   ProcessVoidEvent(new TVoidMemFunEvent<VISU_CutLinesPL>
462                    (GetSpecificPL(), &VISU_CutLinesPL::SetDefault));
463 }
464
465 //---------------------------------------------------------------
466 CORBA::Boolean
467 VISU::CutLines_i
468 ::IsDefault()
469
470   return myCutLinesPL->IsDefault();
471 }
472
473 //---------------------------------------------------------------
474 void
475 VISU::CutLines_i
476 ::SetDefaultPosition(CORBA::Long thePlaneNumber)
477 {
478   VISU::TSetModified aModified(this);
479
480   ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_CutLinesPL, int>
481                    (GetSpecificPL(), &VISU_CutLinesPL::SetPartDefault, thePlaneNumber));
482 }
483
484 //---------------------------------------------------------------
485 CORBA::Boolean
486 VISU::CutLines_i
487 ::IsDefaultPosition(CORBA::Long thePlaneNumber)
488
489   return myCutLinesPL->IsPartDefault(thePlaneNumber);
490 }
491
492 //---------------------------------------------------------------
493 /*! Invert all curves of corresponding table
494  * see void VISU::CutLines_i::SetCurveInverted(CORBA::Long theCurveNumber,CORBA::Boolean theInvert)
495  * \param theInvert - Invert all curves, if value is TRUE, else not.
496  */
497 void
498 VISU::CutLines_i
499 ::SetAllCurvesInverted(CORBA::Boolean theInvert)
500 {
501   for(int i=0; i < GetNbLines(); i++)
502     SetCurveInverted(i, theInvert);
503 }
504
505 //---------------------------------------------------------------
506 /*! Checks the orientation of all curves
507  * \retval TRUE - if all curves are inverted, else FALSE
508  */
509 CORBA::Boolean 
510 VISU::CutLines_i
511 ::IsAllCurvesInverted()
512 {
513   for (int i=0; i<GetNbLines(); i++)
514     if (!IsCurveInverted(i)) return false;
515   return true;
516 }
517
518 //---------------------------------------------------------------
519 /*! Sets orientation of curve
520  * \param theCurveNumber - integer value, number of cut line.
521  * \param theInvert      - boolean value, TRUE or false.
522  */
523 void
524 VISU::CutLines_i
525 ::SetCurveInverted(CORBA::Long theCurveNumber, CORBA::Boolean theInvert)
526 {
527   if(myMapCurvesInverted[theCurveNumber] == theInvert)
528     return;
529
530   VISU::TSetModified aModified(this);
531
532   myMapCurvesInverted[theCurveNumber] = theInvert;
533   myParamsTime.Modified();
534 }
535
536 //---------------------------------------------------------------
537 /*! Checks orientation of curve.
538  * \param theCurveNumber - integer value, number of cut line.
539  * \retval TRUE - if line in the table is inverted, else FALSE.
540  */
541 CORBA::Boolean
542 VISU::CutLines_i
543 ::IsCurveInverted(CORBA::Long theCurveNumber)
544 {
545   return myMapCurvesInverted[theCurveNumber];
546 }
547
548 //---------------------------------------------------------------
549 /*! It control the way the length of cutlines is shown: using aboslute or relative values
550 * \param theAbsLength - boolean value, TRUE or false.
551 */
552 void
553 VISU::CutLines_i
554 ::SetUseAbsoluteLength(CORBA::Boolean theAbsLength)
555 {
556   if ( myUseAbsLength == theAbsLength )
557     return;
558
559   VISU::TSetModified aModified(this);
560
561   myUseAbsLength = theAbsLength;
562   myParamsTime.Modified();
563 }
564
565 //---------------------------------------------------------------
566 CORBA::Boolean
567 VISU::CutLines_i
568 ::IsUseAbsoluteLength()
569 {
570   return myUseAbsLength;
571 }
572
573 //---------------------------------------------------------------
574 void
575 VISU::CutLines_i
576 ::SetNbLines(CORBA::Long theNb) 
577
578   VISU::TSetModified aModified(this);
579
580   ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_CutLinesPL, int>
581                    (GetSpecificPL(), &VISU_CutLinesPL::SetNbParts, theNb));
582 }
583
584 //---------------------------------------------------------------
585 CORBA::Long
586 VISU::CutLines_i
587 ::GetNbLines() 
588
589   return myCutLinesPL->GetNbParts();
590 }
591
592
593 //---------------------------------------------------------------
594 void
595 VISU::CutLines_i
596 ::CreatePipeLine(VISU_PipeLine* thePipeLine)
597 {
598   if(!thePipeLine){
599     myCutLinesPL = VISU_CutLinesPL::New();
600   }else
601     myCutLinesPL = dynamic_cast<VISU_CutLinesPL*>(thePipeLine);
602
603   TSuperClass::CreatePipeLine(myCutLinesPL);
604 }
605
606
607 //----------------------------------------------------------------------------
608 bool
609 VISU::CutLines_i
610 ::CheckIsPossible() 
611 {
612   return IsPossible(GetCResult(),GetCMeshName(),GetEntity(),GetCFieldName(),GetTimeStampNumber(),true);
613 }
614
615
616 //---------------------------------------------------------------
617 VISU_Actor* 
618 VISU::CutLines_i
619 ::CreateActor()
620 {
621   if(VISU_Actor* anActor = TSuperClass::CreateActor()){
622     anActor->SetVTKMapping(true);
623     SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
624     int aDispMode = aResourceMgr->integerValue("VISU" , "cut_lines_represent", 2);
625     anActor->SetRepresentation(aDispMode);
626     return anActor;
627   }
628   return NULL;
629 }
630
631 //---------------------------------------------------------------
632 void
633 VISU::CutLines_i
634 ::BuildTableOfReal(SALOMEDS::SObject_var theSObject)
635 {
636   try{
637     if(MYDEBUG) MESSAGE("CutPlanes_i::BuildTableOfReal");
638     Update();
639     SALOMEDS::GenericAttribute_var anAttr;
640     SALOMEDS::StudyBuilder_var aStudyBuilder = GetStudyDocument()->NewBuilder();
641     anAttr = aStudyBuilder->FindOrCreateAttribute(theSObject, "AttributeTableOfReal");
642     SALOMEDS::AttributeTableOfReal_var aTableOfReal = SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
643     
644     typedef set<vtkFloatingPointType> TXCont;
645     typedef map<vtkFloatingPointType,vtkFloatingPointType> TXYMap;
646     typedef map<int,TXYMap> TXYMapCont;
647     typedef map<long,long> TLineIdCont;
648     
649     QString aTitle( GetScalarBarTitle().c_str() );
650     aTitle = aTitle.simplified();
651     aTableOfReal->SetTitle( aTitle.toLatin1().data() );
652     
653     int iLineEnd = myCutLinesPL->GetAppendPolyData()->GetNumberOfInputConnections(0);
654     if(MYDEBUG) MESSAGE("CutPlanes_i::BuildTableOfReal iLineEnd = "<<iLineEnd);
655     TXCont aXCont;
656     TXYMapCont aXYMapCont; 
657     TLineIdCont aLineIdCont;  // Define internal numeration of lines
658     const vtkFloatingPointType *aDirLn = myCutLinesPL->GetDirLn();
659     const vtkFloatingPointType *aBasePnt = myCutLinesPL->GetBasePnt();
660     const vtkFloatingPointType *aBoundPrjLn = myCutLinesPL->GetBoundPrjLn();
661     for(int iLine = 0, jLine = 0; iLine < iLineEnd; iLine++){
662       vtkDataSet *aDataSet = myCutLinesPL->GetAppendPolyData()->GetInput(iLine);
663       aDataSet->Update();
664       int aNbPoints = aDataSet->GetNumberOfPoints();
665       if(!aNbPoints) continue;
666       vtkPointData *aPointData = aDataSet->GetPointData();
667       vtkDataArray *aScalars = aPointData->GetScalars();
668       vtkCellDataToPointData *aFilter = NULL;
669       if(!aScalars) {
670         aFilter = vtkCellDataToPointData::New();
671         aFilter->SetInput(aDataSet);
672         aFilter->PassCellDataOn();
673         aDataSet = aFilter->GetOutput();
674         aDataSet->Update();
675       }
676       aPointData = aDataSet->GetPointData();
677       aScalars = aPointData->GetScalars();
678       if(!aScalars) continue;
679       if(MYDEBUG) MESSAGE("CutPlanes_i::BuildTableOfReal iLine = "<<iLine<<"; aNbPoints = "<<aNbPoints);
680       aLineIdCont[iLine] = jLine++;
681       TXYMap& aXYMap = aXYMapCont[iLine];
682       vtkFloatingPointType aPnt[3], aVect[3], aDist, aTopBnd, aDivide;
683       aTopBnd = aBoundPrjLn[2];
684       aDivide = aBoundPrjLn[2];
685       if( !IsUseAbsoluteLength() ){
686         aTopBnd = 1.0;
687       }
688       else aDivide = 1.0;
689
690       for(int i = 0; i < aNbPoints; i++){
691         aDataSet->GetPoint(i,aPnt);
692         for(int j = 0; j < 3; j++)
693           aVect[j] = aPnt[j] - aBasePnt[j];
694         //VISU::Sub(aPnt,aBasePnt,aVect);
695         if ( fabs(aBoundPrjLn[2]) < EPS_machine )
696           aDist = 0.5;
697         else
698           {
699             aDist = vtkMath::Dot(aVect,aDirLn)/aDivide; 
700             // the workaround
701             if(aDist < 0.0) aDist = 0.0; 
702             if(aDist > aTopBnd) aDist = aTopBnd;
703           }
704         aXYMap[aDist] = aScalars->GetTuple1(i);
705       }
706       if(aFilter)
707         aFilter->Delete();
708     }
709     if(aXYMapCont.size() == 0)
710       throw std::runtime_error("CutPlanes_i::BuildTableOfReal aXYMapCont.size() == 0 !!!");
711
712     {
713       // Invertion all curves in the table, which has inversion flag is TRUE (see \a myMapCurvesInverted)
714       for(int iLine=0; iLine < iLineEnd; iLine++){
715         if (!IsCurveInverted(iLine)) continue;
716         TXYMap aNewXYMap;
717         TXYMap& aXYMap = aXYMapCont[iLine];
718         TXYMap::const_iterator aXYMapIter = aXYMap.begin();
719         std::list<vtkFloatingPointType> XKeys;
720         for (;aXYMapIter != aXYMap.end() ; aXYMapIter++) XKeys.push_back(aXYMapIter->first);
721         XKeys.sort();
722         if (XKeys.size() > 1) {
723           vtkFloatingPointType a_first_indx = XKeys.front();
724           vtkFloatingPointType a_last_indx = XKeys.back();
725           if (a_first_indx > a_last_indx){
726             XKeys.reverse();
727             vtkFloatingPointType tmp = a_first_indx;
728             a_first_indx = a_last_indx;
729             a_last_indx = tmp;
730           }
731           std::list<vtkFloatingPointType>::const_iterator aIter = XKeys.begin();
732           for (int k=0;k<XKeys.size() && aIter != XKeys.end();k++,aIter++){
733             // Warning: value '1.0' come from workaround:
734             // see also aDist = vtkMath::Dot(aVect,aDirLn) / aBoundPrjLn[2];
735             // aDist >= 0 and aDist<=1.0
736             vtkFloatingPointType aTopBnd = aBoundPrjLn[2];
737             if( !IsUseAbsoluteLength() ){
738               aTopBnd = 1.0;
739             }
740             aNewXYMap[aTopBnd - *aIter] = aXYMap[*aIter];
741           }
742           TXYMap::const_iterator aNewXYMapIter = aNewXYMap.begin();
743           aXYMap.clear();
744           for (;aNewXYMapIter != aNewXYMap.end();aNewXYMapIter++) {
745             aXYMap[aNewXYMapIter->first] = aNewXYMapIter->second;
746           }
747         }
748       }
749     }
750     //Resorting of theXYMap
751     TXYMapCont::iterator aXYMapContIter = aXYMapCont.begin();
752     for(; aXYMapContIter != aXYMapCont.end(); aXYMapContIter++){
753       TXYMap& aXYMap = aXYMapContIter->second, aNewXYMap;
754       if(aXYMap.size() > 2){  
755         // Try to smooth the values of the line by applying linear approximation
756         TXYMap::const_iterator aXYMapIter[2] = {aXYMap.begin(), ++aXYMap.begin()};
757         aNewXYMap[aXYMapIter[0]->first] = aXYMapIter[0]->second;
758         aXCont.insert(aXYMapIter[0]->first);
759         for(; aXYMapIter[1] != aXYMap.end(); aXYMapIter[0]++, aXYMapIter[1]++){
760           vtkFloatingPointType aY[3] = {aXYMapIter[0]->second, aXYMapIter[1]->second, 0.0};
761           aY[2] = (aY[0] + aY[1])/2.0;
762           vtkFloatingPointType aX[3] = {aXYMapIter[0]->first, aXYMapIter[1]->first, 0.0};
763           aX[2] = (aX[0] + aX[1])/2.0;
764           aNewXYMap[aX[2]] = aY[2];
765           aXCont.insert(aX[2]);
766         }
767         aNewXYMap[aXYMapIter[0]->first] = aXYMapIter[0]->second;
768         aXCont.insert(aXYMapIter[0]->first);
769         aXYMap = aNewXYMap;
770       }else{
771         TXYMap::const_iterator aXYMapIter = aXYMap.begin();
772         for(; aXYMapIter != aXYMap.end(); aXYMapIter++)
773           aXCont.insert(aXYMapIter->first);
774       }
775     }
776     if(aXCont.size() == 0)
777       throw std::runtime_error("CutPlanes_i::BuildTableOfReal aXCont.size() == 0 !!!");
778     QString aString;
779     int iEnd = aXCont.size();
780     aTableOfReal->SetNbColumns(iEnd);
781     TXCont::const_iterator aXContIter = aXCont.begin();
782     for(long i = 0; aXContIter != aXCont.end(); aXContIter++, i++){
783       vtkFloatingPointType aDist = *aXContIter; 
784       aTableOfReal->PutValue(aDist,1,i+1);
785       aString.sprintf("%d",i);
786       aTableOfReal->SetColumnTitle(i+1,(const char*)aString.toLatin1());
787       if(MYDEBUG) MESSAGE("CutPlanes_i::BuildTableOfReal aDist = "<<aDist);
788       TXYMapCont::const_iterator aXYMapContIter = aXYMapCont.begin();
789       for(; aXYMapContIter != aXYMapCont.end(); aXYMapContIter++){
790         long iLine = aXYMapContIter->first;
791         long iLineId = aLineIdCont[iLine];
792         const TXYMap& aXYMap = aXYMapCont[iLine];
793         TXYMap::const_iterator aXYMapIter = aXYMap.find(aDist);
794         // Can we find some value that belong to the line and have the same X coordinate?
795         if(aXYMapIter == aXYMap.end()) continue;
796         vtkFloatingPointType aVal = aXYMapIter->second;
797         aTableOfReal->PutValue(aVal,iLineId+2,i+1);
798       }
799     }
800     {
801       aTableOfReal->SetRowTitle(1,"X");
802       aTableOfReal->SetRowUnit(1,"-");
803       QString aUnitName = GetField()->myUnitNames[0].c_str();
804       int aScalarMode = myCutLinesPL->GetScalarMode();
805       if(aScalarMode != 0) 
806         aUnitName = GetField()->myUnitNames[aScalarMode-1].c_str();
807       aUnitName = aUnitName.simplified();
808       if(aUnitName.isEmpty()) aUnitName = "-";
809       TXYMapCont::const_iterator aXYMapContIter = aXYMapCont.begin();
810       for(; aXYMapContIter != aXYMapCont.end(); aXYMapContIter++){
811         long iLine = aXYMapContIter->first;
812         long iLineId = aLineIdCont[iLine];
813         aString.sprintf("Y%d",iLine);
814         if(MYDEBUG) 
815           MESSAGE("CutPlanes_i::BuildTableOfReal - SetRowTitle("<<iLineId+2<<",'"<<(const char*)aString.toLatin1()<<"')");
816         aTableOfReal->SetRowTitle(iLineId+2,(const char*)aString.toLatin1());
817         aTableOfReal->SetRowUnit(iLineId+2,(const char*)aUnitName.toLatin1());
818       }
819     }
820   }catch(std::exception& exc){
821     INFOS("Follow exception was occured :\n"<<exc.what());
822   }catch (...){
823     INFOS("Unknown exception was occured !!!");
824   }
825 }