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