]> SALOME platform Git repositories - modules/geom.git/blob - src/OBJECT/GEOM_Actor.cxx
Salome HOME
Copyrights update 2015.
[modules/geom.git] / src / OBJECT / GEOM_Actor.cxx
1 // Copyright (C) 2007-2015  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, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  GEOM OBJECT : interactive object for Geometry entities visualization
24 //  File   : GEOM_Actor.cxx
25 //  Author : Christophe ATTANASIO
26 //  Module : GEOM
27 //
28 /*!
29   \class GEOM_Actor GEOM_Actor.h
30   \brief This class allows to display an OpenCASCADE CAD model in a VTK viewer.
31 */
32 #include "GEOM_Actor.h" 
33  
34 #include "GEOM_DeviceActor.h" 
35 #include "GEOM_VertexSource.h" 
36 #include "GEOM_EdgeSource.h" 
37 #include "GEOM_WireframeFace.h" 
38 #include "GEOM_ShadingFace.h"
39 #include "GEOM_PainterPolyDataMapper.h"
40 #include "SVTK_Actor.h"
41
42 #include <OCC2VTK_Tools.h>
43
44 #include <vtkObjectFactory.h> 
45 #include <vtkRenderer.h> 
46 #include <vtkProperty.h> 
47 #include <vtkPointPicker.h>
48 #include <vtkCellPicker.h>
49  
50 #include <TopAbs_ShapeEnum.hxx>
51 #include <TopExp_Explorer.hxx>
52 #include <TopoDS.hxx>
53 #include <BRep_Tool.hxx>
54 #include <TopExp.hxx>
55  
56 #include <vtkPolyDataWriter.h> 
57  
58 #include <vtkAppendPolyData.h>  
59 #include <vtkPolyDataMapper.h>  
60 #include <vtkPolyData.h>  
61 #include <vtkTransform.h>
62 #include <vtkMatrix4x4.h>
63 #include <vtkMath.h>
64 #include <vtkCamera.h>
65
66 #include "utilities.h"
67
68 #include "SALOME_InteractiveObject.hxx"
69
70 //vtkStandardNewMacro(GEOM_Actor);
71
72 #ifndef MYDEBUG
73 //#define MYDEBUG
74 #endif
75
76 GEOM_Actor::GEOM_Actor(): 
77   isOnlyVertex(false),
78
79   myDeflection(-1),
80   myIsForced(false),
81
82   //  myDisplayMode(eWireframe), 
83   myIsSelected(false), 
84   myVectorMode(false),
85   myVerticesMode(false),
86
87   myVertexActor(GEOM_DeviceActor::New(),true), 
88   myVertexSource(GEOM_VertexSource::New(),true), 
89  
90   myStandaloneVertexActor(GEOM_DeviceActor::New(),true), 
91   myStandaloneVertexSource(GEOM_VertexSource::New(),true), 
92
93   myIsolatedEdgeActor(GEOM_DeviceActor::New(),true), 
94   myIsolatedEdgeSource(GEOM_EdgeSource::New(),true), 
95  
96   myOneFaceEdgeActor(GEOM_DeviceActor::New(),true), 
97   myOneFaceEdgeSource(GEOM_EdgeSource::New(),true), 
98  
99   mySharedEdgeActor(GEOM_DeviceActor::New(),true), 
100   mySharedEdgeSource(GEOM_EdgeSource::New(),true), 
101  
102   myWireframeFaceActor(GEOM_DeviceActor::New(),true), 
103   myWireframeFaceSource(GEOM_WireframeFace::New(),true), 
104  
105   myShadingFaceActor(GEOM_DeviceActor::New(),true), 
106   myShadingFaceSource(GEOM_ShadingFace::New(),true), 
107  
108   myHighlightActor(GEOM_DeviceActor::New(),true), 
109   myAppendFilter(vtkAppendPolyData::New(),true), 
110   // Use mapper as an instance of GEOM_PainterPolyDataMapper class
111   // to prevent drawing of mappers' content (due to an empty definition
112   // of GEOM_PainterPolyDataMapper::RenderPiece(...)).
113   // !!! Presentation of GEOM_Actor is drawing only with help of actors
114   // defined in this class !!!
115   myPolyDataMapper(GEOM_PainterPolyDataMapper::New(),true),
116
117   myHighlightProp(vtkProperty::New()),
118   myPreHighlightProp(vtkProperty::New()),
119   myShadingFaceProp(vtkProperty::New()),
120   myShadingBackFaceProp(vtkProperty::New())
121
122 #ifdef MYDEBUG
123   MESSAGE (this<< " GEOM_Actor::GEOM_Actor");
124 #endif
125
126   myPolyDataMapper->SetInputConnection(myAppendFilter->GetOutputPort()); 
127   vtkProperty* aProperty; 
128
129   myHighlightProp->SetAmbient(0.5);
130   myHighlightProp->SetDiffuse(0.3);
131   myHighlightProp->SetSpecular(0.2);
132   myHighlightProp->SetRepresentationToSurface();
133   myHighlightProp->SetAmbientColor(1, 1, 1);
134   myHighlightProp->SetDiffuseColor(1, 1, 1);
135   myHighlightProp->SetSpecularColor(0.5, 0.5, 0.5);
136   myHighlightProp->SetPointSize(SALOME_POINT_SIZE+2);
137   myHighlightActor->SetProperty(myHighlightProp.GetPointer());
138
139   this->myHighlightActor->SetInput(myAppendFilter->GetOutputPort(),false);
140
141   myPreHighlightProp->SetColor(0,1,1);
142   myPreHighlightProp->SetPointSize(SALOME_POINT_SIZE);
143   myPreHighlightProp->SetLineWidth(SALOME_LINE_WIDTH+1);
144   myPreHighlightProp->SetRepresentationToWireframe();
145
146   myAppendFilter->AddInputConnection(myVertexSource->GetOutputPort()); 
147   myVertexActor->SetInput(myVertexSource->GetOutputPort(),false); 
148   aProperty = myVertexActor->GetProperty(); 
149   aProperty->SetRepresentation(VTK_POINTS); 
150   aProperty->SetPointSize(3); 
151   aProperty->SetColor(1, 1, 0);
152  
153   myAppendFilter->AddInputConnection(myStandaloneVertexSource->GetOutputPort()); 
154   myStandaloneVertexActor->SetInput(myStandaloneVertexSource->GetOutputPort(),false); 
155   aProperty = myStandaloneVertexActor->GetProperty(); 
156   aProperty->SetRepresentation(VTK_POINTS); 
157   aProperty->SetPointSize(3); 
158   aProperty->SetColor(1, 1, 0);
159  
160   myAppendFilter->AddInputConnection(myIsolatedEdgeSource->GetOutputPort());
161   myIsolatedEdgeActor->SetInput(myIsolatedEdgeSource->GetOutputPort(),false); 
162   aProperty = myIsolatedEdgeActor->GetProperty(); 
163   aProperty->SetRepresentation(VTK_WIREFRAME); 
164   myIsolatedEdgeColor[0] = 1; myIsolatedEdgeColor[1] = 0; myIsolatedEdgeColor[2] = 0;
165   aProperty->SetColor(myIsolatedEdgeColor[0], myIsolatedEdgeColor[1], myIsolatedEdgeColor[2]);
166  
167   myAppendFilter->AddInputConnection(myOneFaceEdgeSource->GetOutputPort());
168   myOneFaceEdgeActor->SetInput(myOneFaceEdgeSource->GetOutputPort(),false); 
169   aProperty = myOneFaceEdgeActor->GetProperty(); 
170   aProperty->SetRepresentation(VTK_WIREFRAME); 
171   myOneFaceEdgeColor[0] = 0; myOneFaceEdgeColor[1] = 1; myOneFaceEdgeColor[2] = 0;
172   aProperty->SetColor(myOneFaceEdgeColor[0], myOneFaceEdgeColor[1], myOneFaceEdgeColor[2]);
173  
174   myAppendFilter->AddInputConnection(mySharedEdgeSource->GetOutputPort()); 
175   mySharedEdgeActor->SetInput(mySharedEdgeSource->GetOutputPort(),false); 
176   aProperty = mySharedEdgeActor->GetProperty(); 
177   aProperty->SetRepresentation(VTK_WIREFRAME); 
178   mySharedEdgeColor[0] = 1; mySharedEdgeColor[1] = 1; mySharedEdgeColor[2] = 0;
179   aProperty->SetColor(mySharedEdgeColor[0], mySharedEdgeColor[1], mySharedEdgeColor[2]);
180  
181   myAppendFilter->AddInputConnection(myWireframeFaceSource->GetOutputPort()); 
182   myWireframeFaceActor->SetInput(myWireframeFaceSource->GetOutputPort(),false); 
183   aProperty = myWireframeFaceActor->GetProperty(); 
184   aProperty->SetRepresentation(VTK_WIREFRAME); 
185   aProperty->SetColor(0.5, 0.5, 0.5);
186
187   myShadingFaceActor->SetInput(myShadingFaceSource->GetOutputPort(),true); 
188
189   myShadingFaceProp->SetRepresentation(VTKViewer::Representation::Surface); 
190   myShadingFaceProp->SetInterpolationToGouraud(); 
191   myShadingFaceProp->SetAmbient(1.0);
192   myShadingFaceProp->SetDiffuse(1.0);
193   myShadingFaceProp->SetSpecular(0.4);
194   myShadingFaceProp->SetAmbientColor(0.329412, 0.223529, 0.027451);
195   myShadingFaceProp->SetDiffuseColor(0.780392, 0.568627, 0.113725);
196   myShadingFaceProp->SetSpecularColor(0.992157, 0.941176, 0.807843);
197
198   myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
199
200   // Toggle display mode 
201   setDisplayMode(0); // WIRE FRAME
202   SetVectorMode(0);  //
203   SetVerticesMode(0);  //
204
205  
206  
207 GEOM_Actor::~GEOM_Actor() 
208
209 #ifdef MYDEBUG
210   MESSAGE (this<< " ~GEOM_Actor::GEOM_Actor");
211 #endif
212   myHighlightProp->Delete();
213   myPreHighlightProp->Delete();
214   myShadingFaceProp->Delete();
215   myShadingBackFaceProp->Delete();
216
217  
218 GEOM_Actor*  
219 GEOM_Actor:: 
220 New() 
221
222   GEOM_Actor* anObject = new GEOM_Actor(); 
223   anObject->SetMapper(anObject->myPolyDataMapper.Get()); 
224   return anObject; 
225
226  
227  
228 void Write(vtkPolyData* theDataSet, const char* theFileName){ 
229   vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New(); 
230   MESSAGE ("Write - "<<theFileName<<"' : "<<theDataSet->GetNumberOfPoints()<<"; "<<theDataSet->GetNumberOfCells()); 
231   aWriter->SetInputData(theDataSet); 
232   aWriter->SetFileName(theFileName); 
233   //aWriter->Write(); 
234   aWriter->Delete(); 
235
236  
237 void 
238 GEOM_Actor:: 
239 SetModified() 
240
241   this->myVertexSource->Modified(); 
242   this->myStandaloneVertexSource->Modified(); 
243   this->myIsolatedEdgeSource->Modified(); 
244   this->myOneFaceEdgeSource->Modified(); 
245   this->mySharedEdgeSource->Modified(); 
246   this->myWireframeFaceSource->Modified(); 
247   this->myShadingFaceSource->Modified(); 
248
249
250 void  
251 GEOM_Actor:: 
252 SetMapper(vtkMapper* theMapper) 
253
254   SALOME_Actor::SetMapper(theMapper); 
255
256
257 void 
258 GEOM_Actor:: 
259 AddToRender(vtkRenderer* theRenderer)
260 {
261   //SALOME_Actor::AddToRender(theRenderer);
262   
263   theRenderer->AddActor(this); 
264  
265   this->myHighlightActor->AddToRender(theRenderer); 
266   
267
268   myShadingFaceActor->AddToRender(theRenderer); 
269   myWireframeFaceActor->AddToRender(theRenderer); 
270  
271   mySharedEdgeActor->AddToRender(theRenderer); 
272   myOneFaceEdgeActor->AddToRender(theRenderer); 
273   myIsolatedEdgeActor->AddToRender(theRenderer); 
274  
275   myVertexActor->AddToRender(theRenderer); 
276   myStandaloneVertexActor->AddToRender(theRenderer); 
277 }
278  
279 void 
280 GEOM_Actor:: 
281 RemoveFromRender(vtkRenderer* theRenderer)
282 {
283   //SALOME_Actor::RemoveFromRender(theRenderer);
284
285   
286   theRenderer->RemoveActor(this);
287
288   myHighlightActor->RemoveFromRender(theRenderer); 
289   myShadingFaceActor->RemoveFromRender(theRenderer); 
290   myWireframeFaceActor->RemoveFromRender(theRenderer); 
291  
292   mySharedEdgeActor->RemoveFromRender(theRenderer); 
293   myOneFaceEdgeActor->RemoveFromRender(theRenderer); 
294   myIsolatedEdgeActor->RemoveFromRender(theRenderer); 
295  
296   myVertexActor->RemoveFromRender(theRenderer);
297   myStandaloneVertexActor->RemoveFromRender(theRenderer);
298
299   
300   SetSelected(false);
301   SetVisibility(false);
302 }
303
304 void  
305 GEOM_Actor:: 
306 setDisplayMode(int theMode) 
307
308 #ifdef MYDEBUG
309   MESSAGE ( "GEOM_Actor::setDisplayMode = "<<theMode );
310 #endif
311
312   if ( theMode == (int)eShadingWithEdges ) {
313     // Coloring edges
314     myIsolatedEdgeActor->GetProperty()->SetColor(myIsolatedEdgeColor[0],
315                                                  myIsolatedEdgeColor[1],
316                                                  myIsolatedEdgeColor[2]);
317     myOneFaceEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
318                                                 myEdgesInShadingColor[1],
319                                                 myEdgesInShadingColor[2]);
320     mySharedEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
321                                                myEdgesInShadingColor[1],
322                                                myEdgesInShadingColor[2]);
323   }
324   else {
325     // Coloring edges
326     myIsolatedEdgeActor->GetProperty()->SetColor(myIsolatedEdgeColor[0],
327                                                  myIsolatedEdgeColor[1],
328                                                  myIsolatedEdgeColor[2]);
329     mySharedEdgeActor->GetProperty()->SetColor(myIsolatedEdgeColor[0],
330                                                myIsolatedEdgeColor[1],
331                                                myIsolatedEdgeColor[2]);
332     myOneFaceEdgeActor->GetProperty()->SetColor(myOneFaceEdgeColor[0],
333                                                myOneFaceEdgeColor[1],
334                                                myOneFaceEdgeColor[2]);
335   }
336
337   VTKViewer_Actor::setDisplayMode(theMode);
338   SetVisibility(GetVisibility()); 
339
340
341 void  
342 GEOM_Actor:: 
343 SetSelected(bool theIsSelected) 
344
345 #ifdef MYDEBUG
346   MESSAGE ( "GEOM_Actor::SetSelected = "<<theIsSelected  );
347 #endif
348
349   myIsSelected = theIsSelected; 
350   SetVisibility(GetVisibility()); 
351
352
353 void  
354 GEOM_Actor:: 
355 SetVisibility(int theVisibility) 
356
357 #ifdef MYDEBUG
358   MESSAGE ( "GEOM_Actor::SetVisibility = "<<theVisibility <<"  myIsSelected="<< myIsSelected
359             << " theVisibility="<<theVisibility<<" myIsPreselected="<<myIsPreselected );
360 #endif
361
362   SALOME_Actor::SetVisibility(theVisibility);
363
364   this->myHighlightActor->SetVisibility(theVisibility && (myIsSelected || myIsPreselected));
365   
366   myShadingFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eShading || myDisplayMode == (int)eShadingWithEdges) && (!myIsSelected || !myIsPreselected)); 
367   myWireframeFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe) && !myIsSelected);
368
369   mySharedEdgeActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe || myDisplayMode == (int)eShadingWithEdges) && !myIsSelected);
370   myOneFaceEdgeActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe || myDisplayMode == (int)eShadingWithEdges) && !myIsSelected);
371   myIsolatedEdgeActor->SetVisibility(theVisibility && !myIsSelected);
372
373   myVertexActor->SetVisibility(theVisibility && (isOnlyVertex || (myVerticesMode && (!myIsSelected && !myIsPreselected))));// must be added new mode points
374
375   myStandaloneVertexActor->SetVisibility(theVisibility);
376 }
377  
378
379 void
380 GEOM_Actor
381 ::SetNbIsos(const int theNb[2])
382 {
383   myWireframeFaceSource->SetNbIso(theNb);
384 }
385
386 void
387 GEOM_Actor
388 ::GetNbIsos(int &theNbU,int &theNbV)
389 {
390   myWireframeFaceSource->GetNbIso(theNbU, theNbV);
391 }
392
393 void
394 GEOM_Actor
395 ::SetVectorMode(bool theMode)
396 {
397   myVectorMode = theMode;
398   myIsolatedEdgeSource->SetVectorMode(theMode);
399   myOneFaceEdgeSource->SetVectorMode(theMode);
400   mySharedEdgeSource->SetVectorMode(theMode);
401   SetModified();
402 }
403
404 bool
405 GEOM_Actor
406 ::GetVectorMode()
407 {
408   return myVectorMode;
409 }
410
411 void
412 GEOM_Actor
413 ::SetVerticesMode(bool theMode)
414 {
415   myVerticesMode = theMode;
416   if ( theMode || isOnlyVertex ) {
417     myAppendFilter->AddInputConnection(myVertexSource->GetOutputPort()); 
418   } else {
419     myAppendFilter->RemoveInputConnection(0, myVertexSource->GetOutputPort()); 
420   }
421   SetModified();
422 }
423
424 bool
425 GEOM_Actor
426 ::GetVerticesMode()
427 {
428   return myVerticesMode;
429 }
430
431 void  
432 GEOM_Actor:: 
433 SetDeflection(float theDeflection) 
434
435   if( myDeflection == theDeflection ) 
436     return;
437     
438   myDeflection = theDeflection; 
439  
440   GEOM::MeshShape(myShape,myDeflection);
441   
442   SetModified(); 
443 }
444
445 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
446                            float theDeflection,
447                            bool theIsVector)
448 {
449   myShape = theShape;
450
451   myVertexSource->Clear();
452   myStandaloneVertexSource->Clear();
453   myIsolatedEdgeSource->Clear();
454   myOneFaceEdgeSource->Clear();
455   mySharedEdgeSource->Clear();
456   myWireframeFaceSource->Clear();
457   myShadingFaceSource->Clear();
458
459   TopExp_Explorer aVertexExp (theShape,TopAbs_VERTEX);
460   for (; aVertexExp.More(); aVertexExp.Next())
461   {
462      const TopoDS_Vertex& aVertex = TopoDS::Vertex(aVertexExp.Current());
463      myVertexSource->AddVertex(aVertex);
464   }
465   
466   SetDeflection(theDeflection);
467
468   // look if edges are free or shared
469   TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
470   TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,anEdgeMap);
471   
472   GEOM::SetShape(theShape,anEdgeMap,theIsVector,
473                  myStandaloneVertexSource.Get(),
474                  myIsolatedEdgeSource.Get(),
475                  myOneFaceEdgeSource.Get(),
476                  mySharedEdgeSource.Get(),
477                  myWireframeFaceSource.Get(),
478                  myShadingFaceSource.Get());
479   isOnlyVertex =  
480     myIsolatedEdgeSource->IsEmpty() &&
481     myOneFaceEdgeSource->IsEmpty() &&
482     mySharedEdgeSource->IsEmpty() &&
483     myWireframeFaceSource->IsEmpty() &&
484     myShadingFaceSource->IsEmpty();
485
486   
487   if((bool)myShape.Infinite() || isOnlyVertex ){
488     myVertexActor->GetDeviceActor()->SetInfinitive(true);
489     myStandaloneVertexActor->GetDeviceActor()->SetInfinitive(true);
490     myHighlightActor->GetDeviceActor()->SetInfinitive(true);
491   }
492
493   // 0051777: TC7.2.0: Element could not be selected in Hypothesis Construction
494   myAppendFilter->Update();
495 }
496
497 // OLD METHODS
498 void GEOM_Actor::setDeflection(double adef) {
499 #ifdef MYDEBUG
500   MESSAGE ( "GEOM_Actor::setDeflection" );
501 #endif
502   SetDeflection((float)adef);
503 }
504
505
506 // warning! must be checked!
507 // SetHighlightProperty
508 // SetWireframeProperty
509 // SetShadingProperty
510
511 void GEOM_Actor::SetHighlightProperty(vtkProperty* Prop)
512 {
513 #ifdef MYDEBUG
514   MESSAGE ( "GEOM_Actor::SetHighlightProperty" );
515 #endif
516   this->myHighlightActor->GetProperty()->DeepCopy(Prop);
517   
518 }
519
520 void GEOM_Actor::SetWireframeProperty(vtkProperty* Prop)
521 {
522 #ifdef MYDEBUG
523   MESSAGE ( this << " GEOM_Actor::SetWireframeProperty" );
524 #endif
525   // must be filled
526   myWireframeFaceActor->SetProperty(Prop);
527 }
528
529
530 vtkProperty* GEOM_Actor::GetWireframeProperty()
531 {
532   return myWireframeFaceActor->GetProperty();
533 }
534
535 vtkProperty* GEOM_Actor::GetIsolatedEdgeProperty()
536 {
537   return myIsolatedEdgeActor->GetProperty();
538 }
539
540 vtkProperty* GEOM_Actor::GetVertexProperty()
541 {
542   return myVertexActor->GetProperty();
543 }
544
545 vtkProperty* GEOM_Actor::GetStandaloneVertexProperty()
546 {
547   return myStandaloneVertexActor->GetProperty();
548 }
549
550 vtkProperty* GEOM_Actor::GetSharedEdgeProperty()
551 {
552   return mySharedEdgeActor->GetProperty();
553 }
554
555 vtkProperty* GEOM_Actor::GetFaceEdgeProperty()
556 {
557   return myOneFaceEdgeActor->GetProperty();
558 }
559
560 void GEOM_Actor::SetShadingProperty(vtkProperty* Prop)
561 {
562 #ifdef MYDEBUG
563   MESSAGE ( "GEOM_Actor::SetShadingProperty" );
564 #endif
565   myShadingFaceProp->DeepCopy(Prop);
566 }
567
568
569 vtkProperty* GEOM_Actor::GetShadingProperty()
570 {
571   return myShadingFaceProp;
572 }
573
574
575 void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *theMapper)
576 {
577 #ifdef MYDEBUG
578   MESSAGE ( "GEOM_Actor::Render" );
579 #endif
580
581   if(!GetVisibility())
582     return;
583
584   /* render the property */
585   if (!this->Property) {
586     // force creation of a property
587     this->GetProperty();
588     this->Property->SetInterpolation(1);
589     this->Property->SetRepresentationToSurface();
590     this->Property->SetAmbient(0.3);
591     this->Property->SetAmbientColor(0.88,0.86,0.2);
592     this->Property->SetDiffuseColor(0.99,0.7,0.21);
593     this->Property->SetSpecularColor(0.99,0.98,0.83);
594   }
595
596   switch(myDisplayMode){
597   case eWireframe://wireframe
598     myPreHighlightProp->SetRepresentationToWireframe();
599     myHighlightProp->SetRepresentationToWireframe();
600     break;
601   case eShading://shading
602   case eShadingWithEdges://shading with edges
603     myPreHighlightProp->SetRepresentationToSurface();
604     myHighlightProp->SetRepresentationToSurface();
605     myShadingFaceProp->SetRepresentationToSurface();
606     myShadingBackFaceProp->SetRepresentationToSurface();
607     break;
608   }
609
610   if(!myIsSelected){
611     if(myIsPreselected){
612       this->myHighlightActor->SetProperty(myPreHighlightProp.GetPointer());
613       myShadingFaceActor->SetProperty(myPreHighlightProp.GetPointer());
614       myShadingFaceActor->SetBackfaceProperty(myPreHighlightProp.GetPointer());
615     } else {
616       this->myHighlightActor->SetProperty(myShadingFaceProp.GetPointer());
617       myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
618       myShadingFaceActor->SetBackfaceProperty(myShadingBackFaceProp.GetPointer());
619     }
620   }
621   else{
622     this->myHighlightActor->SetProperty(myHighlightProp.GetPointer());
623     myShadingFaceActor->SetProperty(myHighlightProp.GetPointer());
624     myShadingFaceActor->SetBackfaceProperty(myHighlightProp.GetPointer());
625   }
626
627   this->Property->Render(this, ren);
628   if (this->BackfaceProperty) {
629     this->BackfaceProperty->BackfaceRender(this, ren);
630     this->Device->SetBackfaceProperty(this->BackfaceProperty);
631   }
632   this->Device->SetProperty(this->Property);
633   /*  if(myShape.ShapeType() == TopAbs_VERTEX) {
634     if(ren){
635       //The parameter determine size of vertex actor relate to diagonal of RendererWindow
636       static double delta = 0.01;
637       double X1 = -1, Y1 = -1, Z1 = 0;
638       ren->ViewToWorld(X1,Y1,Z1);
639       double X2 = +1, Y2 = +1, Z2 = 0;
640       ren->ViewToWorld(X2,Y2,Z2);
641       Z2 = sqrt((X2-X1)*(X2-X1) + (Y2-Y1)*(Y2-Y1) + (Z2-Z1)*(Z2-Z1));
642       this->SetScale(Z2*delta);
643     }
644     vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
645     this->GetMatrix(ren->GetActiveCamera(), aMatrix);
646     this->Device->SetUserMatrix(aMatrix);
647     this->Device->Render(ren,theMapper);
648     aMatrix->Delete();    
649     } else*/
650     this->Device->Render(ren, theMapper);
651 }
652
653 void GEOM_Actor::ReleaseGraphicsResources(vtkWindow *)
654 {
655 #ifdef MYDEBUG
656   MESSAGE ( "GEOM_Actor::ReleaseGraphicsResources" );
657 #endif  
658 }
659
660
661
662 void GEOM_Actor::ShallowCopy(vtkProp *prop)
663 {
664 #ifdef MYDEBUG
665   MESSAGE ( "GEOM_Actor::ShallowCopy" );
666 #endif
667   GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop);
668   if ( f != NULL )
669     {
670       this->SetShape(f->getTopo(),f->GetDeflection());
671     }
672
673   // Now do superclass
674   this->SALOME_Actor::ShallowCopy(prop);
675 }
676
677 const TopoDS_Shape& GEOM_Actor::getTopo() {
678 #ifdef MYDEBUG
679   MESSAGE ( "GEOM_Actor::getTopo" );
680 #endif
681   return myShape;
682 }
683
684 void GEOM_Actor::setInputShape(const TopoDS_Shape& ashape, double adef1,
685                                int imode, bool isVector)
686 {
687 #ifdef MYDEBUG
688   MESSAGE ( "GEOM_Actor::setInputShape" );
689 #endif
690 }
691
692 double GEOM_Actor::getDeflection()
693 {
694 #ifdef MYDEBUG
695   MESSAGE ( "GEOM_Actor::getDeflection" );
696 #endif
697   return (double) GetDeflection();
698 }
699
700
701 double GEOM_Actor::isVector()
702 {
703 #ifdef MYDEBUG
704   MESSAGE ( "GEOM_Actor::isVector" );
705 #endif  
706   return 0;
707 }
708
709 void GEOM_Actor::SubShapeOn()
710 {
711 #ifdef MYDEBUG
712   MESSAGE ( "GEOM_Actor::SubShapeOn" );
713 #endif  
714 }
715
716 void GEOM_Actor::SubShapeOff()
717 {
718 #ifdef MYDEBUG
719   MESSAGE ( "GEOM_Actor::SubShapeOff" );
720 #endif
721 }
722
723 void GEOM_Actor::highlight(bool highlight)
724 {
725 #ifdef MYDEBUG
726   MESSAGE ( this << " GEOM_Actor::highlight highlight="<<highlight );
727 #endif
728   SALOME_Actor::highlight(highlight);  
729 }
730
731 void GEOM_Actor::SetOpacity(double opa)
732 {
733   // enk:tested OK
734   myShadingFaceProp->SetOpacity(opa);
735   myShadingBackFaceProp->SetOpacity(opa);
736   myHighlightProp->SetOpacity(opa);
737   myPreHighlightProp->SetOpacity(opa);
738   myVertexActor->GetProperty()->SetOpacity(opa);
739   myStandaloneVertexActor->GetProperty()->SetOpacity(opa);
740 }
741
742 double GEOM_Actor::GetOpacity()
743 {
744   // enk:tested OK
745   return myShadingFaceProp->GetOpacity(); 
746 }
747
748 void GEOM_Actor::SetColor(double r,double g,double b)
749 {
750   // set the same color to all sub-actors:
751   // - points
752   // - standalone edges
753   // - shared edges
754   // - free edges
755   // - shading color (front and back faces)
756   SetPointColor(r, g, b);
757   SetIsolatedEdgeColor(r, g, b);
758   SetSharedEdgeColor(r, g, b);
759   SetFreeEdgeColor(r, g, b);
760   myShadingFaceProp->SetColor(r,g,b);     // shading color
761   myShadingBackFaceProp->SetColor(r,g,b); // back face shading color
762 }
763
764 void GEOM_Actor::GetColor(double& r,double& g,double& b)
765 {
766   double aRGB[3];
767   myShadingFaceProp->GetColor(aRGB);
768   r = aRGB[0];
769   g = aRGB[1];
770   b = aRGB[2];
771 }
772
773 /*!
774   \brief Set color of points
775   Points actor is shown in Wireframe mode only, see SetVisibility()
776 */
777 void GEOM_Actor::SetPointColor(double r,  double g,  double b)
778 {
779   myVertexActor->GetProperty()->SetColor(r, g, b);
780   myStandaloneVertexActor->GetProperty()->SetColor(r, g, b);
781 }
782
783 /*!
784   \brief Set color of standalone edges, wires, vectors
785   This actor is shown in all display mode, see SetVisibility()
786   TODO: check - this color seems to be used not only for standalone edges
787 */
788 void GEOM_Actor::SetIsolatedEdgeColor(double r, double g,  double b)
789 {
790   myIsolatedEdgeColor[0] = r; myIsolatedEdgeColor[1] = g; myIsolatedEdgeColor[2] = b;
791   myIsolatedEdgeActor->GetProperty()->SetColor(r, g, b);
792 }
793
794 /*!
795   \brief Set color of shared edges
796   This actor is shown only in wireframe and shading+edges display modes, see SetVisibility()
797   TODO: check - this seems to be not working currently
798 */
799 void GEOM_Actor::SetSharedEdgeColor(double r, double g, double b)
800 {
801   mySharedEdgeColor[0] = r; mySharedEdgeColor[1] = g; mySharedEdgeColor[2] = b;
802   if ( myDisplayMode != (int)eShadingWithEdges )
803     mySharedEdgeActor->GetProperty()->SetColor(r, g, b);
804 }
805
806 /*!
807   \brief Set color of edges for standalone faces
808   This actor is shown only in wireframe and shading+edges display modes, see SetVisibility()
809   TODO: this color should be used not only for faces
810 */
811 void GEOM_Actor::SetFreeEdgeColor(double r, double g, double b)
812 {
813   myOneFaceEdgeColor[0] = r; myOneFaceEdgeColor[1] = g; myOneFaceEdgeColor[2] = b;
814   if ( myDisplayMode != (int)eShadingWithEdges )
815     myOneFaceEdgeActor->GetProperty()->SetColor(r, g, b);
816 }
817
818 /*!
819   \brief Set color of iso-lines
820   This actor is shown only in wireframe display mode, see SetVisibility()
821 */
822 void GEOM_Actor::SetIsosColor(double r, double g, double b)
823 {
824   myWireframeFaceActor->GetProperty()->SetColor(r, g, b);
825 }
826
827 void GEOM_Actor::SetMaterial(std::vector<vtkProperty*> theProps)
828 {
829   // we set material properties as back and front material
830   int aSize = theProps.size();
831
832   if ( aSize < 1 || aSize > 2)
833     return;
834
835   // theProps[0] -- front material properties
836   // theProps[1] -- back material properties (if exist)
837
838   double aCoefnt;
839
840   // Set reflection coefficients
841   aCoefnt = theProps[0]->GetAmbient();
842   myShadingFaceProp->SetAmbient(aCoefnt);
843   myVertexActor->GetProperty()->SetAmbient(aCoefnt);
844   myStandaloneVertexActor->GetProperty()->SetAmbient(aCoefnt);
845   if ( aSize == 2 )
846     aCoefnt = theProps[1]->GetAmbient();
847   myShadingBackFaceProp->SetAmbient(aCoefnt);
848
849   // Set diffuse coefficients
850   aCoefnt = theProps[0]->GetDiffuse();
851   myShadingFaceProp->SetDiffuse(aCoefnt);
852   myVertexActor->GetProperty()->SetDiffuse(aCoefnt);
853   myStandaloneVertexActor->GetProperty()->SetDiffuse(aCoefnt);
854   if ( aSize == 2 )
855     aCoefnt = theProps[1]->GetDiffuse();
856   myShadingBackFaceProp->SetDiffuse(aCoefnt);
857   
858   // Set specular coefficients
859   aCoefnt = theProps[0]->GetSpecular();
860   myShadingFaceProp->SetSpecular(aCoefnt);
861   myVertexActor->GetProperty()->SetSpecular(aCoefnt);
862   myStandaloneVertexActor->GetProperty()->SetSpecular(aCoefnt);
863   if ( aSize == 2 )
864     aCoefnt = theProps[1]->GetSpecular();
865   myShadingBackFaceProp->SetSpecular(aCoefnt);
866
867
868   double* aColor;
869
870   // Set reflection colors
871   aColor = theProps[0]->GetAmbientColor();
872   myShadingFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
873   myVertexActor->GetProperty()->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
874   myStandaloneVertexActor->GetProperty()->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
875   if ( aSize == 2 )
876     aColor = theProps[1]->GetAmbientColor();
877   myShadingBackFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
878
879   // Set diffuse colors
880   aColor = theProps[0]->GetDiffuseColor();
881   myShadingFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
882   myVertexActor->GetProperty()->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
883   myStandaloneVertexActor->GetProperty()->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
884   if ( aSize == 2 )
885     aColor = theProps[1]->GetDiffuseColor();
886   myShadingBackFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
887
888   // Set specular colors
889   aColor = theProps[0]->GetSpecularColor();
890   myShadingFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
891   myVertexActor->GetProperty()->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
892   myStandaloneVertexActor->GetProperty()->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
893   if ( aSize == 2 )
894     aColor = theProps[1]->GetSpecularColor();
895   myShadingBackFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
896
897   // Set shininess
898   aCoefnt = theProps[0]->GetSpecularPower();
899   myShadingFaceProp->SetSpecularPower(aCoefnt);
900   myVertexActor->GetProperty()->SetSpecularPower(aCoefnt);
901   myStandaloneVertexActor->GetProperty()->SetSpecularPower(aCoefnt);
902   if ( aSize == 2 )
903     aCoefnt = theProps[1]->GetSpecularPower();
904   myShadingBackFaceProp->SetSpecularPower(aCoefnt);
905
906   // Set back face material property
907   myShadingFaceActor->SetBackfaceProperty(myShadingBackFaceProp.GetPointer());
908 }
909
910 vtkProperty* GEOM_Actor::GetFrontMaterial()
911 {
912   return myShadingFaceProp;
913 }
914
915 vtkProperty* GEOM_Actor::GetBackMaterial()
916 {
917   return myShadingBackFaceProp;
918 }
919
920 bool GEOM_Actor::IsInfinitive()
921 {
922   return ((bool)myShape.Infinite() || isOnlyVertex);
923 }
924
925 /*!
926   To map current selection to VTK representation
927 */
928 void
929 GEOM_Actor
930 ::Highlight(bool theIsHighlight)
931 {
932   myIsSelected = theIsHighlight;
933 #ifdef MYDEBUG
934   MESSAGE ( this << " GEOM_Actor::Highlight myIsSelected="<<myIsSelected );
935 #endif
936
937   SALOME_Actor::Highlight(theIsHighlight); // this method call ::highlight(theIsHighlight) in the end
938   SetVisibility(GetVisibility());
939 }
940
941 /*!
942   To process prehighlight (called from SVTK_InteractorStyle)
943 */
944 bool
945 GEOM_Actor
946 ::PreHighlight(vtkInteractorStyle *theInteractorStyle, 
947                SVTK_SelectionEvent* theSelectionEvent,
948                bool theIsHighlight)
949 {
950 #ifdef MYDEBUG
951   MESSAGE ( this<<" GEOM_Actor::PreHighlight (3) theIsHighlight="<<theIsHighlight );
952 #endif
953
954   if ( !GetPickable() )
955     return false;  
956
957   myPreHighlightActor->SetVisibility( false );
958   bool anIsPreselected = myIsPreselected;
959   
960   Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
961   bool anIsChanged = (mySelectionMode != aSelectionMode);
962
963   if( !theIsHighlight ) {
964     SetPreSelected( false );
965   }else{
966     switch(aSelectionMode){
967     case ActorSelection : 
968     {
969 //       cout << "=============== " << myIO->getEntry() << endl;
970 //       int nbio = mySelector->IObjectCount();
971 //       cout << " nbio = " << nbio << endl;
972
973       if( !mySelector->IsSelected( myIO ) ) {
974         //      printf ("!!!!!!!!!!!!!!!!\n");
975         SetPreSelected( true );
976       }
977     }
978     default:
979       break;
980     }
981   }
982
983   mySelectionMode = aSelectionMode;
984   anIsChanged |= (anIsPreselected != myIsPreselected);
985
986   SetVisibility(GetVisibility());
987   return anIsChanged;
988 }
989
990 /*!
991   To process highlight (called from SVTK_InteractorStyle)
992 */
993 bool
994 GEOM_Actor
995 ::Highlight(vtkInteractorStyle *theInteractorStyle, 
996             SVTK_SelectionEvent* theSelectionEvent,
997             bool theIsHighlight)
998 {
999   // define the selection of object
1000 #ifdef MYDEBUG
1001   MESSAGE ( std::endl << this << " GEOM_Actor::Highlight (3) myIsSelected="<<myIsSelected );
1002 #endif
1003   bool aRet = SALOME_Actor::Highlight(theInteractorStyle,theSelectionEvent,theIsHighlight);
1004   SetSelected(theIsHighlight);
1005   if(theIsHighlight)
1006     SetPreSelected(false);
1007   
1008  
1009   return aRet;
1010 }
1011
1012 // Copy the follower's composite 4x4 matrix into the matrix provided.
1013 void GEOM_Actor::GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result)
1014 {
1015   double *pos, *vup;
1016   double Rx[3], Ry[3], Rz[3], p1[3];
1017   vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
1018   int i;
1019   double distance;
1020   
1021   this->GetOrientation();
1022   this->Transform->Push();  
1023   this->Transform->PostMultiply();  
1024   this->Transform->Identity();
1025
1026   // apply user defined matrix last if there is one 
1027   if (this->UserMatrix)
1028     {
1029     this->Transform->Concatenate(this->UserMatrix);
1030     }
1031
1032   this->Transform->Translate(-this->Origin[0],
1033                              -this->Origin[1],
1034                              -this->Origin[2]);
1035   // scale
1036   this->Transform->Scale(this->Scale[0],
1037                          this->Scale[1],
1038                          this->Scale[2]);
1039   
1040   // rotate
1041   this->Transform->RotateY(this->Orientation[1]);
1042   this->Transform->RotateX(this->Orientation[0]);
1043   this->Transform->RotateZ(this->Orientation[2]);
1044
1045   if (theCam)
1046     {
1047     // do the rotation
1048     // first rotate y 
1049     pos = theCam->GetPosition();
1050     vup = theCam->GetViewUp();
1051
1052     if (theCam->GetParallelProjection())
1053       {
1054       theCam->GetDirectionOfProjection(Rz);
1055       }
1056     else
1057       {
1058       distance = sqrt(
1059         (pos[0] - this->Position[0])*(pos[0] - this->Position[0]) +
1060         (pos[1] - this->Position[1])*(pos[1] - this->Position[1]) +
1061         (pos[2] - this->Position[2])*(pos[2] - this->Position[2]));
1062       for (i = 0; i < 3; i++)
1063         {
1064         Rz[i] = (pos[i] - this->Position[i])/distance;
1065         }
1066       }
1067   
1068     vtkMath::Cross(vup,Rz,Rx);
1069     vtkMath::Normalize(Rx);
1070     vtkMath::Cross(Rz,Rx,Ry);
1071     
1072     matrix->Element[0][0] = Rx[0];
1073     matrix->Element[1][0] = Rx[1];
1074     matrix->Element[2][0] = Rx[2];
1075     matrix->Element[0][1] = Ry[0];
1076     matrix->Element[1][1] = Ry[1];
1077     matrix->Element[2][1] = Ry[2];
1078     matrix->Element[0][2] = Rz[0];
1079     matrix->Element[1][2] = Rz[1];
1080     matrix->Element[2][2] = Rz[2];
1081     
1082     this->Transform->Concatenate(matrix);
1083     }
1084   
1085   // translate to projection reference point PRP
1086   // this is the camera's position blasted through
1087   // the current matrix
1088   p1[0] = this->Origin[0] + this->Position[0];
1089   p1[1] = this->Origin[1] + this->Position[1];
1090   p1[2] = this->Origin[2] + this->Position[2];
1091
1092   this->Transform->Translate(p1[0],p1[1],p1[2]);
1093   this->Transform->GetMatrix(result);
1094   
1095   matrix->Delete();
1096   this->Transform->Pop();  
1097 }  
1098
1099 void GEOM_Actor::SetEdgesInShadingColor(double r,double g,double b)
1100 {
1101   myEdgesInShadingColor[0] = r;
1102   myEdgesInShadingColor[1] = g;
1103   myEdgesInShadingColor[2] = b;
1104 }
1105
1106 void GEOM_Actor::SetIsosWidth(const int width) {
1107   myWireframeFaceActor->GetProperty()->SetLineWidth(width);
1108 }
1109
1110 int GEOM_Actor::GetIsosWidth() const {
1111   return (int)myWireframeFaceActor->GetProperty()->GetLineWidth();
1112 }
1113
1114 void GEOM_Actor::SetWidth(const int width) {
1115   myIsolatedEdgeActor->GetProperty()->SetLineWidth(width);
1116   myOneFaceEdgeActor->GetProperty()->SetLineWidth(width);
1117   mySharedEdgeActor->GetProperty()->SetLineWidth(width);
1118   myHighlightProp->SetLineWidth(width);
1119   myPreHighlightProp->SetLineWidth(width+1);
1120
1121 }
1122
1123 int GEOM_Actor::GetWidth() const {
1124   return (int)myIsolatedEdgeActor->GetProperty()->GetLineWidth();
1125 }