Salome HOME
NRI : Remove dependence with KERNEL.
[modules/visu.git] / src / VISU_I / VISU_PrsObject_i.cc
1 using namespace std;
2 // File:        VISU_PrsObject_i.cxx
3 // Created:     Fri Jan 17 09:27:59 2003
4 // Author:      Alexey PETROV
5 //              <apo@ivanox.nnov.matra-dtv.fr>
6
7
8 #include "VISU_PrsObject_i.hh"
9 #include "VISU_Extractor.hxx"
10 #include "VISU_FieldTransform.hxx"
11 #include "VISU_LookupTable.hxx"
12 #include "VISU_ScalarBarActor.hxx"
13 #include "VISU_Actor.h"
14 using namespace VISU;
15
16 //#include "QAD_Study.h"
17 #include "QAD_Config.h"
18
19 #include <vtkUnstructuredGridReader.h>
20 #include <vtkUnstructuredGridWriter.h>
21
22 #include <vtkDataSet.h>
23 #include <vtkDataSetMapper.h>
24 #include <vtkProperty.h>
25
26 #include <vtkWarpVector.h>
27 #include <vtkContourFilter.h>
28 #include <vtkAppendPolyData.h>
29 #include <vtkCutter.h>
30 #include <vtkPlane.h>
31 #include <vtkCellDataToPointData.h>
32
33 #include <vtkGlyph3D.h>
34 #include <vtkHedgeHog.h>
35 #include <vtkPolyDataSource.h>
36 #include <vtkGlyphSource2D.h>
37 #include <vtkTransformPolyDataFilter.h>
38 #include <vtkCellCenters.h>
39 #include <vtkConeSource.h>
40 #include <vtkStreamLine.h>
41 #include <vtkTriangleFilter.h>
42 #include <vtkGeometryFilter.h>
43 #include <vtkFeatureEdges.h>
44
45
46 #define CHECKTIME
47 #ifdef CHECKTIME
48 #include <OSD_Timer.hxx>
49 #endif
50
51 #ifdef DEBUG
52 static int MYDEBUG = 1;
53 static int MYDEBUGWITHFILES = 0;
54 #else
55 static int MYDEBUG = 0;
56 static int MYDEBUGWITHFILES = 0;
57 #endif
58 static float EPS = 1.0E-3;
59 const float PI2 = 2.0*PI;
60
61 //==============================================================================
62 void SetIOR(SALOMEDS::SObject_var& theSObject, const char* theIOR){
63   SALOMEDS::GenericAttribute_var anAttr;
64   theSObject->FindAttribute(anAttr, "AttributeIOR");
65   SALOMEDS::AttributeIOR_var anIOR  = SALOMEDS::AttributeIOR::_narrow(anAttr);
66   CORBA::String_var aValue(theIOR);
67   anIOR->SetValue(aValue);
68 }
69
70 float CalcScaleFactor(float theBound[6], int theNbElem){
71   float aVolume = 1, vol, idim = 0;
72   for(int i = 0; i < 6; i += 2){
73     vol = fabs(theBound[i+1] - theBound[i]);
74     if(vol > 0) {
75       idim++; 
76       aVolume *= vol;
77     }
78   }
79   aVolume /= theNbElem;
80   float aFactor = pow(aVolume,(float)1./idim);
81   return aFactor;
82 }
83
84 VISU::Result_i* GetResult(SALOMEDS::SObject_ptr theSObject){
85   VISU::Result_var aResult = FindResult(theSObject);
86   if(!aResult->_is_nil())
87     return dynamic_cast<VISU::Result_i*>(VISU::GetServant(aResult.in()));
88   return NULL;
89 }
90
91
92 //==============================================================================
93 QString VISU::PrsObject_i::GetEntry() { 
94   CORBA::String_var anIOR = GetID();
95   SALOMEDS::SObject_var aSObject = myStudy->FindObjectIOR(anIOR);
96   CORBA::String_var anEntry = aSObject->GetID();
97   return anEntry.in();
98 }
99
100
101 //----------------------------------------------------------------
102 //                      Prs3d Object
103 //----------------------------------------------------------------
104 VISU::Prs3d_i::Prs3d_i(Result_i* theResult) : 
105        PrsObject_i(theResult->GetStudyDocument()), 
106        myResult(theResult) 
107 {
108   myMapper = MapperType::New();
109   myColor.R = myColorRGB[0] = 0.5;
110   myColor.G = myColorRGB[1] = 0.5;
111   myColor.B = myColorRGB[2] = 0.5;
112   myAddToStudy = true;
113 }
114
115 void VISU::Prs3d_i::SameAs(const Prs3d_i* theOrigin)
116 {
117   SetColor(theOrigin->GetColor());
118   myMapper = MapperType::New();
119   myMapper->ShallowCopy(theOrigin->GetMapper());
120 }
121
122 VISU::Prs3d_i::~Prs3d_i() {
123   myMapper->Delete();
124 }
125
126
127 /**
128  * Create Actor referred on existing IO
129  */
130 VISU_Actor* VISU::Prs3d_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO){
131   Update();
132   float bounds[6];
133   static float eps = VTK_LARGE_FLOAT * 0.1 ;
134   myMapper->GetBounds(bounds);
135   for (int i =0; i <6; ++i) {
136     if (fabs (bounds[i] - myBounds[i]) > eps ) { 
137       MESSAGE(" Boundaries of actor do not coincide with boundaries of initial shape : \
138                                               error finish of VISU::Prs3d_i::CreateActor");
139       return NULL;}
140   }
141   VISU_Actor* aActor = VISU_Actor::New();
142   if(myMapper->GetInput()->GetNumberOfCells() < 10)
143     aActor->IsShrinkable = false;  //Bug SAL2011 Crash on shrink view 
144   else
145     aActor->IsShrinkable = true;
146   aActor->SetMapper(myMapper);
147   if (myAddToStudy) {
148     if (theIO.IsNull()){
149       //Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(GetEntry(),"VISU",GetName()); 
150       //There is a bug in gcc compiler - const Standard_CString is mapping as char * const not as const char *
151       //(where Standard_CString is defined as typedef char* Standard_CString)
152       Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(strdup(GetEntry()),"VISU",
153                                                                            (const Standard_CString)GetName());
154       aActor->setIO(anIO); 
155     }else
156       aActor->setIO(theIO); 
157   }
158   aActor->DataSource = myMapper->GetInput();
159   aActor->Presentation = this;
160   vtkProperty* aProperty = aActor->GetProperty();
161   aProperty->SetColor(myColorRGB);
162   return aActor;
163 }
164
165 VISU::Storable* VISU::Prs3d_i::Restore(const Storable::TRestoringMap& theMap, int theBuilding)
166      throw(std::logic_error&)
167 {
168   if(MYDEBUG) MESSAGE(GetComment());
169   myName = VISU::Storable::FindValue(theMap,"myName");
170   myColorRGB[0] = myColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble();
171   myColorRGB[1] = myColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble();
172   myColorRGB[2] = myColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble();
173   return NULL;
174 }
175
176 void VISU::Prs3d_i::ToStream(ostrstream& theStr){
177   Storable::DataToStream( theStr, "myName",   myName.c_str() );
178   Storable::DataToStream( theStr, "myColor.R",   myColor.R );
179   Storable::DataToStream( theStr, "myColor.G",   myColor.G );
180   Storable::DataToStream( theStr, "myColor.B",   myColor.B );
181 }
182
183 void VISU::Prs3d_i::Update()
184
185   myMapper->Update(); 
186 }
187
188
189 //----------------------------------------------------------------
190 //                      Mesh Object
191 //----------------------------------------------------------------
192 int VISU::Mesh_i::myNbPresent = 0;
193
194 QString VISU::Mesh_i::GenerateName() { return VISU::GenerateName("Mesh",myNbPresent++);}
195
196 const string VISU::Mesh_i::myComment = "MESH";
197
198 const char* VISU::Mesh_i::GetComment() const { return myComment.c_str();}
199
200
201 VISU::Mesh_i::Mesh_i(Result_i* theResult) : 
202        PrsObject_i(theResult->GetStudyDocument()), 
203        Prs3d_i(theResult) 
204 {
205   myInput = NULL;
206   SALOMEDS::Color aColor = {0,1,1};
207   SetCellColor(aColor);
208   SetNodeColor(aColor);
209   SALOMEDS::Color aLinkColor = {83/255.,83/255.,83/255.};
210   SetLinkColor(aLinkColor);
211 }
212
213 void VISU::Mesh_i::SameAs(const Mesh_i* theOrigin)
214 {
215   VISU::Prs3d_i::SameAs(theOrigin);
216   Mesh_i* aMesh = (Mesh_i*) theOrigin;
217   SetCellColor(aMesh->GetCellColor());
218   SetNodeColor(aMesh->GetNodeColor());
219   SetLinkColor(aMesh->GetLinkColor());
220   SetPresentationType(aMesh->GetPresentationType());
221   //myName = string("Copy of ") + theOrigin->GetName();
222   Build(false);
223 }
224
225 VISU::Storable* VISU::Mesh_i::Create(const char* theMeshName, int theEntity){
226   myMeshName = theMeshName;
227   myEntity = theEntity;
228   mySubMeshName = "";
229   return Build(false);
230 }
231
232 VISU::Storable* VISU::Mesh_i::Create(const char* theMeshName, int theEntity, const char* theFamilyName){
233   myMeshName = theMeshName;
234   myEntity = theEntity;
235   mySubMeshName = theFamilyName;
236   return Build(false);
237 }
238 VISU::Storable* VISU::Mesh_i::Create(const char* theMeshName, const char* theGroupName){
239   myMeshName = theMeshName;
240   myEntity = -1;
241   mySubMeshName = theGroupName;
242   return Build(false);
243 }
244
245 VISU::Storable* VISU::Mesh_i::Restore(const Storable::TRestoringMap& theMap, int theBuilding)
246      throw(std::logic_error&)
247 {
248   Prs3d_i::Restore(theMap,false);
249
250   myMeshName = VISU::Storable::FindValue(theMap,"myMeshName").latin1();
251   myEntity = VISU::Storable::FindValue(theMap,"myEntity").toInt();
252   mySubMeshName = VISU::Storable::FindValue(theMap,"mySubMeshName").latin1();
253
254   myCellColor.R = VISU::Storable::FindValue(theMap,"myCellColor.R").toDouble();
255   myCellColor.G = VISU::Storable::FindValue(theMap,"myCellColor.G").toDouble();
256   myCellColor.B = VISU::Storable::FindValue(theMap,"myCellColor.B").toDouble();
257
258   myNodeColor.R = VISU::Storable::FindValue(theMap,"myNodeColor.R").toDouble();
259   myNodeColor.G = VISU::Storable::FindValue(theMap,"myNodeColor.G").toDouble();
260   myNodeColor.B = VISU::Storable::FindValue(theMap,"myNodeColor.B").toDouble();
261
262   myLinkColor.R = VISU::Storable::FindValue(theMap,"myLinkColor.R").toDouble();
263   myLinkColor.G = VISU::Storable::FindValue(theMap,"myLinkColor.G").toDouble();
264   myLinkColor.B = VISU::Storable::FindValue(theMap,"myLinkColor.B").toDouble();
265
266   if(theBuilding)
267     return Build(true);
268   return NULL;
269 }
270
271 void VISU::Mesh_i::ToStream(ostrstream& theStr){
272   Prs3d_i::ToStream(theStr);
273
274   Storable::DataToStream( theStr, "myMeshName", myMeshName.c_str() );
275   Storable::DataToStream( theStr, "myEntity", myEntity );
276   Storable::DataToStream( theStr, "mySubMeshName", mySubMeshName.c_str() );
277
278   Storable::DataToStream( theStr, "myCellColor.R", myCellColor.R );
279   Storable::DataToStream( theStr, "myCellColor.G", myCellColor.G );
280   Storable::DataToStream( theStr, "myCellColor.B", myCellColor.B );
281
282   Storable::DataToStream( theStr, "myNodeColor.R", myNodeColor.R );
283   Storable::DataToStream( theStr, "myNodeColor.G", myNodeColor.G );
284   Storable::DataToStream( theStr, "myNodeColor.B", myNodeColor.B );
285
286   Storable::DataToStream( theStr, "myLinkColor.R", myLinkColor.R );
287   Storable::DataToStream( theStr, "myLinkColor.G", myLinkColor.G );
288   Storable::DataToStream( theStr, "myLinkColor.B", myLinkColor.B );
289 }
290
291 VISU::Storable* VISU::MeshRestore(SALOMEDS::SObject_ptr theSObject, 
292                                   const string& thePrefix, const Storable::TRestoringMap& theMap)
293      throw(std::logic_error&)
294 {
295   VISU::Result_i* pResult = GetResult(theSObject);
296   if(pResult != NULL){
297     VISU::Mesh_i* pResent = new VISU::Mesh_i(pResult);
298     return pResent->Restore(theMap);
299   }
300   return NULL;
301 }
302
303
304 VISU::Mesh_i::~Mesh_i(){
305   if(MYDEBUG) MESSAGE("Mesh_i::~Mesh_i()");
306 }
307
308
309 VISU::Storable* VISU::Mesh_i::Build(int theRestoring){
310   try{
311 #ifdef CHECKTIME
312     OSD_Timer timer;
313     timer.Start();
314 #endif
315     if(!theRestoring) myName = GenerateName();
316     if(myEntity >= 0) 
317       if(mySubMeshName == "") 
318         myType = VISU::TENTITY; 
319       else 
320         myType = VISU::TFAMILY;
321     else 
322       myType = VISU::TGROUP;
323     if(MYDEBUG) MESSAGE("Mesh_i::Build - myType = "<<myType);
324     //Building Input and comment for searching according label
325     QString aComment;
326     switch(myType){
327     case VISU::TENTITY : 
328       myInput = myResult->GetInput()->GetMeshOnEntity(myMeshName,(VISU::TEntity)myEntity); 
329       aComment.sprintf("myComment=ENTITY;myType=%d;myResultName=%s;myMeshName=%s;myId=%d",
330                        VISU::TENTITY,myResult->GetName(),myMeshName.c_str(),myEntity);
331       break;
332     case VISU::TFAMILY : 
333       myInput = myResult->GetInput()->GetMeshOnEntity(myMeshName,(VISU::TEntity)myEntity,mySubMeshName);
334       aComment.sprintf("myComment=FAMILY;myType=%d;myResultName=%s;myMeshName=%s;myEntityId=%d;myName=%s",
335                        VISU::TFAMILY,myResult->GetName(),myMeshName.c_str(),myEntity,mySubMeshName.c_str());
336       break;
337     case VISU::TGROUP : 
338       myInput = myResult->GetInput()->GetMeshOnGroup(myMeshName,mySubMeshName);
339       aComment.sprintf("myComment=GROUP;myType=%d;myResultName=%s;myMeshName=%s;myName=%s",
340                        VISU::TGROUP,myResult->GetName(),myMeshName.c_str(),mySubMeshName.c_str());
341       break;
342     }
343     if(myInput == NULL) throw std::runtime_error("Mesh_i::Build - myInput == NULL !!!");
344     //Binding pipeline
345     vtkUnstructuredGrid *aDataSet = myInput->GetOutput();
346     //Avoid selection points that don't belong any of cells
347     vtkGeometryFilter *aGeomFilter = vtkGeometryFilter::New();
348     aGeomFilter->SetInput(aDataSet);
349     vtkTriangleFilter *aTriangleFilter = vtkTriangleFilter::New();
350     aTriangleFilter->SetInput(aGeomFilter->GetOutput());
351     myMapper->SetInput(aTriangleFilter->GetOutput());
352     //  myMapper->SetInput(aDataSet);
353     myMapper->ScalarVisibilityOff();
354     //Setting IOR on the label
355     if(!theRestoring) {
356       string aResultEntry = myResult->GetEntry();
357       string anEntry = FindEntryWithComment(myStudy,aResultEntry.c_str(),aComment.latin1());
358       if(anEntry == "") throw std::runtime_error("Mesh_i::Build - anEntry was not found !!!");
359       SALOMEDS::SObject_var aSObj = myStudy->FindObjectID(anEntry.c_str());
360       SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
361       SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSObj,"AttributeIOR");
362       SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
363       CORBA::String_var aString = GetID();
364       anIOR->SetValue(aString); 
365     }
366 #ifdef CHECKTIME
367     timer.Stop();
368     timer.Show();
369 #endif
370     aDataSet->GetBounds(myBounds);
371     return this;
372   }catch(std::runtime_error& exc){
373     MESSAGE("Follow exception was accured :\n"<<exc.what());
374   }catch(...){
375     MESSAGE("Unknown exception was accured!");
376   }
377   return NULL;
378 }
379
380
381 VISU_Actor* VISU::Mesh_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) {
382   VISU_Actor* aActor = VISU::Prs3d_i::CreateActor(theIO);
383   if ( !aActor ) return NULL;
384   aActor->VisuActorType = VisuActorType_Mesh;
385   
386   vtkProperty* aProperty = aActor->GetProperty();
387   //aProperty->SetRepresentation(TypeRepresentation);
388   aProperty->BackfaceCullingOff();
389   aProperty->EdgeVisibilityOn();
390
391   vtkGeometryFilter *gf = vtkGeometryFilter::New();
392   gf->SetInput(aActor->DataSource);
393   vtkFeatureEdges *edges = vtkFeatureEdges::New();
394   edges->SetInput(gf->GetOutput());
395   edges->BoundaryEdgesOn();
396   edges->ManifoldEdgesOn();
397
398   vtkPolyDataMapper *edgeMapper = vtkPolyDataMapper::New();
399   edgeMapper->SetInput(edges->GetOutput());
400   edgeMapper->ScalarVisibilityOff();
401   
402   aActor->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
403   aActor->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
404
405   aActor->EdgeDevice->SetMapper(edgeMapper);
406   edgeMapper->Update();
407
408   aActor->EdgeDevice->GetProperty()->SetColor(myLinkColor.R, myLinkColor.G, myLinkColor.B);
409
410   aActor->EdgeDevice->VisibilityOn();
411   
412   return aActor;
413 }
414  
415
416
417 //==============================================================================
418 int VISU::ScalarMap_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, 
419                                   const char* theFieldName, double theIteration){
420   const VISU::TField* aField = theResult->GetInput()->GetField(theMeshName,(VISU::TEntity)theEntity,theFieldName);
421   if(aField == NULL) return 0;
422   const VISU::TField::TValField& aValField = aField->myValField;
423   if(aValField.find((int)theIteration) == aValField.end()) return 0;
424   return 1;
425 }
426
427 int VISU::ScalarMap_i::myNbPresent = 0;
428 QString VISU::ScalarMap_i::GenerateName() { return VISU::GenerateName("ScalarMap",myNbPresent++);}
429
430 const string VISU::ScalarMap_i::myComment = "SCALARMAP";
431 const char* VISU::ScalarMap_i::GetComment() const { return myComment.c_str();}
432
433 VISU::ScalarMap_i::ScalarMap_i(Result_i* theResult, bool theAddToStudy) : 
434        PrsObject_i(theResult->GetStudyDocument()), 
435        Prs3d_i(theResult) 
436 {
437   myAddToStudy = theAddToStudy;
438   myInput = VISU_Extractor::New();
439   myFieldTransform = VISU_FieldTransform::New();
440 }
441
442 void VISU::ScalarMap_i::SameAs(const ScalarMap_i* theOrigin)
443 {
444   ScalarMap_i* aScalarMap = (ScalarMap_i*) theOrigin;
445   VISU::Prs3d_i::SameAs(aScalarMap);
446   myField = aScalarMap->GetField();
447   myMeshName = myField->myMeshName;
448   myEntity = myField->myEntity;
449   myIteration = aScalarMap->GetIteration();
450   myFieldName = aScalarMap->GetFieldName();
451
452   SetScalarMode(aScalarMap->GetScalarMode());
453   Build(false);
454   SetScaling(aScalarMap->GetScaling());
455   SetOrientation(aScalarMap->GetOrientation());
456   SetPosition(aScalarMap->GetPosX(), aScalarMap->GetPosY());
457   SetSize(aScalarMap->GetWidth(), aScalarMap->GetHeight());
458   SetNbColors(aScalarMap->GetNbColors());
459   SetLabels(aScalarMap->GetLabels());
460   SetTitle(aScalarMap->GetTitle());
461   //if (aScalarMap->isRangeFixed())
462   SetRange(aScalarMap->GetMin(), aScalarMap->GetMax());
463     //else
464     //CalculateRange();
465   //myScalarMode = aScalarMap->GetScalarMode();
466   //myName = string("Copy of ") + theOrigin->GetName();
467 }
468
469
470 /**
471  * Creates Scalar Map and initialises it from resources
472  */
473 VISU::Storable* VISU::ScalarMap_i::Create(const char* theMeshName, VISU::Entity theEntity, 
474                                           const char* theFieldName, CORBA::Double theIteration){
475   myIsFixedRange = false;
476
477   // Orientation
478   QString aOrient = QAD_CONFIG->getSetting("Visu:SBOrientation");
479   if ( !aOrient.isEmpty() ) 
480     myOrientation = (VISU::ScalarMap::Orientation) aOrient.toInt();
481   else
482     myOrientation = VISU::ScalarMap::VERTICAL;
483
484   // Scalar Bar origin
485   QString aXorigin = QAD_CONFIG->getSetting("Visu:SBXorigin");
486   if ( !aXorigin.isEmpty() )
487     myPosition[0] = aXorigin.toFloat();
488   else {
489     if(myOrientation == VISU::ScalarMap::VERTICAL) {
490       myPosition[0] = 0.03;
491     } else {
492       myPosition[0] = 0.2;
493     }
494   }
495   
496   QString aYorigin = QAD_CONFIG->getSetting("Visu:SBYorigin");
497   if ( !aYorigin.isEmpty() )
498     myPosition[1] = aYorigin.toFloat();
499   else {
500     if(myOrientation == VISU::ScalarMap::VERTICAL) {
501       myPosition[1] = 0.1;
502     } else {
503       myPosition[1] = 0.012;
504     }
505   }
506
507   // Scalar Bar size
508   QString aWidth = QAD_CONFIG->getSetting("Visu:SBWidth");
509   if ( !aWidth.isEmpty() )
510     myWidth = aWidth.toFloat();
511   else {
512     myWidth =(myOrientation == VISU::ScalarMap::VERTICAL)? 0.17:0.6;
513   }
514   QString aHeight = QAD_CONFIG->getSetting("Visu:SBHeight");
515   if ( !aHeight.isEmpty() )
516     myHeight = aHeight.toFloat();
517   else {
518     myHeight =(myOrientation == VISU::ScalarMap::VERTICAL)? 0.8:0.12;
519   }
520
521   // Nb of Colors
522   QString aColors = QAD_CONFIG->getSetting("Visu:SBNumberOfColors");
523   myNumberOfColors = (aColors.isEmpty())? 64 : aColors.toInt();
524   if (myNumberOfColors > 64) 
525     myNumberOfColors = 64;
526
527   // Nb of Labels
528   QString aLabels = QAD_CONFIG->getSetting("Visu:SBNumberOfLabels");
529   myNumberOfLabels = (aLabels.isEmpty())? 5 : aLabels.toInt();
530   if (myNumberOfLabels > 65) 
531     myNumberOfLabels = 65;
532   
533   // Scalar Range
534   QString aFixRange = QAD_CONFIG->getSetting("Visu:SBImposeRange");
535   myIsFixedRange = (aFixRange.compare("true") == 0);
536   
537   QString aRangeMin = QAD_CONFIG->getSetting("Visu:SBMinimumValue");
538   myScalarRange[0] = (aRangeMin.isEmpty())? 0 : aRangeMin.toFloat();
539   
540   QString aRangeMax = QAD_CONFIG->getSetting("Visu:SBMaximumValue");
541   myScalarRange[1] = (aRangeMax.isEmpty())? 0 : aRangeMax.toFloat();
542
543   QString aScaling = QAD_CONFIG->getSetting("Visu:SBScaling");
544   if(aScaling.compare("LOGARITHMIC") == 0) 
545     myScaling = VISU::LOGARITHMIC;
546   else 
547     myScaling = VISU::LINEAR;
548
549 //    myName = GenerateName();
550   myMeshName = theMeshName;
551   myEntity = theEntity;
552   myFieldName =theFieldName;
553   myScalarMode = 0;
554   myIteration = theIteration;
555   return Build(false);
556 }
557
558
559
560 VISU::Storable* VISU::ScalarMap_i::Restore(const Storable::TRestoringMap& theMap, int theBuilding)
561      throw(std::logic_error&)
562 {
563   Prs3d_i::Restore(theMap,false);
564
565   myMeshName = VISU::Storable::FindValue(theMap,"myMeshName");
566   myEntity = VISU::Storable::FindValue(theMap,"myEntity").toInt();
567   myFieldName = VISU::Storable::FindValue(theMap,"myFieldName");
568   myIteration = VISU::Storable::FindValue(theMap,"myIteration").toInt();
569
570   myScalarMode = VISU::Storable::FindValue(theMap,"myScalarMode").toInt();
571   myScalarRange[0] = VISU::Storable::FindValue(theMap,"myScalarRange[0]").toDouble();
572   myScalarRange[1] = VISU::Storable::FindValue(theMap,"myScalarRange[1]").toDouble();
573   myIsFixedRange = VISU::Storable::FindValue(theMap,"myIsFixedRange").toInt();
574   myScaling = (VISU::Scaling)VISU::Storable::FindValue(theMap,"myScaling").toInt();
575
576   myTitle = VISU::Storable::FindValue(theMap,"myTitle");
577   myOrientation = (VISU::ScalarMap::Orientation)VISU::Storable::FindValue(theMap,"myOrientation").toInt();
578   myNumberOfColors = VISU::Storable::FindValue(theMap,"myNumberOfColors").toInt();
579   myNumberOfLabels = VISU::Storable::FindValue(theMap,"myNumberOfLabels").toInt();
580   myPosition[0] = VISU::Storable::FindValue(theMap,"myPosition[0]").toDouble();
581   myPosition[1] = VISU::Storable::FindValue(theMap,"myPosition[1]").toDouble();
582   myWidth = VISU::Storable::FindValue(theMap,"myWidth").toDouble();
583   myHeight = VISU::Storable::FindValue(theMap,"myHeight").toDouble();
584
585   if(theBuilding)
586     return Build(true);
587   return NULL;
588 }
589
590 void VISU::ScalarMap_i::ToStream(ostrstream& theStr){
591   Prs3d_i::ToStream(theStr);
592
593   Storable::DataToStream( theStr, "myMeshName",       myMeshName.c_str() );
594   Storable::DataToStream( theStr, "myEntity",         myEntity );
595   Storable::DataToStream( theStr, "myFieldName",      myFieldName.c_str() );
596   Storable::DataToStream( theStr, "myIteration",      myIteration );
597
598   Storable::DataToStream( theStr, "myScalarMode",     myScalarMode );
599   Storable::DataToStream( theStr, "myScalarRange[0]", myScalarRange[0] );
600   Storable::DataToStream( theStr, "myScalarRange[1]", myScalarRange[1] );
601   Storable::DataToStream( theStr, "myIsFixedRange",   myIsFixedRange );
602   Storable::DataToStream( theStr, "myScaling",        myScaling );
603
604   Storable::DataToStream( theStr, "myTitle",          myTitle.c_str() );
605   Storable::DataToStream( theStr, "myOrientation",    myOrientation );
606   Storable::DataToStream( theStr, "myNumberOfColors", myNumberOfColors );
607   Storable::DataToStream( theStr, "myNumberOfLabels", myNumberOfLabels );
608   Storable::DataToStream( theStr, "myPosition[0]",    myPosition[0] );
609   Storable::DataToStream( theStr, "myPosition[1]",    myPosition[1] );
610   Storable::DataToStream( theStr, "myWidth",          myWidth );
611   Storable::DataToStream( theStr, "myHeight",         myHeight );
612 }
613
614 void VISU::ScalarMap_i::SetScaling(VISU::Scaling theScaling){
615   VISU_FieldTransform::TTransformFun aFun;
616   if(MYDEBUG)  MESSAGE("ScalarMap_i::SetScaling - theScaling = "<<theScaling);
617   switch(theScaling){
618   case VISU::LOGARITHMIC : 
619     aFun = &Logarithmic10;  
620     break;
621   default:  
622     aFun = &Identical;
623   }
624   myScaling = theScaling;
625   myFieldTransform->SetTransformFunction(aFun);
626   if(MYDEBUGWITHFILES)
627     WriteToFile(myFieldTransform->GetUnstructuredGridOutput(),(string("/tmp/")+getenv("USER")+"-PrsScaling").c_str());
628 }
629
630 VISU::Scaling VISU::ScalarMap_i::GetScaling(){
631   return myScaling;
632 }
633
634
635 void VISU::ScalarMap_i::SetRange(CORBA::Double theMin, CORBA::Double theMax) { 
636   myScalarRange[0] = theMin; 
637   myScalarRange[1] = theMax; 
638   myIsFixedRange = true;
639   if(MYDEBUG) 
640     MESSAGE("ScalarMap_i::SetRange - myScalarRange[0] = "<<myScalarRange[0]<<
641             "; myScalarRange[1] = "<<myScalarRange[1]);
642 }
643  
644    
645 void VISU::ScalarMap_i::CalculateRange() {
646   myIsFixedRange = false;
647   myInput->GetUnstructuredGridOutput()->GetScalarRange(myScalarRange);
648   if(MYDEBUG) 
649     MESSAGE("ScalarMap_i::CalculateRange - myScalarRange[0] = "<<myScalarRange[0]<<
650             "; myScalarRange[1] = "<<myScalarRange[1]);
651 }
652
653 void VISU::ScalarMap_i::SetScalarMode(CORBA::Long theScalarMode){
654   myScalarMode = theScalarMode;
655   vtkUnstructuredGridReader* aReader = 
656     myResult->GetInput()->GetFieldOnMesh(myMeshName,(VISU::TEntity)myEntity,myFieldName,myIteration);
657   if(aReader != NULL) {
658     string aFieldName = VISU_Convertor::GenerateName(myFieldName,(int)myIteration);
659     myInput->Extract(aReader,aFieldName,myScalarMode,myField->myNbComp,myField->myEntity);
660   }
661 }
662
663 VISU::Storable* VISU::ScalarMapRestore(SALOMEDS::SObject_ptr theSObject, 
664                                        const string& thePrefix, const Storable::TRestoringMap& theMap)
665      throw(std::logic_error&)
666 {
667   VISU::Result_i* pResult = GetResult(theSObject);
668   if(pResult != NULL){
669     VISU::ScalarMap_i* pResent = new VISU::ScalarMap_i(pResult);
670     return pResent->Restore(theMap);
671   }
672   return NULL;
673 }
674
675
676 VISU::ScalarMap_i::~ScalarMap_i(){
677   if(MYDEBUG) MESSAGE("ScalarMap_i::~ScalarMap_i()");
678   myInput->Delete();
679   myFieldTransform->Delete();
680 }
681
682
683 VISU::Storable* VISU::ScalarMap_i::Build(int theRestoring){
684   if(MYDEBUG) 
685     MESSAGE("ScalarMap_i::Build - "<<myFieldName<<"; theRestoring = "<<theRestoring);
686   try{
687 #ifdef CHECKTIME
688     OSD_Timer timer;
689     timer.Start();
690 #endif
691     myField = myResult->GetInput()->GetField(myMeshName,(VISU::TEntity)myEntity,myFieldName);
692     if(myField == NULL) throw std::runtime_error("There is no Field with the parameters !!!");
693     SetScalarMode(myScalarMode);
694     if(myInput->GetInput() == NULL) throw std::runtime_error("Can't build build vtk representation !!!");
695     vtkUnstructuredGrid *aDataSet = myInput->GetUnstructuredGridOutput();
696     myFieldTransform->SetInput(aDataSet);
697     SetScaling(myScaling);
698     aDataSet->GetBounds(myBounds);
699     if(!theRestoring){
700       if (!myIsFixedRange) aDataSet->GetScalarRange(myScalarRange);
701       myName = "NoName";
702       CORBA::String_var anIOR = GetID();
703       const VISU::TField::TValField& aValField = myField->myValField;
704       const VISU::TField::TValForTime& aValForTime = aValField.find((int)myIteration)->second;
705       const VISU::TField::TTime& aTime = aValForTime.myTime;
706       QString aComment;
707       aComment.sprintf("%s, %g",myFieldName.c_str(),aTime.first);
708       myTitle = aComment.simplifyWhiteSpace();
709       if (myAddToStudy) {
710         myName = GenerateName();
711         aComment.sprintf("myComment=TIMESTAMP;myType=%d;myResultName=%s;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d",
712                          VISU::TTIMESTAMP,myResult->GetName(),myMeshName.c_str(),myEntity,myFieldName.c_str(),(int)myIteration,myField->myNbComp);
713         string aResultEntry = myResult->GetEntry();
714         string aRefFatherEntry = myResult->GetRefFatherEntry();
715         string anEntry = FindEntryWithComment(myStudy,aResultEntry.c_str(),aComment.latin1());
716         if(anEntry == "") throw std::runtime_error("There is no Entry for binding the presentation !!!");
717         aComment.sprintf("myComment=%s;myResultName=%s;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d;myComponentId=%d",
718                          GetComment(),myResult->GetName(),myMeshName.c_str(),myEntity,myFieldName.c_str(),(int)myIteration,myField->myNbComp,myScalarMode);
719         CreateAttributes(myStudy,anEntry.c_str(),aRefFatherEntry.c_str(),
720                          anIOR,myName.c_str(),"",aComment.latin1(),true);
721       }
722     }
723     if(MYDEBUG) 
724       MESSAGE("ScalarMap_i::Build - myFieldName = "<<myFieldName<<"; myName = "<<myName<<
725               "; myScalarRange[0] = "<<myScalarRange[0]<<"; myScalarRange[1] = "<<myScalarRange[1]<<
726               "; myNumberOfColors = "<<myNumberOfColors);
727     
728     myMapper->SetInput(DoHook(theRestoring));
729     myMapper->ScalarVisibilityOn();
730 #ifdef CHECKTIME
731     timer.Stop();
732     timer.Show();
733 #endif
734     return this;
735   }catch(std::runtime_error& exc){
736     MESSAGE("Follow exception was accured :\n"<<exc.what());
737   }catch(...){
738     MESSAGE("Unknown exception was accured!");
739   }
740   return NULL;
741 }
742
743
744 VISU::ScalarMap_i::DataType* VISU::ScalarMap_i::DoHook(int theRestoring){
745   myMapper->ScalarVisibilityOn();
746   return myFieldTransform->GetUnstructuredGridOutput();
747 }
748
749
750
751 VISU_Actor* VISU::ScalarMap_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) {
752   Update();
753   VISU_LookupTable* aActorLookupTbl = VISU_LookupTable::New();
754   if(GetScaling() == VISU::LOGARITHMIC) 
755     aActorLookupTbl->SetLog(true);
756   aActorLookupTbl->SetHueRange(0.667,0.0);
757   aActorLookupTbl->SetNumberOfColors(myNumberOfColors);
758   aActorLookupTbl->SetRange(myScalarRange);
759   aActorLookupTbl->SetMapScale(1.);
760   aActorLookupTbl->Build();
761   myMapper->SetLookupTable(aActorLookupTbl);   
762 //  if(GetScaling() == VISU::ScalarMap::LOGARITHMIC){
763 //    float* aLogScalarRange = aActorLookupTbl->GetLogRange();
764 //    myMapper->SetScalarRange(aLogScalarRange);
765 //  }else
766     myMapper->SetScalarRange(myScalarRange);
767   aActorLookupTbl->Delete();
768
769   VISU_Actor* aActor = VISU::Prs3d_i::CreateActor(theIO);
770   if ( !aActor ) return NULL;
771
772   VISU_ScalarBarActor* aBar = VISU_ScalarBarActor::New();
773   VISU_LookupTable* aBarLookupTbl = VISU_LookupTable::New();
774   if(GetScaling() == VISU::LOGARITHMIC) 
775     aBarLookupTbl->SetLog(true);
776   aBarLookupTbl->SetHueRange(0.667,0.0);
777   aBarLookupTbl->SetNumberOfColors(myNumberOfColors);
778   aBarLookupTbl->SetRange(myScalarRange);
779   aBarLookupTbl->Build();
780   aBar->SetLookupTable(aBarLookupTbl);
781   aBarLookupTbl->Delete();
782
783   aBar->SetTitle(myTitle.c_str());
784   aBar->SetOrientation(myOrientation);
785   aBar->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
786   aBar->GetPositionCoordinate()->SetValue(myPosition[0],
787                                           myPosition[1]);
788   aBar->SetWidth(myWidth);
789   aBar->SetHeight(myHeight);
790   aBar->SetNumberOfLabels(myNumberOfLabels);
791   aActor->setScalarBar(aBar);
792
793   aActor->VisuActorType = VisuActorType_ScalarMap;
794   strncpy(aActor->FieldName, myFieldName.c_str(), 40);
795   aActor->FieldName[39] = '\0';
796
797   vtkProperty* aProperty = aActor->GetProperty();
798 //  aProperty->SetSpecularColor( 1, 1, 1);
799 //  aProperty->SetSpecular( 0.3 );
800 //  aProperty->SetSpecularPower( 20 );
801 //  aProperty->SetAmbient( 0.2);
802 //  aProperty->SetDiffuse( 0.8 );
803   aProperty->EdgeVisibilityOn();     
804   return aActor;
805 }
806
807
808 //==============================================================================
809 int VISU::DeformedShape_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, 
810                                       const char* theFieldName, double theIteration){
811   if(!VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration)) return 0;
812   const VISU::TField* aField = theResult->GetInput()->GetField(theMeshName,(VISU::TEntity)theEntity,theFieldName);
813   return aField->myNbComp > 1;
814 }
815
816 int VISU::DeformedShape_i::myNbPresent = 0;
817 QString VISU::DeformedShape_i::GenerateName() { return VISU::GenerateName("Def.Shape",myNbPresent++);}
818
819 const string VISU::DeformedShape_i::myComment = "DEFORMEDSHAPE";
820 const char* VISU::DeformedShape_i::GetComment() const { return myComment.c_str();}
821
822 VISU::DeformedShape_i::DeformedShape_i(Result_i* theResult, bool theAddToStudy) : 
823        PrsObject_i(theResult->GetStudyDocument()), 
824        Prs3d_i(theResult),       
825        ScalarMap_i(theResult, theAddToStudy)
826 {
827   if(MYDEBUG) MESSAGE("DeformedShape_i::DeformedShape_i");
828   myWarpVector = vtkWarpVector::New();
829 }
830
831
832 void VISU::DeformedShape_i::SameAs(const DeformedShape_i* theOrigin)
833 {
834   DeformedShape_i* aDefShape = (DeformedShape_i*) theOrigin;
835   setColored(aDefShape->isColored());
836   VISU::ScalarMap_i::SameAs(theOrigin);
837   SetScale(aDefShape->GetScale());
838 }
839
840
841 VISU::Storable* VISU::DeformedShape_i::Create(const char* theMeshName, VISU::Entity theEntity, 
842                                               const char* theFieldName, double theIteration){
843   myIsColored = false;
844   return ScalarMap_i::Create(theMeshName,theEntity,theFieldName,theIteration);
845 }
846
847 VISU::Storable* VISU::DeformedShape_i::Restore(const Storable::TRestoringMap& theMap, int theBuilding)
848      throw(std::logic_error&)
849 {
850   ScalarMap_i::Restore(theMap,false);
851
852   myFactor = VISU::Storable::FindValue(theMap,"myFactor").toDouble();
853   myIsColored = VISU::Storable::FindValue(theMap,"myIsColored").toInt();
854
855   if(theBuilding)
856     return Build(true);
857   return NULL;
858 }
859
860 void VISU::DeformedShape_i::ToStream(ostrstream& theStr){
861   ScalarMap_i::ToStream(theStr);
862
863   Storable::DataToStream( theStr, "myFactor", myFactor );
864   Storable::DataToStream( theStr, "myIsColored", myIsColored );
865 }
866
867 VISU::Storable* VISU::DeformedShapeRestore(SALOMEDS::SObject_ptr theSObject, 
868                                            const string& thePrefix, const Storable::TRestoringMap& theMap)
869      throw(std::logic_error&)
870 {
871   VISU::Result_i* pResult = GetResult(theSObject);
872   if(pResult != NULL){
873     VISU::DeformedShape_i* pResent = new VISU::DeformedShape_i(pResult);
874     return pResent->Restore(theMap);
875   }
876   return NULL;
877 }
878
879
880 VISU::DeformedShape_i::~DeformedShape_i(){
881   if(MYDEBUG) MESSAGE("DeformedShape_i::~DeformedShape_i()");
882   myWarpVector->Delete();
883 }
884
885
886 VISU::ScalarMap_i::DataType* VISU::DeformedShape_i::DoHook(int theRestoring){
887   if(!theRestoring)
888     myFactor = ScaleFactor();
889   if(MYDEBUG) 
890     MESSAGE("DeformedShape_i::DoHook() - myFactor = "<<myFactor);
891   if(myField->myNbComp > 1){
892     if(myField->myEntity == VISU::CELL_ENTITY){
893       vtkCellDataToPointData *aFilter = vtkCellDataToPointData::New();
894       aFilter->SetInput(myFieldTransform->GetUnstructuredGridOutput());
895       aFilter->PassCellDataOn();
896       myWarpVector->SetInput(aFilter->GetUnstructuredGridOutput());
897       aFilter->Delete();
898     }else
899       myWarpVector->SetInput(myFieldTransform->GetUnstructuredGridOutput());
900
901     if(GetScaling() == VISU::LOGARITHMIC) 
902       myWarpVector->SetScaleFactor(log10(myFactor));
903     else
904       myWarpVector->SetScaleFactor(myFactor);
905     if(myIsColored)
906       myMapper->ScalarVisibilityOn();
907   }
908   return myWarpVector->GetOutput();
909 }
910
911
912 float VISU::DeformedShape_i::ScaleFactor() { 
913   vtkUnstructuredGrid *aDataSet = myInput->GetUnstructuredGridOutput();
914   int nbCells = aDataSet->GetNumberOfCells(), nbPoints = aDataSet->GetNumberOfPoints();
915   return ::CalcScaleFactor(myBounds, nbCells? nbCells: nbPoints);
916 }
917
918 void VISU::DeformedShape_i::Update(){
919   myWarpVector->SetScaleFactor(myFactor);
920   myMapper->Update();
921 }
922
923 VISU_Actor* VISU::DeformedShape_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) {
924   VISU_Actor* aActor = VISU::ScalarMap_i::CreateActor(theIO);
925   if ( ! aActor ) return NULL;
926   if (myIsColored) {
927     myMapper->ScalarVisibilityOn();
928   } else {
929     myMapper->ScalarVisibilityOff();
930     aActor->setScalarBar(NULL);
931   }
932   aActor->VisuActorType = VisuActorType_DeformedShape;
933   aActor->GetProperty()->SetRepresentation(1);
934   return aActor;
935 }
936
937
938 //==============================================================================
939 int VISU::CutPlanes_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, 
940                                   const char* theFieldName, double theIteration){
941   return VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration);
942 }
943
944 int VISU::CutPlanes_i::myNbPresent = 0;
945 QString VISU::CutPlanes_i::GenerateName() { return VISU::GenerateName("CutPlanes",myNbPresent++);}
946
947 const string VISU::CutPlanes_i::myComment = "CUTPLANES";
948 const char* VISU::CutPlanes_i::GetComment() const { return myComment.c_str();}
949
950 VISU::CutPlanes_i::CutPlanes_i(Result_i* theResult, bool theAddToStudy) :
951        PrsObject_i(theResult->GetStudyDocument()), 
952        Prs3d_i(theResult),       
953        ScalarMap_i(theResult, theAddToStudy)
954 {
955   if(MYDEBUG) MESSAGE("CutPlanes_i::CutPlanes_i");
956   myAppendPolyData = vtkAppendPolyData::New();
957 }
958
959 void VISU::CutPlanes_i::SameAs(const CutPlanes_i* theOrigin)
960 {
961   CutPlanes_i* aCutPlanes = (CutPlanes_i*) theOrigin;
962   SetNbPlanes(aCutPlanes->GetNbPlanes());
963   SetOrientationType(aCutPlanes->GetOrientationType());
964   SetRotateX(aCutPlanes->GetRotateX());
965   SetRotateY(aCutPlanes->GetRotateY());
966   Update();
967   VISU::ScalarMap_i::SameAs(theOrigin);
968 }
969
970 VISU::Storable* VISU::CutPlanes_i::Create(const char* theMeshName, VISU::Entity theEntity, 
971                                           const char* theFieldName, double theIteration){
972   return ScalarMap_i::Create(theMeshName,theEntity,theFieldName,theIteration);
973 }
974
975 VISU::Storable* VISU::CutPlanes_i::Restore(const Storable::TRestoringMap& theMap, int theBuilding)
976      throw(std::logic_error&)
977 {
978   ScalarMap_i::Restore(theMap,false);
979
980   myNbPlanes = VISU::Storable::FindValue(theMap,"myNbPlanes").toInt();
981   myBasePlane = (VISU::CutPlanes::Orientation)VISU::Storable::FindValue(theMap,"myBasePlane").toInt();
982   SetOrientationType(myBasePlane);
983   float aRot[2];
984   aRot[0] = VISU::Storable::FindValue(theMap,"aRot[0]").toDouble();
985   SetRotateX(aRot[0]);
986   aRot[1] = VISU::Storable::FindValue(theMap,"aRot[1]").toDouble();
987   SetRotateY(aRot[1]);
988
989   if(theBuilding)
990     return Build(true);
991   return NULL;
992 }
993
994 void VISU::CutPlanes_i::ToStream(ostrstream& theStr){
995   ScalarMap_i::ToStream(theStr);
996
997   Storable::DataToStream( theStr, "myNbPlanes",  myNbPlanes );
998   Storable::DataToStream( theStr, "myBasePlane", myBasePlane );
999   Storable::DataToStream( theStr, "aRot[0]",     GetRotateX() );
1000   Storable::DataToStream( theStr, "aRot[1]",     GetRotateY() );
1001 }
1002
1003 VISU::Storable* VISU::CutPlanesRestore(SALOMEDS::SObject_ptr theSObject, 
1004                                        const string& thePrefix, const Storable::TRestoringMap& theMap)
1005      throw(std::logic_error&)
1006 {
1007   VISU::Result_i* pResult = GetResult(theSObject);
1008   if(pResult != NULL){
1009     VISU::CutPlanes_i* pResent = new VISU::CutPlanes_i(pResult);
1010     return pResent->Restore(theMap);
1011   }
1012   return NULL;
1013 }
1014
1015
1016 VISU::CutPlanes_i::~CutPlanes_i(){
1017   if(MYDEBUG) MESSAGE("CutPlanes_i::~CutPlanes_i()");
1018   myAppendPolyData->Delete();
1019 }
1020
1021 VISU_Actor* VISU::CutPlanes_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) {
1022   VISU_Actor* aActor = VISU::ScalarMap_i::CreateActor(theIO);
1023   if (! aActor ) return NULL;
1024   aActor->VisuActorType = VisuActorType_CutPlanes;
1025   return aActor;
1026 }
1027
1028
1029
1030 float* GetIdent(float theR[3][3]){
1031   for(int i = 0; i < 3; i++)
1032     for(int j = 0; j < 3; j++)
1033       theR[i][j] = (i==j? 1.0: 0.0);
1034   return theR[0];
1035 }
1036
1037
1038 float* GetRx(float theRx[3][3], float thaAng){
1039   theRx[0][0] = 1.0;            theRx[0][1] = 0.0;            theRx[0][2] = 0.0;
1040   theRx[1][0] = 0.0;            theRx[1][1] = cos(thaAng);    theRx[1][2] = -sin(thaAng);
1041   theRx[2][0] = 0.0;            theRx[2][1] = sin(thaAng);    theRx[2][2] = cos(thaAng);
1042   return theRx[0];
1043 }
1044
1045
1046 float* GetRy(float theRy[3][3], float thaAng){
1047   theRy[0][0] = cos(thaAng);    theRy[0][1] = 0.0;            theRy[0][2] = sin(thaAng);
1048   theRy[1][0] = 0.0;            theRy[1][1] = 1.0;            theRy[1][2] = 0.0;   
1049   theRy[2][0] = -sin(thaAng);   theRy[2][1] = 0.0;            theRy[2][2] = cos(thaAng);   
1050   return theRy[0];
1051 }
1052
1053
1054 float* GetRz(float theRz[3][3], float thaAng){
1055   theRz[0][0] = cos(thaAng);    theRz[0][1] = -sin(thaAng);   theRz[0][2] = 0.0;
1056   theRz[1][0] = sin(thaAng);    theRz[1][1] = cos(thaAng);    theRz[1][2] = 0.0;   
1057   theRz[2][0] = 0.0;            theRz[2][1] = 0.0;            theRz[2][2] = 1.0;   
1058   return theRz[0];
1059 }
1060
1061
1062 void MulMatrix(float C[3][3], const float A[3][3], const float B[3][3]){ // C = A*B;
1063   for(int i = 0; i < 3; i++)
1064     for(int j = 0; j < 3; j++){
1065       C[i][j] = 0.0;
1066       for(int k = 0; k < 3; k++)
1067         C[i][j] += A[i][k]*B[k][j];
1068     }
1069 }
1070
1071
1072 float DotMul(const float A[3], const float B[3]){ // A*B;
1073   float C = 0.0;
1074   for(int i = 0; i < 3; i++)  C += A[i]*B[i];
1075   return C;
1076 }
1077
1078
1079 void Mul(float C[3], const float A[3], float B){ // A*B;
1080   for(int i = 0; i < 3; i++)  C[i] = A[i]*B;
1081 }
1082
1083
1084 void GetBoundProject(float BoundPrj[3], const float BoundBox[6], const float Dir[3]){
1085   float BoundPoints[8][3] = { {BoundBox[0],BoundBox[2],BoundBox[4]},
1086                               {BoundBox[1],BoundBox[2],BoundBox[4]},
1087                               {BoundBox[0],BoundBox[3],BoundBox[4]},
1088                               {BoundBox[1],BoundBox[3],BoundBox[4]},
1089                               {BoundBox[0],BoundBox[2],BoundBox[5]},
1090                               {BoundBox[1],BoundBox[2],BoundBox[5]}, 
1091                               {BoundBox[0],BoundBox[3],BoundBox[5]}, 
1092                               {BoundBox[1],BoundBox[3],BoundBox[5]}};
1093   BoundPrj[0] = DotMul(Dir,BoundPoints[0]), BoundPrj[1] = BoundPrj[0];
1094   float tmp;
1095   for(int i = 1; i < 8; i++){
1096     tmp = DotMul(Dir,BoundPoints[i]);
1097     if(BoundPrj[1] < tmp) BoundPrj[1] = tmp;
1098     if(BoundPrj[0] > tmp) BoundPrj[0] = tmp;
1099   }
1100   BoundPrj[2] = BoundPrj[1] - BoundPrj[0];
1101   BoundPrj[1] = BoundPrj[0] + (1.0 - EPS)*BoundPrj[2];
1102   BoundPrj[0] = BoundPrj[0] + EPS*BoundPrj[2];
1103   BoundPrj[2] = BoundPrj[1] - BoundPrj[0];
1104 }
1105
1106 void VISU::CutPlanes_i::SetRotateX(CORBA::Double theAng){
1107   if(myBasePlane == VISU::CutPlanes::XY)
1108     myAng[0] = theAng;   
1109   else if(myBasePlane == VISU::CutPlanes::YZ)
1110     myAng[1] = theAng; 
1111   else if(myBasePlane == VISU::CutPlanes::ZX)
1112     myAng[2] = theAng;
1113 }
1114
1115 CORBA::Double VISU::CutPlanes_i::GetRotateX(){
1116   if(myBasePlane == VISU::CutPlanes::XY)
1117     return myAng[0];   
1118   else if(myBasePlane == VISU::CutPlanes::YZ)
1119     return myAng[1]; 
1120   else if(myBasePlane == VISU::CutPlanes::ZX)
1121     return myAng[2];
1122 }
1123
1124 void VISU::CutPlanes_i::SetRotateY(CORBA::Double theAng){
1125   if(myBasePlane == VISU::CutPlanes::XY)
1126     myAng[1] = theAng;   
1127   else if(myBasePlane == VISU::CutPlanes::YZ)
1128     myAng[2] = theAng; 
1129   else if(myBasePlane == VISU::CutPlanes::ZX)
1130     myAng[0] = theAng;
1131 }
1132
1133 CORBA::Double VISU::CutPlanes_i::GetRotateY(){
1134   if(myBasePlane == VISU::CutPlanes::XY)
1135     return myAng[1];   
1136   else if(myBasePlane == VISU::CutPlanes::YZ)
1137     return myAng[2]; 
1138   else if(myBasePlane == VISU::CutPlanes::ZX)
1139     return myAng[0];
1140 }
1141
1142 VISU::ScalarMap_i::DataType* VISU::CutPlanes_i::DoHook(int theRestoring){
1143   if(!theRestoring){
1144     myAng[0] = myAng[1] = myAng[2] = 0.0;
1145     myNbPlanes = 10;
1146     myBasePlane = VISU::CutPlanes::XY;
1147   }
1148   if(MYDEBUG) 
1149     MESSAGE("CutPlanes_i::DoHook() - myNbPlanes = "<<myNbPlanes<<"; myBasePlane = "<<myBasePlane<<
1150             "; myAng[0] = "<<myAng[0]<<"; myAng[1] = "<<myAng[1]<<"; myAng[2] = "<<myAng[2]);
1151   Update();
1152   myMapper->ScalarVisibilityOn();
1153   return myAppendPolyData->GetOutput();
1154 }
1155
1156
1157 void VISU::CutPlanes_i::SetPlane(int theId){
1158   vtkCutter *aCutPlane = vtkCutter::New();
1159   aCutPlane->SetInput(myFieldTransform->GetUnstructuredGridOutput());
1160   vtkPlane *aPlane = vtkPlane::New();
1161   float aOrig[3];
1162   Mul(aOrig,myDir,myBoundPrj[0] + theId*myDBPrj);
1163   if(MYDEBUG) MESSAGE("aOrig["<<theId<<"]: "<<aOrig[0]<<"; "<<aOrig[1]<<"; "<<aOrig[2]);
1164   aPlane->SetOrigin(aOrig);
1165   if(theId == 0) aPlane->SetNormal(myInvDir);
1166   else  aPlane->SetNormal(myDir);
1167   aCutPlane->SetCutFunction(aPlane);
1168   aPlane->Delete();
1169   myAppendPolyData->AddInput(aCutPlane->GetOutput());
1170   aCutPlane->Delete();
1171 }
1172
1173
1174 void VISU::CutPlanes_i::Update(){
1175   int iEnd = myAppendPolyData->GetNumberOfInputs();
1176   if(MYDEBUG) MESSAGE("CutPlanes_i::Update - iEnd = "<<iEnd);
1177   for(int i = iEnd-1; i >= 0; i--)
1178     myAppendPolyData->RemoveInput(myAppendPolyData->GetInput(i));
1179  
1180   float aRx[3][3], aRy[3][3], aRz[3][3];
1181   int iPlane = 0;
1182   if(myBasePlane == VISU::CutPlanes::XY){ // X-Y
1183     if(fabs(myAng[0]) > EPS) ::GetRx(aRx,myAng[0]); else ::GetIdent(aRx);
1184     if(fabs(myAng[1]) > EPS) ::GetRy(aRy,myAng[1]); else ::GetIdent(aRy);
1185     ::MulMatrix(myRotation,aRx,aRy);
1186     iPlane = 2;
1187   }else if(myBasePlane == VISU::CutPlanes::YZ){ // Y-Z
1188     if(fabs(myAng[1]) > EPS) ::GetRy(aRy,myAng[1]); else ::GetIdent(aRy);
1189     if(fabs(myAng[2]) > EPS) ::GetRz(aRz,myAng[2]); else ::GetIdent(aRz);
1190     ::MulMatrix(myRotation,aRy,aRz);
1191      iPlane = 0;
1192   }else if(myBasePlane == VISU::CutPlanes::ZX){ // Z-X
1193     if(fabs(myAng[2]) > EPS) ::GetRz(aRz,myAng[2]); else ::GetIdent(aRz);
1194     if(fabs(myAng[0]) > EPS) ::GetRx(aRx,myAng[0]); else ::GetIdent(aRx);
1195     ::MulMatrix(myRotation,aRz,aRx);
1196     iPlane = 1;
1197   }
1198   for(int i = 0; i < 3; i++)  myDir[i] = myRotation[i][iPlane];
1199   ::Mul(myInvDir,myDir,-1.0);
1200   ::GetBoundProject(myBoundPrj, myBounds, myDir);
1201   if(MYDEBUG) MESSAGE("myDir "<<myDir[0]<<"; "<<myDir[1]<<"; "<<myDir[2]);
1202   int aNbPlanes = GetNbPlanes();
1203   SCRUTE(aNbPlanes);
1204   if (aNbPlanes > 1 ) {
1205     myDBPrj = myBoundPrj[2]/(aNbPlanes - 1);
1206     for (int i = 0; i < aNbPlanes; i++){
1207       SetPlane(i);
1208     }
1209   }
1210    else { 
1211      myDBPrj = 0.5*myBoundPrj[2];
1212      SetPlane(1);
1213    }
1214 }
1215
1216
1217 //==============================================================================
1218 int VISU::IsoSurfaces_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, 
1219                                     const char* theFieldName, double theIteration){
1220   return VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration);
1221 }
1222
1223 int VISU::IsoSurfaces_i::myNbPresent = 0;
1224 QString VISU::IsoSurfaces_i::GenerateName() { return VISU::GenerateName("IsoSurfaces",myNbPresent++);}
1225
1226 const string VISU::IsoSurfaces_i::myComment = "ISOSURFACES";
1227 const char* VISU::IsoSurfaces_i::GetComment() const { return myComment.c_str();}
1228
1229 VISU::IsoSurfaces_i::IsoSurfaces_i(Result_i* theResult, bool theAddToStudy) :
1230        PrsObject_i(theResult->GetStudyDocument()), 
1231        Prs3d_i(theResult),       
1232        ScalarMap_i(theResult, theAddToStudy)
1233 {
1234   if(MYDEBUG) MESSAGE("IsoSurfaces_i::IsoSurfaces_i");
1235   myContourFilter = vtkContourFilter::New();
1236 }
1237
1238 void VISU::IsoSurfaces_i::SameAs(const IsoSurfaces_i* theOrigin) {
1239   IsoSurfaces_i* aIsoSurfaces = (IsoSurfaces_i*) theOrigin;
1240   SetNbSurfaces(aIsoSurfaces->GetNbSurfaces());
1241   SetRange(aIsoSurfaces->GetRangeMin(), aIsoSurfaces->GetRangeMax());
1242   VISU::ScalarMap_i::SameAs(theOrigin);
1243 }
1244
1245 VISU::Storable* VISU::IsoSurfaces_i::Create(const char* theMeshName, VISU::Entity theEntity, 
1246                                             const char* theFieldName, double theIteration){
1247   myNbSurface = 10;
1248   myRange[0] = 0;
1249   myRange[1] = 0;
1250   return ScalarMap_i::Create(theMeshName,theEntity,theFieldName,theIteration);
1251 }
1252
1253 VISU::Storable* VISU::IsoSurfaces_i::Restore(const Storable::TRestoringMap& theMap, int theBuilding)
1254      throw(std::logic_error&)
1255 {
1256   ScalarMap_i::Restore(theMap,false);
1257
1258   myNbSurface = VISU::Storable::FindValue(theMap,"myNbSurface").toInt();
1259   myRange[0] = VISU::Storable::FindValue(theMap,"myRange[0]").toDouble();
1260   myRange[1] = VISU::Storable::FindValue(theMap,"myRange[1]").toDouble();
1261
1262   if(theBuilding)
1263     return Build(true);
1264   return NULL;
1265 }
1266
1267 void VISU::IsoSurfaces_i::ToStream(ostrstream& theStr){
1268   ScalarMap_i::ToStream(theStr);
1269
1270   Storable::DataToStream( theStr, "myNbSurface", myNbSurface );
1271   Storable::DataToStream( theStr, "myRange[0]", myRange[0] );
1272   Storable::DataToStream( theStr, "myRange[1]", myRange[1] );
1273 }
1274
1275 VISU::Storable* VISU::IsoSurfacesRestore(SALOMEDS::SObject_ptr theSObject, 
1276                                          const string& thePrefix, const Storable::TRestoringMap& theMap)
1277      throw(std::logic_error&)
1278 {
1279   VISU::Result_i* pResult = GetResult(theSObject);
1280   if(pResult != NULL){
1281     VISU::IsoSurfaces_i* pResent = new VISU::IsoSurfaces_i(pResult);
1282     return pResent->Restore(theMap);
1283   }
1284   return NULL;
1285 }
1286
1287
1288 VISU::IsoSurfaces_i::~IsoSurfaces_i(){
1289   if(MYDEBUG) MESSAGE("IsoSurfaces_i::~IsoSurfaces_i()");
1290   myContourFilter->Delete();
1291 }
1292
1293
1294 VISU::ScalarMap_i::DataType* VISU::IsoSurfaces_i::DoHook(int theRestoring){
1295   if(MYDEBUG) 
1296     MESSAGE("IsoSurfaces_i::DoHook() - myNbSurface = "<<myNbSurface);
1297   if(myField->myEntity == VISU::CELL_ENTITY){
1298     vtkCellDataToPointData *aFilter = vtkCellDataToPointData::New();
1299     aFilter->SetInput(myFieldTransform->GetUnstructuredGridOutput());
1300     aFilter->PassCellDataOn();
1301     myContourFilter->SetInput(aFilter->GetOutput());
1302     aFilter->Delete();
1303   } else
1304     myContourFilter->SetInput(myFieldTransform->GetUnstructuredGridOutput());
1305
1306   if ((myRange[0]==0) && (myRange[1]==0)) {
1307     myRange[0] = myScalarRange[0];
1308     myRange[1] = myScalarRange[1];
1309   }
1310   if(GetScaling() == VISU::LOGARITHMIC){ 
1311     float aLogRange[2];
1312     VISU_LookupTable::ComputeLogRange(myRange,aLogRange);
1313     if(MYDEBUG) 
1314       MESSAGE("IsoSurfaces_i::DoHook() - aLogRange = {"<<aLogRange[0]<<", "<<aLogRange[1]<<"}");
1315     myContourFilter->GenerateValues(myNbSurface, aLogRange);
1316   }else
1317     myContourFilter->GenerateValues(myNbSurface, myRange);
1318   myMapper->ScalarVisibilityOn();
1319   return myContourFilter->GetOutput();
1320 }
1321
1322
1323 void VISU::IsoSurfaces_i::Update(){
1324   if ((myRange[0]==0) && (myRange[1]==0)) {
1325     myRange[0] = myScalarRange[0];
1326     myRange[1] = myScalarRange[1];
1327   }
1328   if(GetScaling() == VISU::LOGARITHMIC){ 
1329     float aLogRange[2];
1330     VISU_LookupTable::ComputeLogRange(myRange,aLogRange);
1331     if(MYDEBUG) 
1332       MESSAGE("IsoSurfaces_i::Update() - aLogRange = {"<<aLogRange[0]<<", "<<aLogRange[1]<<"}");
1333     myContourFilter->GenerateValues(myNbSurface, aLogRange);
1334   }else
1335     myContourFilter->GenerateValues(myNbSurface, myRange);
1336   myMapper->Update();
1337 }
1338
1339
1340 VISU_Actor* VISU::IsoSurfaces_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) {
1341   VISU_Actor* aActor = VISU::ScalarMap_i::CreateActor(theIO);
1342   if ( ! aActor ) return NULL;
1343   aActor->VisuActorType = VisuActorType_IsoSurfaces;
1344   return aActor;
1345 }
1346
1347 //==============================================================================
1348 int VISU::StreamLines_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, 
1349                                     const char* theFieldName, double theIteration){
1350   return DeformedShape_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration);
1351 }
1352
1353 int VISU::StreamLines_i::myNbPresent = 0;
1354 QString VISU::StreamLines_i::GenerateName() { return VISU::GenerateName("StreamLines",myNbPresent++);}
1355
1356 const string VISU::StreamLines_i::myComment = "STREAMLINES";
1357 const char* VISU::StreamLines_i::GetComment() const { return myComment.c_str();}
1358
1359 VISU::StreamLines_i::StreamLines_i(Result_i* theResult, bool theAddToStudy) :
1360        PrsObject_i(theResult->GetStudyDocument()), 
1361        Prs3d_i(theResult),       
1362        ScalarMap_i(theResult, theAddToStudy),
1363        DeformedShape_i(theResult, theAddToStudy)
1364 {
1365   if(MYDEBUG) MESSAGE("StreamLines_i::StreamLines_i");
1366   myStream = vtkStreamLine::New();
1367 }
1368
1369 VISU::Storable* VISU::StreamLines_i::Create(const char* theMeshName, VISU::Entity theEntity, 
1370                                             const char* theFieldName, double theIteration){
1371   myDirection = VISU::StreamLines::FORWARD;
1372   myStepLength = 0.1;
1373   myIntegrationStep = 0.1;
1374   myPropagationTime = 100;
1375   return ScalarMap_i::Create(theMeshName,theEntity,theFieldName,theIteration);
1376 }
1377
1378 void VISU::StreamLines_i::SameAs(const StreamLines_i* theOrigin) {
1379   StreamLines_i* aIsoLines = (StreamLines_i*) theOrigin;
1380   SetDirection(aIsoLines->GetDirection());
1381   SetStepLength(aIsoLines->GetStepLength());
1382   SetIntegrationStep(aIsoLines->GetIntegrationStep());
1383   SetPropagationTime(aIsoLines->GetPropagationTime());
1384   VISU::DeformedShape_i::SameAs(theOrigin);
1385 }
1386
1387 VISU::Storable* VISU::StreamLines_i::Restore(const Storable::TRestoringMap& theMap, int theBuilding)
1388      throw(std::logic_error&)
1389 {
1390   DeformedShape_i::Restore(theMap,false);
1391
1392   myStepLength = VISU::Storable::FindValue(theMap,"myStepLength").toDouble();
1393   myIntegrationStep = VISU::Storable::FindValue(theMap,"myIntegrationStep").toDouble();
1394   myPropagationTime = VISU::Storable::FindValue(theMap,"myPropagationTime").toDouble();
1395   myDirection = (VISU::StreamLines::Direction) VISU::Storable::FindValue(theMap,"myDirection").toInt();
1396
1397   if(theBuilding)
1398     return Build(true);
1399   return NULL;
1400 }
1401
1402 void VISU::StreamLines_i::ToStream(ostrstream& theStr){
1403   DeformedShape_i::ToStream(theStr);
1404
1405   Storable::DataToStream( theStr, "myStepLength", myStepLength );
1406   Storable::DataToStream( theStr, "myIntegrationStep", myIntegrationStep );
1407   Storable::DataToStream( theStr, "myPropagationTime", myPropagationTime );
1408   Storable::DataToStream( theStr, "myDirection", (int)myDirection );
1409
1410 }
1411
1412 VISU::Storable* VISU::StreamLinesRestore(SALOMEDS::SObject_ptr theSObject, 
1413                                          const string& thePrefix, const Storable::TRestoringMap& theMap)
1414      throw(std::logic_error&)
1415 {
1416   VISU::Result_i* pResult = GetResult(theSObject);
1417   if(pResult != NULL){
1418     VISU::StreamLines_i* pResent = new VISU::StreamLines_i(pResult);
1419     return pResent->Restore(theMap);
1420   }
1421   return NULL;
1422 }
1423
1424
1425 VISU::StreamLines_i::~StreamLines_i(){
1426   if(MYDEBUG) MESSAGE("StreamLines_i::~StreamLines_i()");
1427   myStream->Delete();
1428 }
1429
1430
1431 VISU::ScalarMap_i::DataType* VISU::StreamLines_i::DoHook(int theRestoring){
1432   return myStream->GetOutput();
1433 }
1434
1435
1436 void VISU::StreamLines_i::Update(){
1437   if(myField->myNbComp > 1){
1438     if(myField->myEntity == VISU::CELL_ENTITY){
1439       //myStream->DebugOn();
1440       vtkCellDataToPointData *aFilter = vtkCellDataToPointData::New();
1441       aFilter->SetInput(myFieldTransform->GetUnstructuredGridOutput());
1442       aFilter->PassCellDataOn();
1443       myStream->SetInput(aFilter->GetOutput());
1444       aFilter->Delete();
1445
1446       vtkCellCenters *centers = vtkCellCenters::New(); // for vectors on cells
1447       centers->SetInput(myFieldTransform->GetUnstructuredGridOutput());
1448       centers->VertexCellsOn();
1449       myStream->SetSource(centers->GetOutput());
1450       centers->Delete();
1451     }else{
1452       myStream->SetInput(myFieldTransform->GetUnstructuredGridOutput());
1453       myStream->SetSource(myFieldTransform->GetUnstructuredGridOutput());
1454     }
1455     myStream->SetStepLength(myStepLength);
1456     myStream->SetIntegrationStepLength(myIntegrationStep);
1457     myStream->SetMaximumPropagationTime(myPropagationTime);
1458     switch (myDirection) {
1459     case VISU::StreamLines::FORWARD:
1460       myStream->SetIntegrationDirectionToForward();
1461       break;
1462     case VISU::StreamLines::BACKWARD:
1463       myStream->SetIntegrationDirectionToBackward();
1464       break;
1465     case VISU::StreamLines::BOTH:
1466       myStream->SetIntegrationDirectionToIntegrateBothDirections();
1467     }
1468     myStream->Update();
1469     myMapper->Update();
1470   }
1471 }
1472
1473
1474 VISU_Actor* VISU::StreamLines_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) {
1475   VISU_Actor* aActor = VISU::DeformedShape_i::CreateActor(theIO);
1476   if ( ! aActor ) return NULL;
1477   aActor->VisuActorType = VisuActorType_StreamLines;
1478   return aActor;
1479 }
1480
1481 //==============================================================================
1482 int VISU::Vectors_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, 
1483                                 const char* theFieldName, double theIteration){
1484   return DeformedShape_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration);
1485 }
1486
1487 int VISU::Vectors_i::myNbPresent = 0;
1488 QString VISU::Vectors_i::GenerateName() { return VISU::GenerateName("Vectors",myNbPresent++);}
1489
1490 const string VISU::Vectors_i::myComment = "VECTORS";
1491 const char* VISU::Vectors_i::GetComment() const { return myComment.c_str();}
1492
1493 VISU::Vectors_i::Vectors_i(Result_i* theResult, bool theAddToStudy) :
1494        PrsObject_i(theResult->GetStudyDocument()), 
1495        Prs3d_i(theResult),       
1496        ScalarMap_i(theResult, theAddToStudy),
1497        DeformedShape_i(theResult, theAddToStudy)
1498 {
1499   if(MYDEBUG) MESSAGE("Vectors_i::Vectors_i");
1500   myGlyph = vtkGlyph3D::New();
1501   myHog = vtkHedgeHog::New();
1502 }
1503
1504 void VISU::Vectors_i::SameAs(const VISU::Vectors_i* theOrigin) {
1505   Vectors_i* aVectors = (Vectors_i*) theOrigin;
1506   SetLineWidth(aVectors->GetLineWidth());
1507   SetGlyphType(aVectors->GetGlyphType());
1508   SetGlyphPos(aVectors->GetGlyphPos());
1509   VISU::DeformedShape_i::SameAs(theOrigin);
1510 }
1511
1512 VISU::Storable* VISU::Vectors_i::Create(const char* theMeshName, VISU::Entity theEntity, 
1513                                         const char* theFieldName, double theIteration){
1514   myLineWidth = 1.0;
1515   myTypeGlyph = VISU::Vectors::ARROW;
1516   myPosGlyph = VISU::Vectors::CENTER;
1517   return DeformedShape_i::Create(theMeshName,theEntity,theFieldName,theIteration);
1518 }
1519
1520 VISU::Storable* VISU::Vectors_i::Restore(const Storable::TRestoringMap& theMap, int theBuilding)
1521      throw(std::logic_error&)
1522 {
1523   DeformedShape_i::Restore(theMap,false);
1524
1525   myTypeGlyph = (VISU::Vectors::GlyphType)VISU::Storable::FindValue(theMap,"myTypeGlyph").toInt();
1526   myLineWidth = VISU::Storable::FindValue(theMap,"myLineWidth").toDouble();
1527   myPosGlyph = (VISU::Vectors::GlyphPos)VISU::Storable::FindValue(theMap,"myPosGlyph").toInt();
1528
1529   if(theBuilding)
1530     return Build(true);
1531   return NULL;
1532 }
1533
1534 void VISU::Vectors_i::ToStream(ostrstream& theStr){
1535   DeformedShape_i::ToStream(theStr);
1536
1537   Storable::DataToStream( theStr, "myTypeGlyph", myTypeGlyph );
1538   Storable::DataToStream( theStr, "myLineWidth", myLineWidth );
1539   Storable::DataToStream( theStr, "myPosGlyph",  myPosGlyph );
1540 }
1541
1542 VISU::Storable* VISU::VectorsRestore(SALOMEDS::SObject_ptr theSObject, 
1543                                      const string& thePrefix, const Storable::TRestoringMap& theMap)
1544      throw(std::logic_error&)
1545 {
1546   VISU::Result_i* pResult = GetResult(theSObject);
1547   if(pResult != NULL){
1548     VISU::Vectors_i* pResent = new VISU::Vectors_i(pResult);
1549     return pResent->Restore(theMap);
1550   }
1551   return NULL;
1552 }
1553
1554
1555 VISU::ScalarMap_i::DataType* VISU::Vectors_i::DoHook(int theRestoring){
1556   if(!theRestoring){
1557     myFactor = ScaleFactor();
1558   }
1559   if(MYDEBUG) 
1560     MESSAGE("Vectors_i::DoHook() - myFactor = "<<myFactor<<"; myTypeGlyph = "<<myTypeGlyph<<
1561             "; myLineWidth = "<<myLineWidth<<"; myPosGlyph = "<<myPosGlyph);
1562   if (myTypeGlyph == VISU::Vectors::NONE) return myHog->GetOutput();
1563   return myGlyph->GetOutput();
1564 }
1565
1566 VISU::Vectors_i::~Vectors_i(){
1567   if(MYDEBUG) MESSAGE("Vectors_i::~Vectors_i()");
1568   myGlyph->Delete();
1569   myHog->Delete();
1570 }
1571
1572 VISU_Actor* VISU::Vectors_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) {
1573   VISU_Actor* aActor = VISU::DeformedShape_i::CreateActor(theIO);
1574   if ( ! aActor ) return NULL;
1575   aActor->VisuActorType = VisuActorType_Vectors;
1576   aActor->IsShrinkable = false;
1577   vtkProperty* aProperty = aActor->GetProperty();
1578   aProperty->SetRepresentation(2);
1579   aProperty->SetLineWidth(myLineWidth);
1580   return aActor;
1581 }
1582
1583 void VISU::Vectors_i::Update() {
1584   switch (myTypeGlyph) {
1585   case VISU::Vectors::ARROW:
1586     {
1587       vtkGlyphSource2D *aGlyphSource = vtkGlyphSource2D::New();
1588       aGlyphSource->SetGlyphTypeToArrow();
1589       aGlyphSource->SetFilled(0);
1590       if(myPosGlyph == VISU::Vectors::TAIL)
1591         aGlyphSource->SetCenter(0.5, 0.0, 0.0);
1592       else if(myPosGlyph == VISU::Vectors::HEAD)
1593         aGlyphSource->SetCenter(-0.5, 0.0, 0.0);
1594       myGlyph->SetSource(aGlyphSource->GetOutput());
1595       aGlyphSource->Delete();
1596     }
1597     break;
1598
1599   case VISU::Vectors::CONE2:
1600   case VISU::Vectors::CONE6:
1601     {
1602       vtkConeSource *aGlyphSource = vtkConeSource::New(); //by default
1603       if (myTypeGlyph == VISU::Vectors::CONE6)
1604         aGlyphSource->SetResolution(7);
1605       else
1606         aGlyphSource->SetResolution(3);
1607       aGlyphSource->SetHeight(.7);
1608       aGlyphSource->SetRadius(.1);
1609       vtkTransform *aTransform = vtkTransform::New();
1610       if(myPosGlyph == VISU::Vectors::TAIL)
1611         aTransform->Translate(0.5*aGlyphSource->GetHeight(),0.0,0.0);
1612       else if(myPosGlyph == VISU::Vectors::HEAD)
1613         aTransform->Translate(-0.5*aGlyphSource->GetHeight(),0.0,0.0);
1614       
1615       vtkTransformPolyDataFilter *aFilter = vtkTransformPolyDataFilter::New();
1616       aFilter->SetInput(aGlyphSource->GetOutput());
1617       aGlyphSource->Delete();
1618       aFilter->SetTransform(aTransform);
1619       aTransform->Delete();
1620       myGlyph->SetSource(aGlyphSource->GetOutput());
1621       aFilter->Delete();
1622     }
1623     break;
1624   case VISU::Vectors::NONE:
1625     {
1626       if(myField->myEntity == VISU::CELL_ENTITY){
1627         vtkCellCenters *centers = vtkCellCenters::New(); // for vectors on cells
1628         centers->SetInput(myFieldTransform->GetUnstructuredGridOutput());
1629         centers->VertexCellsOn();
1630         myHog->SetInput(centers->GetOutput());
1631         centers->Delete();
1632       }else
1633         myHog->SetInput(myFieldTransform->GetInput());
1634       
1635       myHog->SetScaleFactor(myFactor);
1636       myHog->Update();
1637       myMapper->SetInput(myHog->GetOutput());
1638       myMapper->Update();
1639       return;
1640     }
1641   }
1642   if(myField->myNbComp > 1){
1643     if(myField->myEntity == VISU::CELL_ENTITY){
1644       vtkCellCenters *centers = vtkCellCenters::New(); // for vectors on cells
1645       centers->SetInput(myFieldTransform->GetUnstructuredGridOutput());
1646       centers->VertexCellsOn();
1647       myGlyph->SetInput(centers->GetOutput());
1648       centers->Delete();
1649     }else
1650       myGlyph->SetInput(myFieldTransform->GetUnstructuredGridOutput());
1651     myGlyph->SetVectorModeToUseVector();
1652     myGlyph->SetScaleFactor(2*myFactor);
1653   }
1654   myGlyph->Update();
1655   myMapper->SetInput(myGlyph->GetOutput());
1656   myMapper->Update();  
1657 }
1658 //==============================================================================
1659