Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/visu.git] / src / OBJECT / VISU_GaussPtsAct.cxx
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : VISU_MeshAct.hxx
25 //  Author : Laurent CORNABE with the help of Nicolas REJNERI
26 //  Module : VISU
27 //  $Header$
28
29 #include "VISU_GaussPtsAct.h"
30 #include "VISU_GaussPointsPL.hxx"
31 #include "VISU_GaussPtsSettings.h"
32 #include "VISU_GaussPtsDeviceActor.h"
33 #include "VISU_WidgetCtrl.hxx"
34 #include "VISU_SphereWidget.hxx"
35 #include "VISU_OpenGLPointSpriteMapper.hxx"
36 #include "VISU_ScalarBarCtrl.hxx"
37 #include "VISU_ScalarBarActor.hxx"
38
39 #include "SALOME_ExtractGeometry.h"
40
41 #include "VISU_Event.h" 
42 #include "SVTK_Actor.h"
43
44 #include <vtkCamera.h>
45 #include <vtkRenderer.h>
46 #include <vtkPointPicker.h>
47 #include <vtkScalarBarWidget.h>
48 #include <vtkScalarBarActor.h>
49 #include <vtkTextMapper.h>
50 #include <vtkTextProperty.h>
51
52 #include <vtkCellData.h>
53 #include <vtkPointData.h>
54
55 #include <vtkDataArray.h>
56 #include <vtkFloatArray.h>
57
58 #include <vtkSphereSource.h>
59 #include <vtkPolyDataMapper.h>
60 #include <vtkPolyData.h>
61 #include <vtkActor.h>
62
63 #include <vtkObjectFactory.h>
64 #include <vtkCallbackCommand.h>
65 #include <vtkInteractorStyle.h>
66 #include <vtkRenderWindowInteractor.h>
67 #include <vtkOutlineSource.h>
68
69 #include <sstream>
70 #include <boost/bind.hpp>
71
72 #include <vtkUnstructuredGrid.h>
73 #include <vtkDataSetMapper.h>
74 #include <vtkRenderWindow.h>
75 #include <vtkCellArray.h>
76 #include <vtkCell.h>
77 #include <vtkMath.h>
78
79 #include <vtkViewport.h>
80
81 #include "utilities.h"
82
83 #ifdef _DEBUG_
84 static int MYDEBUG = 0;
85 static int MYDEBUG1 = 0;
86 static int MYDEBUG2 = 0;
87 #else
88 static int MYDEBUG = 0;
89 static int MYDEBUG1 = 0;
90 static int MYDEBUG2 = 0;
91 #endif
92
93
94 //============================================================================
95 vtkStandardNewMacro(VISU_GaussPtsAct);
96
97 //----------------------------------------------------------------------------
98 VISU_GaussPtsAct
99 ::VISU_GaussPtsAct():
100   myEventCallbackCommand(vtkCallbackCommand::New()),
101   myPriority(0.0),
102   myDeviceActor(VISU_GaussPtsDeviceActor::New()),
103   myWidgetCtrl(NULL),
104   myGaussPointsPL(NULL),
105   myLastObjPointID(-1),
106   myTextActor(VISU_FramedTextActor::New()),
107   myCursorPyramid(VISU_CursorPyramid::New()),
108   myCursorPyramidSelected(VISU_CursorPyramid::New()),
109   myCellSource(vtkUnstructuredGrid::New()),
110   myCellActor(SVTK_Actor::New()),
111   myScalarBarCtrl(VISU_ScalarBarCtrl::New()),
112   myBarVisibility(true),
113   myPickingSettings(NULL),
114   myInsideCursorSettings(NULL),
115   myCurrentPL(NULL)
116 {
117   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::VISU_GaussPtsAct - this = "<<this);
118
119   myEventCallbackCommand->Delete();
120   myDeviceActor->Delete();
121   myTextActor->Delete();
122
123   myCursorPyramid->Delete();
124   myCursorPyramid->SetPickable(0);
125   myCursorPyramid->SetVisibility(0);
126
127   myCursorPyramidSelected->Delete();
128   myCursorPyramidSelected->SetPickable(0);
129   myCursorPyramidSelected->SetVisibility(0);
130
131   myCellSource->Delete();
132   myCellActor->Delete();
133
134   myEventCallbackCommand->SetClientData(this); 
135   myEventCallbackCommand->SetCallback(VISU_GaussPtsAct::ProcessEvents);
136
137   myDeviceActor->SetProperty(GetProperty());
138   myDeviceActor->SetVisibility(true);
139   myDeviceActor->SetPickable(false);
140
141   myTextActor->SetVisibility(false);
142   myTextActor->SetPickable(false);
143
144   myCellSource->Allocate();
145   myCellActor->Initialize();
146   myCellActor->SetRepresentation(VTK_WIREFRAME);
147   myCellActor->SetSource(myCellSource.GetPointer());
148   
149   myCellActor->SetVisibility(0);
150   myCellActor->SetPickable(0);
151   myCellActor->GetProperty()->SetAmbient(1.0);
152   myCellActor->GetProperty()->SetDiffuse(0.0);
153
154   myScalarBarCtrl->Delete();
155 }
156
157 VISU_GaussPtsAct
158 ::~VISU_GaussPtsAct()
159 {
160   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::~VISU_GaussPtsAct - this = "<<this);
161   SetWidgetCtrl(NULL);
162   SetInteractor(NULL);
163   SetPickingSettings(NULL);
164   SetInsideCursorSettings(NULL);
165 }
166
167
168 //----------------------------------------------------------------------------
169 void
170 VISU_GaussPtsAct
171 ::SetPipeLine(VISU_PipeLine* thePipeLine) 
172 {
173   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::SetPipeLine - this = "<<this);
174
175   myGaussPointsPL = dynamic_cast<VISU_GaussPointsPL*>(thePipeLine);
176
177   Superclass::SetPipeLine(thePipeLine);
178 }
179
180 VISU_GaussPointsPL*
181 VISU_GaussPtsAct
182 ::GetGaussPointsPL()
183 {
184   return myGaussPointsPL.GetPointer();
185 }
186
187 void
188 VISU_GaussPtsAct
189 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
190 {
191   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::ShallowCopyPL - this = "<<this);
192
193   Superclass::ShallowCopyPL(thePipeLine);
194
195   UpdateInsideCursorSettings();
196
197   Highlight(isHighlighted());
198 }
199
200
201 //----------------------------------------------------------------------------
202 vtkMapper* 
203 VISU_GaussPtsAct
204 ::GetMapper()
205 {
206   myMapper->Update();
207   return Superclass::GetMapper();
208 }
209
210 float* 
211 VISU_GaussPtsAct
212 ::GetBounds()
213 {
214   return GetMapper()->GetBounds();
215 }
216
217 vtkDataSet* 
218 VISU_GaussPtsAct
219 ::GetInput()
220 {
221   return GetMapper()->GetInput();
222 }
223
224 VISU_PipeLine* 
225 VISU_GaussPtsAct
226 ::GetCurrentPL() 
227
228   return myCurrentPL;
229 }
230
231
232 //----------------------------------------------------------------------------
233 void
234 VISU_GaussPtsAct
235 ::AddToRender(vtkRenderer* theRenderer)
236 {
237   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::AddToRender - this = "<<this);
238
239   Superclass::AddToRender(theRenderer);
240
241   myDeviceActor->AddToRender(theRenderer);
242
243   theRenderer->AddActor(myTextActor.GetPointer());
244   theRenderer->AddActor(myCellActor.GetPointer());
245
246   myCursorPyramid->AddToRender(theRenderer);
247   myCursorPyramidSelected->AddToRender(theRenderer);
248   myScalarBarCtrl->AddToRender(theRenderer);
249 }
250
251 void 
252 VISU_GaussPtsAct
253 ::RemoveFromRender(vtkRenderer* theRenderer)
254 {
255   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::RemoveFromRender - this = "<<this);
256
257   Superclass::RemoveFromRender(theRenderer);
258
259   myDeviceActor->RemoveFromRender(theRenderer);
260   
261   theRenderer->RemoveActor(myTextActor.GetPointer());
262   theRenderer->RemoveActor(myCellActor.GetPointer());
263   
264   myCursorPyramid->RemoveFromRender(theRenderer);
265   myCursorPyramidSelected->RemoveFromRender(theRenderer);
266   myScalarBarCtrl->RemoveFromRender(theRenderer);
267 }
268
269 void 
270 VISU_GaussPtsAct
271 ::SetTransform(VTKViewer_Transform* theTransform)
272 {
273   Superclass::SetTransform(theTransform);
274
275   myDeviceActor->SetTransform(theTransform);
276 }
277
278 int
279 VISU_GaussPtsAct
280 ::RenderOpaqueGeometry(vtkViewport *viewport)
281 {
282   return 1;
283 }
284
285 int
286 VISU_GaussPtsAct
287 ::RenderTranslucentGeometry(vtkViewport *viewport)
288 {
289   return 1;
290 }
291
292
293 //----------------------------------------------------------------------------
294 void
295 VISU_GaussPtsAct
296 ::SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl)
297 {
298   if(myWidgetCtrl == theWidgetCtrl)
299     return;
300
301   if(MYDEBUG) 
302     MESSAGE("VISU_GaussPtsAct::SetWidgetCtrl - this = "<<this<<"; theWidget = "<<theWidgetCtrl);
303
304   if(myWidgetCtrl)
305     myWidgetCtrl->RemoveObserver(myEventCallbackCommand.GetPointer());
306
307   if(theWidgetCtrl){
308     theWidgetCtrl->AddObserver(vtkCommand::EnableEvent, 
309                                myEventCallbackCommand.GetPointer(), 
310                                myPriority);
311     theWidgetCtrl->AddObserver(vtkCommand::DisableEvent, 
312                                myEventCallbackCommand.GetPointer(), 
313                                myPriority);
314     theWidgetCtrl->AddObserver(vtkCommand::StartInteractionEvent, 
315                                myEventCallbackCommand.GetPointer(), 
316                                myPriority);
317     theWidgetCtrl->AddObserver(vtkCommand::EndInteractionEvent, 
318                                myEventCallbackCommand.GetPointer(), 
319                                myPriority);
320   }
321
322   myWidgetCtrl = theWidgetCtrl;
323 }
324
325 bool
326 VISU_GaussPtsAct
327 ::GetChangeMagnification()
328 {
329   return myChangeMagnification;
330 }
331
332 void
333 VISU_GaussPtsAct
334 ::ChangeMagnification( bool up )
335 {
336   myEventCallbackCommand->SetAbortFlag(1);
337
338   float aMagnification = myInsideCursorSettings->GetMagnification();
339   float anIncrement = myInsideCursorSettings->GetIncrement();
340   float coefficient = up ? anIncrement : 1 / anIncrement;
341
342   myInsideCursorSettings->SetMagnification( aMagnification * coefficient );
343   myInsideCursorSettings->InvokeEvent(VISU::UpdateFromSettingsEvent,NULL);
344
345   Update();
346 }
347
348 //----------------------------------------------------------------------------
349 namespace
350 {
351   VISU_GaussPointsPL*
352   CreatePipeLine(VISU_GaussPointsPL* thePipeLine)
353   {
354     VISU_GaussPointsPL* aPipeLine = VISU_GaussPointsPL::New();
355     aPipeLine->SetGaussPtsIDMapper(thePipeLine->GetGaussPtsIDMapper());
356     aPipeLine->ShallowCopy(thePipeLine);
357     aPipeLine->Update();
358     return aPipeLine;
359   }
360 }
361
362 void
363 VISU_GaussPtsAct
364 ::SetMapperInput(vtkDataSet* theDataSet) 
365 {
366   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::SetMapperInput - this = "<<this);
367
368   myDeviceActor->SetPipeLine(GetGaussPointsPL());
369   myCurrentPL = myDeviceActor->GetPipeLine();
370
371   myMapper->SetInput(myCurrentPL->GetPickableDataSet());
372   SetMapper(myMapper.GetPointer());
373 }
374
375
376 //----------------------------------------------------------------------------
377 namespace
378 {
379   inline  
380   float 
381   GetRadius(vtkIdType theVTKID,
382             vtkDataArray *theScalarArray,
383             VISU_GaussPointsPL* theGaussPointsPL)
384   {
385     float aRadius = 0.5;
386     if(theGaussPointsPL->GetPSMapper()->GetPointSpriteMode() == 1) // Geometry mode
387       aRadius *= theGaussPointsPL->GetSize() * theGaussPointsPL->GetAverageCellSize();
388     else if(theGaussPointsPL->GetBicolor()){
389       float aVal = theScalarArray->GetTuple1(theVTKID);
390       if(aVal > 0.0)
391         aRadius *= theGaussPointsPL->GetMaxSize();
392       else
393         aRadius *= theGaussPointsPL->GetMinSize();
394       aRadius *= theGaussPointsPL->GetAverageCellSize();
395     }else
396       aRadius *= theGaussPointsPL->GetPointSize(theVTKID,theScalarArray);
397
398     return aRadius;
399   }
400 }
401
402 float
403 VISU_GaussPtsAct
404 ::GetRadius(vtkIdType theObjID,
405             vtkIdType theVTKID,
406             vtkDataArray *theScalarArray)
407 {
408   return ::GetRadius(theVTKID,theScalarArray,myDeviceActor->GetPipeLine());
409 }
410
411 //----------------------------------------------------------------------------
412 float 
413 VISU_GaussPtsAct
414 ::GetMagnification(vtkIdType theObjID)
415 {
416   return myDeviceActor->GetPipeLine()->GetMagnification();
417 }
418
419
420 //----------------------------------------------------------------------------
421 namespace
422 {
423   inline  
424   float 
425   GetClamp(VISU_GaussPointsPL* theGaussPointsPL)
426   {
427     float aClamp = theGaussPointsPL->GetClamp();
428     if(theGaussPointsPL->GetPrimitiveType() == VISU_OpenGLPointSpriteMapper::GeomSphere)
429       return -aClamp;
430     return aClamp;
431   }
432 }
433
434 float 
435 VISU_GaussPtsAct
436 ::GetClamp(vtkIdType theObjID)
437 {
438   return ::GetClamp(myDeviceActor->GetPipeLine());
439 }
440
441
442 //----------------------------------------------------------------------------
443 void
444 VISU_GaussPtsAct
445 ::SetFactory(VISU::TActorFactory* theActorFactory)
446
447   using namespace VISU;
448   myGaussPtsActorFactory = dynamic_cast<TGaussPtsActorFactory*>(theActorFactory);
449   myUpdatePrs3dSignal.connect(boost::bind(&TGaussPtsActorFactory::UpdateFromActor,
450                                           myGaussPtsActorFactory,
451                                           _1));
452   Superclass::SetFactory(theActorFactory);
453 }
454
455 VISU::TGaussPtsActorFactory*
456 VISU_GaussPtsAct
457 ::GetGaussPtsFactory()
458 {
459   return myGaussPtsActorFactory;
460 }
461
462
463 //----------------------------------------------------------------------------
464 void
465 VISU_GaussPtsAct
466 ::SetVisibility(int theMode)
467 {
468   Superclass::SetVisibility(theMode);
469   myScalarBarCtrl->SetVisibility(theMode);
470   Highlight(isHighlighted());
471 }
472
473 int
474 VISU_GaussPtsAct
475 ::IsSegmentationEnabled()
476 {
477   return myWidgetCtrl  && myWidgetCtrl->GetEnabled();
478 }
479
480
481 //----------------------------------------------------------------------------
482 void
483 VISU_GaussPtsAct
484 ::SetBarVisibility(bool theMode)
485 {
486   myBarVisibility = theMode;
487   myScalarBarCtrl->SetCtrlVisibility(theMode); 
488   myScalarBarCtrl->SetVisibility(GetVisibility()); 
489 }
490
491 bool
492 VISU_GaussPtsAct
493 ::GetBarVisibility()
494
495   return myBarVisibility;
496 }
497
498 VISU_ScalarBarCtrl* 
499 VISU_GaussPtsAct
500 ::GetScalarBarCtrl()
501 {
502   return myScalarBarCtrl.GetPointer();
503 }
504
505 //----------------------------------------------------------------------------
506 void
507 VISU_GaussPtsAct
508 ::SetInteractor(vtkRenderWindowInteractor* theInteractor)
509 {
510   if(theInteractor == myInteractor)
511     return;
512
513   if(myInteractor)
514     myInteractor->RemoveObserver(myEventCallbackCommand.GetPointer());
515   
516   if(theInteractor){
517     theInteractor->AddObserver(vtkCommand::CharEvent, 
518                                myEventCallbackCommand.GetPointer(), 
519                                myPriority);
520     theInteractor->AddObserver(VISU::SetSMDecreaseMagnificationEvent, 
521                                myEventCallbackCommand.GetPointer(), 
522                                myPriority);
523     theInteractor->AddObserver(VISU::SetSMIncreaseMagnificationEvent, 
524                                myEventCallbackCommand.GetPointer(), 
525                                myPriority);
526   }
527   Superclass::SetInteractor(theInteractor);
528
529   Modified();
530 }
531 //-------------------------------------------------------------------------
532 void 
533 VISU_GaussPtsAct
534 ::ProcessEvents(vtkObject* vtkNotUsed(theObject), 
535                 unsigned long theEvent,
536                 void* theClientData, 
537                 void* vtkNotUsed(theCallData))
538 {
539   if(vtkObject* anObject = reinterpret_cast<vtkObject*>(theClientData))
540     if(VISU_GaussPtsAct* self = dynamic_cast<VISU_GaussPtsAct*>(anObject)) {
541       if(theEvent == VISU::UpdateInsideSettingsEvent)
542         self->UpdateInsideCursorSettings();
543       else
544         self->OnInteractorEvent(theEvent);
545     }
546 }
547
548 //-------------------------------------------------------------------------
549 void
550 VISU_GaussPtsAct
551 ::OnInteractorEvent(unsigned long theEvent)
552 {
553   switch(theEvent){
554   case vtkCommand::CharEvent: {
555     switch(myInteractor->GetKeyCode()) {
556     case 'M' :
557     case 'm' :
558     {
559       if( IsSegmentationEnabled() )
560       {
561         this->ChangeMagnification( myInteractor->GetShiftKey() );
562         return;
563       }
564
565       myChangeMagnification = myInteractor->GetShiftKey();
566       break;
567     }
568     case 'D' :
569     case 'd' :
570     {
571       if( IsSegmentationEnabled() && myWidgetCtrl->IsSphereActive() )
572       {
573         VISU_SphereWidget* aSphereWidget = myWidgetCtrl->GetSphereWidget();
574         aSphereWidget->ChangeRadius( myInteractor->GetShiftKey() );
575         myWidgetCtrl->InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
576         myWidgetCtrl->GetInteractor()->Render();
577       }
578       return;
579     }
580     default:
581       return;
582     }
583     myUpdatePrs3dSignal(this);
584     break;
585   }
586   case VISU::SetSMDecreaseMagnificationEvent: 
587   case VISU::SetSMIncreaseMagnificationEvent: 
588     myChangeMagnification = theEvent == VISU::SetSMIncreaseMagnificationEvent;
589     myUpdatePrs3dSignal(this);
590     break;
591   case VISU::UpdatePickingSettingsEvent:
592     UpdatePickingSettings();
593     break;
594   case vtkCommand::EndInteractionEvent:
595   case vtkCommand::EnableEvent:
596   case vtkCommand::DisableEvent: 
597     myCurrentPL->GetMapper()->Update();
598     Highlight(isHighlighted());
599     break;
600   default:
601     break;
602   }
603 }
604
605 //----------------------------------------------------------------------------
606 bool VISU_GaussPtsAct::IsInfinitive()
607 {
608   if(vtkMapper* aMapper = myDeviceActor->GetMapper()){
609     if(vtkDataSet* aDataSet= aMapper->GetInput()){
610       aDataSet->Update();
611       myIsInfinite = aDataSet->GetNumberOfCells() < 2;
612     }
613   }
614   return myIsInfinite;
615 }
616
617 //----------------------------------------------------------------------------
618 bool
619 VISU_GaussPtsAct
620 ::PreHighlight(vtkInteractorStyle* theInteractorStyle, 
621                SVTK_SelectionEvent* theSelectionEvent,
622                bool theIsHighlight)
623 {
624   myPreHighlightActor->SetVisibility(false);
625   myCursorPyramid->SetVisibility(false);  
626
627   if (!myBarVisibility) {
628     return false;
629   }
630
631   if(!theIsHighlight)
632     myLastObjPointID = -1;
633
634   Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
635
636   if(aSelectionMode == ActorSelection || !theIsHighlight)
637     return Superclass::PreHighlight(theInteractorStyle,
638                                     theSelectionEvent,
639                                     theIsHighlight);  
640   
641   bool anIsChanged = (mySelectionMode != aSelectionMode);
642   bool anIsPreselected = myIsPreselected;
643   myIsPreselected = false;
644   
645   if(aSelectionMode == GaussPointSelection && theIsHighlight){
646     myPointPicker->Pick(theSelectionEvent->myX, 
647                         theSelectionEvent->myY, 
648                         0.0, 
649                         theInteractorStyle->GetCurrentRenderer());
650     
651     if(myPointPicker->GetActor() != this)
652       return (anIsPreselected != myIsPreselected);
653     
654     vtkIdType aVtkId = myPointPicker->GetPointId();
655     
656     if(aVtkId >= 0 && mySelector->IsValid(this,aVtkId,true) && hasIO()){
657       vtkIdType anObjId = GetNodeObjId( aVtkId );
658       myIsPreselected = (anObjId >= 0);
659       if(myIsPreselected){
660         anIsChanged = (myLastObjPointID != anObjId);
661         if(anIsChanged){
662           float* aNodeCoord = GetNodeCoord(anObjId);
663           vtkDataSet* aDataSet = GetInput();
664           vtkCellData* aCellData = aDataSet->GetCellData();
665           if(vtkDataArray *aScalarArray = aCellData->GetScalars()){
666             float aPyramidHeight = myPickingSettings->GetPyramidHeight();
667             aPyramidHeight = aPyramidHeight*myGaussPointsPL->GetMaxPointSize();
668             //float aColor[3] = myPreHighlightActor->GetProperty()->GetColor();
669             float aColor[3];
670             theInteractorStyle->GetCurrentRenderer()->GetBackground( aColor );
671             aColor[0] = 1. - aColor[0];
672             aColor[1] = 1. - aColor[1];
673             aColor[2] = 1. - aColor[2];
674
675             myCursorPyramid->Init(aPyramidHeight,
676                                   myPickingSettings->GetCursorSize(),
677                                   GetRadius(anObjId,aVtkId,aScalarArray),
678                                   GetMagnification(anObjId),
679                                   GetClamp(anObjId),
680                                   aNodeCoord,
681                                   aColor);
682           }
683           myLastObjPointID = anObjId;
684         }
685         myCursorPyramid->SetVisibility(true);
686       }
687     }
688   }
689   
690   mySelectionMode = aSelectionMode;
691   anIsChanged |= (anIsPreselected != myIsPreselected);
692
693   return anIsChanged;
694 }
695
696
697 //----------------------------------------------------------------------------
698 inline
699 void
700 ChangeZoom(VISU_PickingSettings *thePickingSettings,
701            vtkInteractorStyle* theInteractorStyle,
702            int theInitialHasIndex,
703            SVTK_Selector* theSelector,
704            const Handle(SALOME_InteractiveObject)& theIO)
705 {
706   int aCurrentHasIndex = theSelector->HasIndex(theIO);
707
708   if(theInitialHasIndex + aCurrentHasIndex == 1){
709     vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
710     vtkCamera *aCamera = aRenderer->GetActiveCamera();
711     float aZoomFactor = thePickingSettings->GetZoomFactor();
712     double aScale = aCamera->GetParallelScale();
713     if (!theInitialHasIndex && aCurrentHasIndex) {
714       aCamera->SetParallelScale(aScale/aZoomFactor);
715     }
716     else {
717       aCamera->SetParallelScale(aScale*aZoomFactor);
718     }
719   }
720   
721 }
722
723 bool
724 VISU_GaussPtsAct
725 ::Highlight(vtkInteractorStyle* theInteractorStyle, 
726             SVTK_SelectionEvent* theSelectionEvent,
727             bool theIsHighlight)
728
729   myIsHighlighted = false;
730   Handle(SALOME_InteractiveObject) anIO = getIO();
731   int anInitialHasIndex = mySelector->HasIndex(anIO);
732
733   Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
734   //
735   if(!theIsHighlight && aSelectionMode == GaussPointSelection){
736     mySelector->RemoveIObject(anIO);
737
738     ChangeZoom(myPickingSettings,
739                theInteractorStyle,
740                anInitialHasIndex,
741                mySelector.GetPointer(),
742                anIO);
743
744     return true;
745   }
746   
747   if (!myBarVisibility) {
748     return false;
749   }
750   //
751   if(aSelectionMode == ActorSelection){
752     return Superclass::Highlight(theInteractorStyle,
753                                  theSelectionEvent,
754                                  theIsHighlight);
755   }
756   //
757   if(aSelectionMode == GaussPointSelection && !theSelectionEvent->myIsRectangle){
758
759     vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
760     myPointPicker->Pick(theSelectionEvent->myX, 
761                         theSelectionEvent->myY,
762                         0.0, 
763                         aRenderer);
764
765     if(myPointPicker->GetActor() != this) {
766       mySelector->ClearIObjects();
767
768       ChangeZoom(myPickingSettings,
769                  theInteractorStyle,
770                  anInitialHasIndex,
771                  mySelector.GetPointer(),
772                  anIO);
773
774       return true;
775     }
776
777     vtkIdType aVtkId = myPointPicker->GetPointId();
778     if( aVtkId >= 0  && mySelector->IsValid( this, aVtkId, true ) && hasIO()) {
779       vtkIdType anObjId = GetNodeObjId( aVtkId );
780       if(anObjId >= 0){
781         myIsHighlighted = true;
782         // Update the Selector
783         if(mySelector->IsSelected(myIO))
784           mySelector->AddOrRemoveIndex(myIO,anObjId,theSelectionEvent->myIsShift);
785         else{
786           if(!theSelectionEvent->myIsShift){
787             mySelector->ClearIObjects();
788           }
789           mySelector->AddOrRemoveIndex(myIO,anObjId,theSelectionEvent->myIsShift);
790           mySelector->AddIObject(this);
791         }
792         //
793         float* aNodeCoord = GetNodeCoord(anObjId);
794         //
795         // FlyTo
796         vtkRenderWindowInteractor* anInteractor = theInteractorStyle->GetInteractor();
797         float aDollyWas = anInteractor->GetDolly();
798         int aNumberOfFlyFramesWas = anInteractor->GetNumberOfFlyFrames();
799         
800         anInteractor->SetDolly(0.);
801         anInteractor->SetNumberOfFlyFrames(myPickingSettings->GetStepNumber());
802         anInteractor->FlyTo(aRenderer,aNodeCoord);
803         aRenderer->ResetCameraClippingRange();
804         anInteractor->SetDolly(aDollyWas);
805         anInteractor->SetNumberOfFlyFrames(aNumberOfFlyFramesWas);
806         
807         mySelectionMode = aSelectionMode;
808
809         ChangeZoom(myPickingSettings,
810                    theInteractorStyle,
811                    anInitialHasIndex,
812                    mySelector.GetPointer(),
813                    anIO);
814
815         return true;
816         //
817       }// if( anObjId >= 0 ) {
818     }//if( aVtkId >= 0  && mySelector->IsValid( this, aVtkId, true ) && hasIO()) 
819   }//if(!theSelectionEvent->myIsRectangle){
820
821   ChangeZoom(myPickingSettings,
822              theInteractorStyle,
823              anInitialHasIndex,
824              mySelector.GetPointer(),
825              anIO);
826   
827   return false;
828 }
829
830 //==================================================================
831 // function : Highlight
832 // purpose  :
833 //==================================================================
834 void
835 VISU_GaussPtsAct
836 ::Highlight(bool theIsHighlight)
837 {
838   if(!mySelector.GetPointer())
839     return;
840
841   myOutlineActor->SetVisibility(false);
842   myTextActor->SetVisibility(false);
843   myCursorPyramidSelected->SetVisibility(false);
844   myCursorPyramid->SetVisibility(false);
845   myCellActor->SetVisibility(false);
846   GetScalarBarCtrl()->SetIsMarked(false);
847   GetScalarBarCtrl()->Update();
848
849   if(!theIsHighlight)
850     return;
851
852   bool anIsVisible = GetVisibility();
853
854   Selection_Mode aSelectionMode = mySelector->SelectionMode();
855
856   if(aSelectionMode == ActorSelection)
857     Superclass::highlight(theIsHighlight);
858   else if(aSelectionMode != GaussPointSelection)
859     return;
860
861   TColStd_IndexedMapOfInteger aMapIndex;
862   mySelector->GetIndex( getIO(), aMapIndex );
863   if(aMapIndex.Extent() != 1 || !myBarVisibility) {
864     return;
865   }
866   //
867   std::ostringstream aStr;
868   int anObjId = aMapIndex(1);
869   aStr<<"Global ID: "<<anObjId;
870   //
871   vtkIdType aVtkId = GetNodeVTKID(anObjId);
872   if(aVtkId >= 0){
873     float *aNodeCoord = GetNodeCoord(anObjId);
874     float aWorldCoord[4] = {aNodeCoord[0], aNodeCoord[1], aNodeCoord[2], 1.};
875     //
876     vtkDataSet* aDataSet = GetInput();
877     vtkCellData* aDataSetAttributes = aDataSet->GetCellData();
878     //
879     if(vtkDataArray* aScalarArray = aDataSetAttributes->GetScalars()){
880       float aVal = aScalarArray->GetTuple1(aVtkId);
881       //
882       GetScalarBarCtrl()->SetIsMarked(true);
883       GetScalarBarCtrl()->SetMarkValue(aVal);
884       GetScalarBarCtrl()->Update();
885       //
886       float aPyramidHeight = myPickingSettings->GetPyramidHeight();
887       aPyramidHeight = aPyramidHeight*myGaussPointsPL->GetMaxPointSize();
888       myCursorPyramidSelected->Init(aPyramidHeight,
889                                     myPickingSettings->GetCursorSize(),
890                                     GetRadius(anObjId,aVtkId,aScalarArray),
891                                     GetMagnification(anObjId),
892                                     GetClamp(anObjId),
893                                     aNodeCoord,
894                                     myHighlightActor->GetProperty()->GetColor());
895       myCursorPyramidSelected->SetVisibility(anIsVisible && theIsHighlight);
896       //
897       const VISU::PGaussPtsIDMapper& aGaussPtsIDMapper = 
898         myGaussPointsPL->GetGaussPtsIDMapper();
899       VISU::TNamedIDMapper* aParent = aGaussPtsIDMapper->GetParent();
900       
901       VISU::TGaussPointID aGaussPointID = myGaussPointsPL->GetObjID(anObjId);
902       VISU::TCellID aCellID = aGaussPointID.first;
903       VISU::TLocalPntID aLocalPntID = aGaussPointID.second;
904       aStr<<"\nParentCellID: "<<aCellID;
905       std::string aParentName = aParent->GetElemName(aCellID);
906       if(aParentName != "") {
907         aStr<<"\nParentCellName: '"<<aParentName<<"'";
908       }
909       aStr<<"\nLocalPntID: "<<aLocalPntID;
910       aStr<<"\nScalar: "<<aVal;
911     }
912
913     if(vtkDataArray* aFieldArray = aDataSetAttributes->GetArray("VISU_FIELD")){
914       if(vtkFloatArray *aFloatArray = dynamic_cast<vtkFloatArray*>(aFieldArray)){
915         int aNbComp = aFloatArray->GetNumberOfComponents();
916         aStr<<"\nData: {";
917         int anId = 0;
918         while(anId < aNbComp){
919           float aComp = aFloatArray->GetComponent(aVtkId,anId++);
920           aStr<<aComp;
921           if(anId < aNbComp)
922             aStr<<"; ";
923         }
924         aStr<<"}";
925       }
926     }
927     //
928     // myTextActor
929     std::string aString = aStr.str();
930     myTextActor->SetModePosition(myPickingSettings->GetInfoWindowPosition());
931     myTextActor->SetTransparency(myPickingSettings->GetInfoWindowTransparency());
932     myTextActor->SetWorldPoint(aWorldCoord);
933     myTextActor->SetText(aString.c_str());
934     myTextActor->SetVisibility(anIsVisible && theIsHighlight);
935     //
936     // myCellActor
937     if(myPickingSettings->GetDisplayParentMesh()){
938       const VISU::PGaussPtsIDMapper& aGaussPtsIDMapper = 
939         myGaussPointsPL->GetGaussPtsIDMapper();
940       VISU::TNamedIDMapper* aParent = aGaussPtsIDMapper->GetParent();
941       
942       myCellSource->Reset();
943       myCellSource->Modified(); // a VTK bug
944       myCellSource->SetPoints(aParent->GetVTKOutput()->GetPoints());
945       
946       VISU::TGaussPointID aGaussPointID = aGaussPtsIDMapper->GetObjID(anObjId);
947       vtkIdType aCellID = aGaussPointID.first;
948       vtkCell* aCell = aParent->GetElemCell(aCellID);
949       myCellSource->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
950       myCellActor->SetVisibility(anIsVisible && theIsHighlight);
951       myCellActor->SetRepresentation(VTK_WIREFRAME);
952     }
953   }
954 }
955
956
957 //----------------------------------------------------------------
958 void
959 VISU_GaussPtsAct
960 ::SetPickingSettings(VISU_PickingSettings* thePickingSettings)
961 {
962   if(myPickingSettings == thePickingSettings)
963     return;
964
965   if(myPickingSettings)
966     myPickingSettings->RemoveObserver(myEventCallbackCommand.GetPointer());
967
968   myPickingSettings = thePickingSettings;
969
970   if(thePickingSettings)
971   {
972     thePickingSettings->AddObserver(VISU::UpdatePickingSettingsEvent, 
973                                     myEventCallbackCommand.GetPointer(), 
974                                     myPriority);
975     this->UpdatePickingSettings();
976   }
977 }
978
979 void
980 VISU_GaussPtsAct
981 ::UpdatePickingSettings()
982 {
983   if(!myPickingSettings || myPickingSettings->GetInitial())
984     return;
985
986   myTextActor->SetModePosition(myPickingSettings->GetInfoWindowPosition());
987   myTextActor->SetTransparency(myPickingSettings->GetInfoWindowTransparency());
988
989   float aHeight = myGaussPointsPL->GetMaxPointSize()*myPickingSettings->GetPyramidHeight();
990   float aCursorSize = myPickingSettings->GetCursorSize();
991   myCursorPyramid->SetPreferences(aHeight,aCursorSize);
992   myCursorPyramidSelected->SetPreferences(aHeight,aCursorSize);
993
994   myHighlightActor->GetProperty()->SetColor( myPickingSettings->GetColor() );
995   myPointPicker->SetTolerance( myPickingSettings->GetPointTolerance() );
996
997   Highlight(isHighlighted());
998
999   Update();
1000 }
1001
1002 //----------------------------------------------------------------
1003 void
1004 VISU_GaussPtsAct
1005 ::SetInsideCursorSettings(VISU_InsideCursorSettings* theInsideCursorSettings)
1006 {
1007   if(myInsideCursorSettings == theInsideCursorSettings)
1008     return;
1009
1010   if(myInsideCursorSettings)
1011     myInsideCursorSettings->RemoveObserver(myEventCallbackCommand.GetPointer());
1012
1013   myInsideCursorSettings = theInsideCursorSettings;
1014
1015   if(theInsideCursorSettings){
1016     theInsideCursorSettings->AddObserver(VISU::UpdateInsideSettingsEvent, 
1017                                          myEventCallbackCommand.GetPointer(), 
1018                                          myPriority);
1019     UpdateInsideCursorSettings();
1020   }
1021 }
1022
1023 void
1024 VISU_GaussPtsAct
1025 ::UpdateInsideCursorSettings()
1026 {
1027   UpdateInsideCursorSettings( myDeviceActor );
1028 }
1029
1030 void
1031 VISU_GaussPtsAct
1032 ::UpdateInsideCursorSettings( PDeviceActor theActor )
1033 {
1034   if(!myInsideCursorSettings || myInsideCursorSettings->GetInitial())
1035     return;
1036
1037   VISU_GaussPointsPL* aPipeline = theActor->GetPipeLine();
1038
1039   SALOME_ExtractGeometry* anExtractGeometry = aPipeline->GetExtractGeometryFilter();
1040   vtkImplicitFunction* anImplicitFunction = anExtractGeometry->GetImplicitFunction();
1041
1042   aPipeline->ShallowCopy(GetGaussPointsPL());
1043
1044   aPipeline->SetImplicitFunction(anImplicitFunction); // To restore
1045
1046   aPipeline->SetPrimitiveType( myInsideCursorSettings->GetPrimitiveType() );
1047   aPipeline->SetClamp( myInsideCursorSettings->GetClamp() );
1048   aPipeline->SetImageData( myInsideCursorSettings->GetTexture() );
1049   aPipeline->SetAlphaThreshold( myInsideCursorSettings->GetAlphaThreshold() );
1050   aPipeline->SetResolution( myInsideCursorSettings->GetResolution() );
1051   aPipeline->SetMinSize( myInsideCursorSettings->GetMinSize() );
1052   aPipeline->SetMaxSize( myInsideCursorSettings->GetMaxSize() );
1053   aPipeline->SetMagnification( myInsideCursorSettings->GetMagnification() );
1054   aPipeline->SetMagnificationIncrement( myInsideCursorSettings->GetIncrement() );
1055
1056   if( myInsideCursorSettings->GetPrimitiveType() != VISU_OpenGLPointSpriteMapper::GeomSphere )
1057     theActor->GetProperty()->SetRepresentation( VTK_POINTS );
1058   else
1059     theActor->GetProperty()->SetRepresentation( VTK_SURFACE );
1060
1061   aPipeline->Update();
1062
1063   Highlight(isHighlighted());
1064
1065   Update();
1066 }
1067
1068 //==============================================================================
1069 vtkStandardNewMacro(VISU_GaussPtsAct1);
1070
1071
1072 //----------------------------------------------------------------------------
1073 VISU_GaussPtsAct1
1074 ::VISU_GaussPtsAct1():
1075   myInsideDeviceActor(VISU_GaussPtsDeviceActor::New()),
1076   myOutsideDeviceActor(VISU_GaussPtsDeviceActor::New()),
1077   myOutsideCursorSettings(NULL)
1078 {
1079   if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::VISU_GaussPtsAct1 - this = "<<this);
1080
1081   myEventCallbackCommand->SetCallback(VISU_GaussPtsAct1::ProcessEvents);
1082
1083   myInsideDeviceActor->SetVisibility(false);
1084   myInsideDeviceActor->SetPickable(false);
1085   myInsideDeviceActor->Delete();
1086
1087   myOutsideDeviceActor->SetVisibility(false);
1088   myOutsideDeviceActor->SetPickable(false);
1089   myOutsideDeviceActor->Delete();
1090 }
1091
1092 VISU_GaussPtsAct1
1093 ::~VISU_GaussPtsAct1()
1094 {
1095   if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::~VISU_GaussPtsAct1 - this = "<<this);
1096
1097   SetOutsideCursorSettings(NULL);
1098 }
1099
1100
1101 //----------------------------------------------------------------------------
1102 void
1103 VISU_GaussPtsAct1
1104 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
1105 {
1106   if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::ShallowCopyPL - this = "<<this);
1107
1108   Superclass::ShallowCopyPL(thePipeLine);
1109
1110   UpdateOutsideCursorSettings();
1111 }
1112
1113
1114 //----------------------------------------------------------------------------
1115 void
1116 VISU_GaussPtsAct1
1117 ::AddToRender(vtkRenderer* theRenderer)
1118 {
1119   Superclass::AddToRender(theRenderer);
1120
1121   myInsideDeviceActor->AddToRender(theRenderer);
1122   myOutsideDeviceActor->AddToRender(theRenderer);
1123 }
1124
1125 void 
1126 VISU_GaussPtsAct1
1127 ::RemoveFromRender(vtkRenderer* theRenderer)
1128 {
1129   Superclass::RemoveFromRender(theRenderer);
1130
1131   myInsideDeviceActor->RemoveFromRender(theRenderer);
1132   myOutsideDeviceActor->RemoveFromRender(theRenderer);
1133 }
1134
1135 void 
1136 VISU_GaussPtsAct1
1137 ::SetTransform(VTKViewer_Transform* theTransform)
1138 {
1139   Superclass::SetTransform(theTransform);
1140
1141   myInsideDeviceActor->SetTransform(theTransform);
1142   myOutsideDeviceActor->SetTransform(theTransform);
1143 }
1144
1145
1146 //----------------------------------------------------------------------------
1147 void
1148 VISU_GaussPtsAct1
1149 ::SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl)
1150 {
1151   if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::SetWidgetCtrl - this = "<<this);
1152
1153   if(myWidgetCtrl == theWidgetCtrl){
1154     return;
1155   }
1156
1157   if(myWidgetCtrl){
1158     myInsideDeviceActor->GetPipeLine()->SetImplicitFunction(NULL);
1159     myInsideDeviceActor->SetVisibility(false);
1160
1161     myOutsideDeviceActor->GetPipeLine()->SetImplicitFunction(NULL);  
1162     myOutsideDeviceActor->SetVisibility(false);
1163   }
1164
1165   Superclass::SetWidgetCtrl(theWidgetCtrl);
1166
1167   if(theWidgetCtrl){
1168     myInsideDeviceActor->GetPipeLine()->SetImplicitFunction(theWidgetCtrl->ImplicitFunction());
1169     myInsideDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1170
1171     myOutsideDeviceActor->GetPipeLine()->SetImplicitFunction(theWidgetCtrl->ImplicitFunction());  
1172     myOutsideDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1173   }
1174 }
1175
1176
1177 //----------------------------------------------------------------------------
1178 void
1179 VISU_GaussPtsAct1
1180 ::SetMapperInput(vtkDataSet* theDataSet) 
1181 {
1182   if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::SetMapperInput - this = "<<this);
1183
1184   Superclass::SetMapperInput(theDataSet);
1185
1186   if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
1187     myInsideDeviceActor->SetPipeLine(aPipeLine);
1188     aPipeLine->Delete();
1189   }
1190
1191   if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
1192     myOutsideDeviceActor->SetPipeLine(aPipeLine);
1193     aPipeLine->Delete();
1194
1195     SALOME_ExtractGeometry* anExtractGeometry = aPipeLine->GetExtractGeometryFilter();
1196     anExtractGeometry->SetExtractBoundaryCells(true);
1197     anExtractGeometry->SetExtractInside(true);
1198   }
1199 }
1200
1201
1202 //----------------------------------------------------------------------------
1203 float
1204 VISU_GaussPtsAct1
1205 ::GetRadius(vtkIdType theObjID,
1206             vtkIdType theVTKID,
1207             vtkDataArray *theScalarArray)
1208 {
1209   VISU_GaussPointsPL* aPipeLine = myDeviceActor->GetPipeLine();
1210   if(IsSegmentationEnabled()){
1211     if(myInsideDeviceActor->GetPipeLine()->GetNodeVTKID(theObjID) < 0)
1212       aPipeLine = myOutsideDeviceActor->GetPipeLine();
1213     else
1214       aPipeLine = myInsideDeviceActor->GetPipeLine();
1215   }
1216   return ::GetRadius(theVTKID,theScalarArray,aPipeLine);
1217 }
1218
1219
1220 //----------------------------------------------------------------------------
1221 float 
1222 VISU_GaussPtsAct1
1223 ::GetMagnification(vtkIdType theObjID)
1224 {
1225   VISU_GaussPointsPL* aPipeLine = myDeviceActor->GetPipeLine();
1226   if(IsSegmentationEnabled()){
1227     if(myInsideDeviceActor->GetPipeLine()->GetNodeVTKID(theObjID) < 0)
1228       aPipeLine = myOutsideDeviceActor->GetPipeLine();
1229     else
1230       aPipeLine = myInsideDeviceActor->GetPipeLine();
1231   }
1232   return aPipeLine->GetMagnification();
1233 }
1234
1235
1236 //----------------------------------------------------------------------------
1237 float 
1238 VISU_GaussPtsAct1
1239 ::GetClamp(vtkIdType theObjID)
1240 {
1241   if(IsSegmentationEnabled()){
1242     if(myInsideDeviceActor->GetPipeLine()->GetNodeVTKID(theObjID) < 0)
1243       return ::GetClamp(myOutsideDeviceActor->GetPipeLine());
1244     else
1245       return ::GetClamp(myInsideDeviceActor->GetPipeLine());
1246   }
1247   return Superclass::GetClamp(theObjID);
1248 }
1249
1250
1251 //----------------------------------------------------------------
1252 void 
1253 VISU_GaussPtsAct1
1254 ::Connect(VISU_GaussPtsAct2* theActor)
1255 {
1256   mySetVisibilitySignal.connect(boost::bind(&VISU_GaussPtsAct2::SetVisibility,theActor,_1));
1257 }
1258
1259 void
1260 VISU_GaussPtsAct1
1261 ::SetVisibility(int theMode)
1262 {
1263   if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::SetVisibility - this = "<<this);
1264
1265   Superclass::SetVisibility(theMode);
1266
1267   bool aVisisbility = GetVisibility();
1268   bool anIsSegementation = IsSegmentationEnabled();
1269   myDeviceActor->SetVisibility(aVisisbility && !anIsSegementation);
1270   myInsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1271   myOutsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1272
1273   mySetVisibilitySignal(GetVisibility());
1274 }
1275
1276 //----------------------------------------------------------------
1277 void
1278 VISU_GaussPtsAct1
1279 ::UpdateInsideCursorSettings()
1280 {
1281   Superclass::UpdateInsideCursorSettings( myInsideDeviceActor );
1282 }
1283
1284 //----------------------------------------------------------------
1285 void
1286 VISU_GaussPtsAct1
1287 ::SetOutsideCursorSettings(VISU_OutsideCursorSettings* theOutsideCursorSettings)
1288 {
1289   if(myOutsideCursorSettings == theOutsideCursorSettings)
1290     return;
1291
1292   if(myOutsideCursorSettings)
1293     myOutsideCursorSettings->RemoveObserver(myEventCallbackCommand.GetPointer());
1294
1295   myOutsideCursorSettings = theOutsideCursorSettings;
1296
1297   if(theOutsideCursorSettings)
1298   {
1299     theOutsideCursorSettings->AddObserver(VISU::UpdateOutsideSettingsEvent, 
1300                                           myEventCallbackCommand.GetPointer(), 
1301                                           myPriority);
1302     UpdateOutsideCursorSettings();
1303   }
1304 }
1305
1306 void
1307 VISU_GaussPtsAct1
1308 ::UpdateOutsideCursorSettings()
1309 {
1310   if(!myOutsideCursorSettings || myOutsideCursorSettings->GetInitial())
1311     return;
1312
1313   VISU_GaussPointsPL* aPipeline = myOutsideDeviceActor->GetPipeLine();
1314
1315   SALOME_ExtractGeometry* anExtractGeometry = aPipeline->GetExtractGeometryFilter();
1316   vtkImplicitFunction* anImplicitFunction = anExtractGeometry->GetImplicitFunction();
1317   float aMagnification = aPipeline->GetMagnification();
1318
1319   aPipeline->ShallowCopy(GetGaussPointsPL());
1320
1321   aPipeline->SetImplicitFunction(anImplicitFunction); // To restore
1322   anExtractGeometry->SetExtractBoundaryCells(true);
1323   anExtractGeometry->SetExtractInside(true);
1324   aPipeline->SetMagnification( aMagnification );
1325
1326   aPipeline->SetPrimitiveType( myOutsideCursorSettings->GetPrimitiveType() );
1327
1328   if( myOutsideCursorSettings->GetPrimitiveType() != VISU_OpenGLPointSpriteMapper::GeomSphere )
1329     myOutsideDeviceActor->GetProperty()->SetRepresentation( VTK_POINTS );
1330   else
1331     myOutsideDeviceActor->GetProperty()->SetRepresentation( VTK_SURFACE );
1332
1333   aPipeline->SetClamp( myOutsideCursorSettings->GetClamp() );
1334   aPipeline->SetImageData( myOutsideCursorSettings->GetTexture() );
1335   aPipeline->SetAlphaThreshold( myOutsideCursorSettings->GetAlphaThreshold() );
1336   aPipeline->SetResolution( myOutsideCursorSettings->GetResolution() );
1337   aPipeline->SetSize( myOutsideCursorSettings->GetSize() );
1338   aPipeline->SetMagnification( myOutsideCursorSettings->GetMagnification() );
1339   aPipeline->SetMagnificationIncrement( myOutsideCursorSettings->GetIncrement() );
1340
1341   if( myOutsideCursorSettings->GetUniform() )
1342   {
1343     myOutsideDeviceActor->GetPSMapper()->ScalarVisibilityOff();
1344     myOutsideDeviceActor->GetPSMapper()->SetPointSpriteMode( 1 ); // Geometry mode
1345     myOutsideDeviceActor->GetProperty()->SetColor( myOutsideCursorSettings->GetColor() );
1346   }
1347   else
1348   {
1349     myOutsideDeviceActor->GetPSMapper()->SetPointSpriteMode( 2 ); // Outside cursor mode
1350     myOutsideDeviceActor->GetPSMapper()->SetColorModeToMapScalars();
1351     myOutsideDeviceActor->GetPSMapper()->ScalarVisibilityOn();
1352   }
1353
1354   aPipeline->Update();
1355
1356   Highlight(isHighlighted());
1357
1358   Update();
1359 }
1360
1361
1362 //----------------------------------------------------------------
1363 void 
1364 VISU_GaussPtsAct1
1365 ::ProcessEvents(vtkObject* theObject, 
1366                 unsigned long theEvent,
1367                 void* theClientData, 
1368                 void* theCallData)
1369 {
1370   if(vtkObject* anObject = reinterpret_cast<vtkObject*>(theClientData))
1371     if(VISU_GaussPtsAct1* self = dynamic_cast<VISU_GaussPtsAct1*>(anObject))
1372       if(theEvent == VISU::UpdateOutsideSettingsEvent)
1373         self->UpdateOutsideCursorSettings();
1374
1375   Superclass::ProcessEvents(theObject,theEvent,theClientData,theCallData);
1376 }
1377
1378 void
1379 VISU_GaussPtsAct1
1380 ::OnInteractorEvent(unsigned long theEvent)
1381 {
1382   switch(theEvent){
1383   case vtkCommand::StartInteractionEvent: 
1384     myDeviceActor->SetVisibility(GetVisibility());
1385     myInsideDeviceActor->SetVisibility(false);
1386     myOutsideDeviceActor->SetVisibility(false);
1387     break;
1388   case vtkCommand::EnableEvent: 
1389   case vtkCommand::DisableEvent:
1390   case vtkCommand::EndInteractionEvent: {
1391     bool aVisisbility = GetVisibility();
1392     bool anIsSegementation = IsSegmentationEnabled();
1393     myDeviceActor->SetVisibility(aVisisbility && !anIsSegementation);
1394     myInsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1395     myOutsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1396     break;
1397   }
1398   default:
1399     break;
1400   }
1401   
1402   Superclass::OnInteractorEvent(theEvent);
1403 }
1404
1405
1406 //==============================================================================
1407 vtkStandardNewMacro(VISU_GaussPtsAct2);
1408
1409
1410 //----------------------------------------------------------------------------
1411 VISU_GaussPtsAct2
1412 ::VISU_GaussPtsAct2()
1413 {
1414   if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::VISU_GaussPtsAct2 - this = "<<this);
1415   myDeviceActor->SetVisibility(false);
1416 }
1417
1418 VISU_GaussPtsAct2
1419 ::~VISU_GaussPtsAct2()
1420 {
1421   if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::~VISU_GaussPtsAct2 - this = "<<this);
1422 }
1423
1424
1425 //----------------------------------------------------------------------------
1426 void
1427 VISU_GaussPtsAct2
1428 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
1429 {
1430   if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::ShallowCopyPL - this = "<<this);
1431
1432   Superclass::ShallowCopyPL(thePipeLine);
1433 }
1434
1435
1436 //----------------------------------------------------------------------------
1437 void
1438 VISU_GaussPtsAct2
1439 ::SetMapperInput(vtkDataSet* theDataSet) 
1440 {
1441   if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::SetMapperInput - this = "<<this);
1442
1443   if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
1444     myDeviceActor->SetPipeLine(aPipeLine);
1445     myCurrentPL = aPipeLine;
1446     aPipeLine->Delete();
1447
1448     myMapper->SetInput(myCurrentPL->GetPickableDataSet());
1449     SetMapper(myMapper.GetPointer());
1450   }
1451 }
1452
1453 //----------------------------------------------------------------------------
1454 void
1455 VISU_GaussPtsAct2
1456 ::SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl)
1457 {
1458   if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::SetWidgetCtrl - this = "<<this);
1459
1460   if(myWidgetCtrl == theWidgetCtrl)
1461     return;
1462
1463   if(myWidgetCtrl){
1464     theWidgetCtrl->RemoveObserver(myEventCallbackCommand.GetPointer());
1465     myDeviceActor->GetPipeLine()->SetImplicitFunction(NULL);
1466     myDeviceActor->SetVisibility(false);
1467   }
1468
1469   Superclass::SetWidgetCtrl(theWidgetCtrl);
1470
1471   if(theWidgetCtrl){
1472     myDeviceActor->GetPipeLine()->SetImplicitFunction(theWidgetCtrl->ImplicitFunction());
1473     myDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1474   }
1475 }
1476
1477
1478 //----------------------------------------------------------------------------
1479 void
1480 VISU_GaussPtsAct2
1481 ::SetVisibility(int theMode)
1482 {
1483   if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::SetVisibility - this = "<<this);
1484
1485   Superclass::SetVisibility(theMode);
1486
1487   myDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1488 }
1489
1490 void
1491 VISU_GaussPtsAct2
1492 ::OnInteractorEvent(unsigned long theEvent)
1493 {
1494   switch(theEvent){
1495   case vtkCommand::EnableEvent: 
1496   case vtkCommand::DisableEvent:
1497     myDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1498     if(theEvent == vtkCommand::EnableEvent)
1499       Update();
1500     break;
1501   case vtkCommand::EndInteractionEvent:
1502     Update();
1503     break;
1504   default:
1505     break;
1506   }
1507   Superclass::OnInteractorEvent(theEvent);
1508 }