2 #include "OCCViewer_ViewModel.h"
3 #include "OCCViewer_ViewWindow.h"
4 #include "OCCViewer_VService.h"
5 #include "OCCViewer_ViewPort3d.h"
7 #include "SUIT_ViewWindow.h"
8 #include "SUIT_Desktop.h"
9 #include "SUIT_Session.h"
12 #include <qapplication.h>
13 #include <qcolordialog.h>
15 #include <qpopupmenu.h>
17 #include <AIS_Axis.hxx>
18 #include <AIS_Drawer.hxx>
19 #include <AIS_ListIteratorOfListOfInteractive.hxx>
21 #include <Geom_Axis2Placement.hxx>
22 #include <Prs3d_DatumAspect.hxx>
23 #include <Prs3d_LineAspect.hxx>
25 OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron )
28 // init CasCade viewers
29 myV3dViewer = OCCViewer_VService::Viewer3d( "", (short*) "Viewer3d", "", 1000.,
30 V3d_XposYnegZpos, true, true );
34 myV3dCollector = OCCViewer_VService::Viewer3d( "", (short*) "Collector3d", "", 1000.,
35 V3d_XposYnegZpos, true, true );
36 myV3dCollector->Init();
39 myAISContext = new AIS_InteractiveContext( myV3dViewer, myV3dCollector);
43 /* create trihedron */
44 if( DisplayTrihedron )
46 Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(gp::XOY());
47 myTrihedron = new AIS_Trihedron(anAxis);
48 myTrihedron->SetInfiniteState( Standard_True );
50 Quantity_Color Col(193/255., 205/255., 193/255., Quantity_TOC_RGB);
51 //myTrihedron->SetColor( Col );
52 myTrihedron->SetArrowColor( Col.Name() );
53 myTrihedron->SetSize(100);
54 Handle(AIS_Drawer) drawer = myTrihedron->Attributes();
55 if (drawer->HasDatumAspect()) {
56 Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect();
57 daspect->FirstAxisAspect()->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB));
58 daspect->SecondAxisAspect()->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB));
59 daspect->ThirdAxisAspect()->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB));
62 myAISContext->Display(myTrihedron);
63 myAISContext->Deactivate(myTrihedron);
67 mySelectionEnabled = true;
68 myMultiSelectionEnabled = true;
72 OCCViewer_Viewer::~OCCViewer_Viewer()
77 SUIT_ViewWindow* OCCViewer_Viewer::createView(SUIT_Desktop* theDesktop)
79 OCCViewer_ViewWindow* res = new OCCViewer_ViewWindow(theDesktop, this);
84 //*********************************************************************
85 void OCCViewer_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
87 SUIT_ViewModel::setViewManager(theViewManager);
89 connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
90 this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
92 connect(theViewManager, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)),
93 this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
95 connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
96 this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
101 //*********************************************************************
102 void OCCViewer_Viewer::onMousePress(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
104 myStartPnt.setX(theEvent->x()); myStartPnt.setY(theEvent->y());
108 //*********************************************************************
109 void OCCViewer_Viewer::onMouseMove(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
111 if (!mySelectionEnabled) return;
112 if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
114 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
115 myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView->getViewPort()->getView());
119 //*********************************************************************
120 void OCCViewer_Viewer::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
122 if (!mySelectionEnabled) return;
123 if (theEvent->button() != Qt::LeftButton) return;
124 if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
127 myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y());
128 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
129 bool aHasShift = (theEvent->state() & Qt::ShiftButton);
131 if (myStartPnt == myEndPnt)
133 if (aHasShift && myMultiSelectionEnabled)
134 myAISContext->ShiftSelect();
136 myAISContext->Select();
140 if (aHasShift && myMultiSelectionEnabled)
141 myAISContext->ShiftSelect(myStartPnt.x(), myStartPnt.y(),
142 myEndPnt.x(), myEndPnt.y(),
143 aView->getViewPort()->getView(), Standard_False );
145 myAISContext->Select(myStartPnt.x(), myStartPnt.y(),
146 myEndPnt.x(), myEndPnt.y(),
147 aView->getViewPort()->getView(), Standard_False );
149 int Nb = myAISContext->NbSelected();
150 if( Nb>1 && !myMultiSelectionEnabled )
152 myAISContext->InitSelected();
153 Handle( SelectMgr_EntityOwner ) anOwner = myAISContext->SelectedOwner();
154 if( !anOwner.IsNull() )
156 myAISContext->ClearSelected( Standard_False );
157 myAISContext->AddOrRemoveSelected( anOwner, Standard_False );
161 myAISContext->UpdateCurrentViewer();
163 emit selectionChanged();
167 //*********************************************************************
168 void OCCViewer_Viewer::enableSelection(bool isEnabled)
170 mySelectionEnabled = isEnabled;
171 //!! To be done for view windows
174 //*********************************************************************
175 void OCCViewer_Viewer::enableMultiselection(bool isEnable)
177 myMultiSelectionEnabled = isEnable;
178 //!! To be done for view windows
181 //*********************************************************************
182 void OCCViewer_Viewer::contextMenuPopup(QPopupMenu* thePopup)
184 thePopup->insertItem( tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
185 thePopup->insertItem( tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBgColor() ) );
187 thePopup->insertSeparator();
189 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
190 if ( aView && !aView->getToolBar()->isVisible() )
191 thePopup->insertItem( tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) );
194 void OCCViewer_Viewer::onDumpView()
196 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
201 //*********************************************************************
202 void OCCViewer_Viewer::onChangeBgColor()
204 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
207 OCCViewer_ViewPort3d* aViewPort3d = aView->getViewPort();
210 QColor aColorActive = aViewPort3d->backgroundColor();
212 QColor selColor = QColorDialog::getColor( aColorActive, aView);
213 if ( selColor.isValid() )
214 aViewPort3d->setBackgroundColor(selColor);
217 //*********************************************************************
218 void OCCViewer_Viewer::onShowToolbar() {
219 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
221 aView->getToolBar()->show();
224 //*********************************************************************
225 void OCCViewer_Viewer::update()
227 if (!myV3dViewer.IsNull())
228 myV3dViewer->Update();
231 //*********************************************************************
232 void OCCViewer_Viewer::getSelectedObjects(AIS_ListOfInteractive& theList)
235 for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
236 theList.Append(myAISContext->SelectedInteractive());
239 //*********************************************************************
240 void OCCViewer_Viewer::setObjectsSelected(const AIS_ListOfInteractive& theList)
242 AIS_ListIteratorOfListOfInteractive aIt;
243 for (aIt.Initialize(theList); aIt.More(); aIt.Next())
244 myAISContext->SetSelected(aIt.Value(), false);
245 myAISContext->UpdateCurrentViewer();
248 //*********************************************************************
249 void OCCViewer_Viewer::performSelectionChanged()
251 emit selectionChanged();
254 //****************************************************************
256 void OCCViewer_Viewer::onClearViewAspects()
261 //****************************************************************
263 void OCCViewer_Viewer::clearViewAspects()
265 myViewAspects.clear();
268 //****************************************************************
270 const viewAspectList& OCCViewer_Viewer::getViewAspects()
272 return myViewAspects;
275 //****************************************************************
277 void OCCViewer_Viewer::appendViewAspect( const viewAspect& aParams )
279 myViewAspects.append( aParams );
282 //****************************************************************
284 void OCCViewer_Viewer::updateViewAspects( const viewAspectList& aViewList )
286 myViewAspects = aViewList;
289 bool OCCViewer_Viewer::highlight( const Handle(AIS_InteractiveObject)& obj,
290 bool hilight, bool update )
292 bool isInLocal = myAISContext->HasOpenedContext();
296 if ( hilight && !myAISContext->IsSelected( obj ) )
297 myAISContext->AddOrRemoveCurrentObject( obj, false );
298 else if ( !hilight && myAISContext->IsSelected( obj ) )
299 myAISContext->AddOrRemoveCurrentObject( obj, false );
303 myV3dViewer->Redraw();
308 bool OCCViewer_Viewer::unHighlightAll( bool updateviewer )
310 if ( myAISContext->HasOpenedContext() )
311 myAISContext->ClearSelected( updateviewer );
313 myAISContext->ClearCurrents( updateviewer );
317 bool OCCViewer_Viewer::isInViewer( const Handle(AIS_InteractiveObject)& obj,
320 AIS_ListOfInteractive List;
321 myAISContext->DisplayedObjects(List);
325 AIS_ListOfInteractive List1;
326 myAISContext->ObjectsInCollector(List1);
330 AIS_ListIteratorOfListOfInteractive ite(List);
331 for ( ; ite.More(); ite.Next() )
332 if( ite.Value()==obj )
338 bool OCCViewer_Viewer::isVisible( const Handle(AIS_InteractiveObject)& obj )
340 return myAISContext->IsDisplayed( obj );
343 void OCCViewer_Viewer::setColor( const Handle(AIS_InteractiveObject)& obj,
349 Quantity_Color CSFColor = Quantity_Color ( color.red() / 255.,
350 color.green() / 255.,
353 obj->SetColor( CSFColor );
357 myV3dViewer->Update();
360 void OCCViewer_Viewer::switchRepresentation( const Handle(AIS_InteractiveObject)& obj,
361 int mode, bool update )
363 myAISContext->SetDisplayMode( obj, (Standard_Integer)mode, true );
365 myV3dViewer->Update();
368 void OCCViewer_Viewer::setTransparency( const Handle(AIS_InteractiveObject)& obj,
369 float trans, bool update )
371 myAISContext->SetTransparency( obj, trans, false );
372 myAISContext->Redisplay( obj, Standard_False, Standard_True );
374 myV3dViewer->Update();
377 //****************************************************************
378 void OCCViewer_Viewer::toggleTrihedron()
380 if (myTrihedron.IsNull()) return;
381 if (myAISContext->IsDisplayed(myTrihedron)) {
382 myAISContext->Erase(myTrihedron);
384 myAISContext->Display(myTrihedron);