1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2004 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : GEOMToolsGUI_1.cxx
23 // Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
26 #include <PyConsole_Console.h>
28 #include "GEOMToolsGUI.h"
29 #include "GEOMToolsGUI_TransparencyDlg.h"
30 #include "GEOMToolsGUI_NbIsosDlg.h"
32 #include <GeometryGUI.h>
33 #include <GEOM_Displayer.h>
36 #include <GEOM_Actor.h>
38 #include <SALOME_ListIO.hxx>
39 #include <SALOME_ListIteratorOfListIO.hxx>
44 #include <SVTK_ViewModel.h>
45 #include <SVTK_ViewWindow.h>
46 #include <SVTK_View.h>
48 #include <OCCViewer_ViewModel.h>
50 #include <SUIT_ViewManager.h>
51 #include <SUIT_Desktop.h>
52 #include <SUIT_ResourceMgr.h>
53 #include <SUIT_Session.h>
54 #include <SUIT_OverrideCursor.h>
55 #include <SUIT_MessageBox.h>
57 #include <SalomeApp_Application.h>
58 #include <SalomeApp_Study.h>
59 #include <SalomeApp_Module.h>
61 #include <LightApp_SelectionMgr.h>
62 #include <LightApp_NameDlg.h>
64 #include <GEOMImpl_Types.hxx>
66 #include "utilities.h"
69 #include <AIS_Drawer.hxx>
70 #include <Prs3d_IsoAspect.hxx>
71 #include <Prs3d_PointAspect.hxx>
72 #include <Graphic3d_AspectMarker3d.hxx>
75 #include <QColorDialog>
79 #include <vtkRenderer.h>
81 void GEOMToolsGUI::OnSettingsColor()
83 SUIT_Session* sess = SUIT_Session::session();
84 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
85 SUIT_Desktop* desk = sess->activeApplication()->desktop();
87 QColor anInitColor = resMgr->colorValue( "Geometry", "SettingsShadingColor", QColor( "yellow" ) );
89 QColor aDialogColor = QColorDialog::getColor(anInitColor, desk );
90 if( aDialogColor.isValid() )
92 QString type = desk->activeWindow()->getViewManager()->getType();
93 if( type != OCCViewer_Viewer::Type() && type != SVTK_Viewer::Type() )
94 MESSAGE("Settings Color is not supported for current Viewer");
96 resMgr->setValue( "Geometry", "SettingsShadingColor", aDialogColor );
100 void GEOMToolsGUI::OnRename()
102 SALOME_ListIO selected;
103 SalomeApp_Application* app =
104 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
106 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
107 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
108 if ( aSelMgr && appStudy ) {
109 aSelMgr->selectedObjects( selected );
110 if ( !selected.IsEmpty() ) {
111 _PTR(Study) aStudy = appStudy->studyDS();
113 bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
115 SUIT_MessageBox::warning ( app->desktop(),
116 QObject::tr("WRN_WARNING"),
117 QObject::tr("WRN_STUDY_LOCKED") );
121 bool isAny = false; // is there any appropriate object selected
122 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
123 Handle(SALOME_InteractiveObject) IObject = It.Value();
125 _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
126 _PTR(GenericAttribute) anAttr;
128 if ( obj->FindAttribute(anAttr, "AttributeName") ) {
129 _PTR(AttributeName) aName (anAttr);
131 GEOM::GEOM_Object_var anObj =
132 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
133 if (!CORBA::is_nil(anObj)) {
135 QString newName = LightApp_NameDlg::getName( app->desktop(), aName->Value().c_str() );
136 if (!newName.isEmpty()) {
137 aName->SetValue( newName.toLatin1().data() ); // rename the SObject
138 IObject->setName( newName.toLatin1().data() );// rename the InteractiveObject
139 anObj->SetName( newName.toLatin1().data() ); // Rename the corresponding GEOM_Object
140 (dynamic_cast<SalomeApp_Module*>(app->activeModule()))->updateObjBrowser( false );
143 } // if ( name attribute )
148 SUIT_MessageBox::warning( app->desktop(),
149 QObject::tr("WRN_WARNING"),
150 QObject::tr("GEOM_WRN_NO_APPROPRIATE_SELECTION") );
157 app->updateActions(); //SRN: To update a Save button in the toolbar
160 void GEOMToolsGUI::OnCheckGeometry()
162 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
163 PyConsole_Console* pyConsole = app->pythonConsole();
166 pyConsole->exec("from GEOM_usinggeom import *");
169 void GEOMToolsGUI::OnAutoColor()
171 QList<SALOME_Prs> aListOfGroups;
173 SALOME_ListIO selected;
174 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
178 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
179 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
180 if( !aSelMgr || !appStudy )
183 aSelMgr->selectedObjects( selected );
184 if( selected.IsEmpty() )
187 Handle(SALOME_InteractiveObject) anIObject = selected.First();
189 _PTR(Study) aStudy = appStudy->studyDS();
190 _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
191 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
192 if( CORBA::is_nil( aMainObject ) )
195 aMainObject->SetAutoColor( true );
197 QList<SALOMEDS::Color> aReservedColors;
199 GEOM_Displayer aDisp (appStudy);
201 SALOME_View* vf = aDisp.GetActiveView();
203 SUIT_ViewWindow* window = app->desktop()->activeWindow();
204 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
205 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
207 for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
209 _PTR(SObject) aChildSObject( it->Value() );
210 GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
211 if( CORBA::is_nil( aChildObject ) )
214 if( aChildObject->GetType() != GEOM_GROUP )
217 SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
218 aChildObject->SetColor( aColor );
219 aReservedColors.append( aColor );
221 QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
223 SALOME_Prs* aPrs = vf->CreatePrs( aChildSObject->GetID().c_str() );
227 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
230 SVTK_View* aView = vtkVW->getView();
231 SUIT_OverrideCursor();
232 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() )
233 aView->SetColor( It.Value(), c );
237 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
238 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
240 SOCC_Prs* anOCCPrs = dynamic_cast<SOCC_Prs*>( aPrs );
244 AIS_ListOfInteractive aList;
245 anOCCPrs->GetObjects( aList );
246 if( !aList.Extent() )
249 Handle(AIS_InteractiveObject) io = aList.First();
253 Quantity_Color aQuanColor( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
255 // Set color for a point
256 Handle(AIS_Drawer) aCurDrawer = io->Attributes();
257 Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
258 Quantity_Color aCurColor;
259 Standard_Real aCurScale;
260 Aspect_TypeOfMarker aCurTypeOfMarker;
261 aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
262 aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aQuanColor, aCurScale) );
263 ic->SetLocalAttributes( io, aCurDrawer );
265 io->SetColor( aQuanColor );
266 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
267 Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aQuanColor );
269 io->Redisplay( Standard_True );
273 app->updateActions(); //SRN: To update a Save button in the toolbar
276 void GEOMToolsGUI::OnDisableAutoColor()
278 SALOME_ListIO selected;
279 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
283 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
284 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
285 if( !aSelMgr || !appStudy )
288 aSelMgr->selectedObjects( selected );
289 if( selected.IsEmpty() )
292 Handle(SALOME_InteractiveObject) anIObject = selected.First();
294 _PTR(Study) aStudy = appStudy->studyDS();
295 _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
296 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
297 if( CORBA::is_nil( aMainObject ) )
300 aMainObject->SetAutoColor( false );
304 void GEOMToolsGUI::OnColor()
306 SALOME_ListIO selected;
307 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
308 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
309 if ( app && appStudy ) {
310 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
312 aSelMgr->selectedObjects( selected );
313 if ( !selected.IsEmpty() ) {
314 SUIT_ViewWindow* window = app->desktop()->activeWindow();
315 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
316 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
318 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
321 SVTK_View* aView = vtkVW->getView();
322 QColor initcolor = aView->GetColor( selected.First() );
323 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
325 SUIT_OverrideCursor();
326 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
327 aView->SetColor( It.Value(), c );
332 Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
333 if ( !io.IsNull() ) {
334 Quantity_Color aColor;
336 QColor initcolor( (int)( aColor.Red() * 255.0 ), (int)( aColor.Green() * 255.0 ), (int)( aColor.Blue() * 255.0 ) );
337 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
339 SUIT_OverrideCursor();
340 aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
341 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
342 io = GEOMBase::GetAIS( It.Value(), true );
343 if ( !io.IsNull() ) {
344 // Set color for a point
345 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
346 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
347 Handle(AIS_Drawer) aCurDrawer = io->Attributes();
348 Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
349 Quantity_Color aCurColor;
350 Standard_Real aCurScale;
351 Aspect_TypeOfMarker aCurTypeOfMarker;
352 aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
353 aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aColor, aCurScale) );
354 ic->SetLocalAttributes(io, aCurDrawer);
356 io->SetColor( aColor );
357 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
358 Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aColor );
360 io->Redisplay( Standard_True );
362 // store color to GEOM_Object
363 _PTR(Study) aStudy = appStudy->studyDS();
364 _PTR(SObject) aSObject( aStudy->FindObjectID( It.Value()->getEntry() ) );
365 GEOM::GEOM_Object_var anObject =
366 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObject));
368 SALOMEDS::Color aSColor;
369 aSColor.R = (double)c.red() / 255.0;
370 aSColor.G = (double)c.green() / 255.0;
371 aSColor.B = (double)c.blue() / 255.0;
372 anObject->SetColor( aSColor );
373 anObject->SetAutoColor( false );
377 } // first IO is not null
379 } // if ( selection not empty )
383 app->updateActions(); //SRN: To update a Save button in the toolbar
386 void GEOMToolsGUI::OnTransparency()
388 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
392 void GEOMToolsGUI::OnNbIsos()
394 SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
396 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
397 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
399 if(isOCC){ // if is OCCViewer
401 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
402 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
405 if ( ic->MoreCurrent() ) {
406 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
407 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
409 int UIso = CurDrawer->UIsoAspect()->Number();
410 int VIso = CurDrawer->VIsoAspect()->Number();
412 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
413 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
415 NbIsosDlg->setU( UIso );
416 NbIsosDlg->setV( VIso );
418 if ( NbIsosDlg->exec() ) {
419 SUIT_OverrideCursor();
420 for(; ic->MoreCurrent(); ic->NextCurrent()) {
421 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
422 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
424 int nbUIso = NbIsosDlg->getU();
425 int nbVIso = NbIsosDlg->getV();
427 CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbUIso) );
428 CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbVIso) );
430 ic->SetLocalAttributes(CurObject, CurDrawer);
431 ic->Redisplay(CurObject);
436 else if(isVTK){ // if is VTKViewer
438 // Warning. It's works incorrect. must be recheked.
440 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
443 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
446 SALOME_ListIO selected;
447 aSelMgr->selectedObjects( selected );
448 if ( selected.IsEmpty() )
451 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
455 SALOME_View* view = GEOM_Displayer::GetActiveView();
457 vtkActorCollection* aCollection = vtkActorCollection::New();
459 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
460 Handle(SALOME_InteractiveObject) anIObject = It.Value();
461 SALOME_Prs* aPrs = view->CreatePrs( anIObject->getEntry() );
462 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( aPrs );
464 vtkActorCollection* anActors = vtkPrs->GetObjects();
465 anActors->InitTraversal();
466 vtkActor* anAct = anActors->GetNextActor();
467 aCollection->AddItem(anAct);
472 aCollection->InitTraversal();
479 vtkActor* anAct = aCollection->GetNextActor();
480 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
481 anActor->GetNbIsos(UIso,VIso);
485 GEOMToolsGUI_NbIsosDlg* NbIsosDlg =
486 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
488 NbIsosDlg->setU( UIso );
489 NbIsosDlg->setV( VIso );
491 if ( NbIsosDlg->exec() ) {
492 SUIT_OverrideCursor();
494 while( anAct!=NULL ) {
495 if(GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)){
496 // There are no casting to needed actor.
497 UIso = NbIsosDlg->getU();
498 VIso = NbIsosDlg->getV();
499 int aIsos[2]={UIso,VIso};
500 anActor->SetNbIsos(aIsos);
502 anAct = aCollection->GetNextActor();
508 void GEOMToolsGUI::OnOpen()
511 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
512 _PTR(Study) aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
514 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
515 Handle(SALOME_InteractiveObject) anIObject;
516 for(;It.More();It.Next()) {
517 anIObject = It.Value();
518 _PTR(SObject) obj ( aStudy->FindObjectID(anIObject->getEntry()) );
519 _PTR(AttributePersistentRef) aPersist;
520 _PTR(AttributeIOR) anIOR;
522 // this SObject may be GEOM module root SObject
523 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator() );
524 _PTR(GenericAttribute) anAttr;
525 bool useSubItems = false;
526 while (anIter->More() && !useSubItems) {
527 _PTR(SObject) subobj ( anIter->Value() );
528 if (subobj->FindAttribute(anAttr, "AttributePersistentRef")) {
535 obj->FindAttribute(anAttr, "AttributePersistentRef");
537 while(useSubItems?anIter->More():!anAttr->_is_nil()) {
538 if(!obj->FindAttribute(anAttr, "AttributeIOR") &&
539 obj->FindAttribute(anAttr, "AttributePersistentRef")) {
540 _PTR(SComponent) FComp ( obj->GetFatherComponent() );
542 if (FComp->FindAttribute(anAttr, "AttributeName")) {
543 _PTR(AttributeName) aName ( anAttr );
544 QString compName = QAD_Application::getDesktop()->getComponentName(aName->Value().c_str());
545 // parent->loadComponentData(parent->getComponentName(aName->Value()));
546 Engines::Component_var comp ;
547 if ( compName.compare("SUPERV") == 0 ) {
548 comp = QAD_Application::getDesktop()->getEngine( "SuperVisionContainer", compName) ;
551 comp = QAD_Application::getDesktop()->getEngine( "FactoryServer", compName);
552 if ( comp->_is_nil() )
553 comp = QAD_Application::getDesktop()->getEngine( "FactoryServerPy", compName);
556 if (!CORBA::is_nil(comp)) {
557 SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
558 if (!CORBA::is_nil(driver)) {
559 SALOMEDS::StudyBuilder_var B = dynamic_cast<SALOMEDS_Study*>(aStudy.get())->GetStudy()->NewBuilder();
560 if (!CORBA::is_nil(B)) {
561 B->LoadWith(FComp,driver);
567 MESSAGE("loadComponentData(): Driver is null");
572 MESSAGE("loadComponentData(): Engine is null");
576 // Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer","GEOM");
577 // if (!CORBA::is_nil(comp)) {
578 // SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
579 // SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
580 // SALOMEDS::SComponent_var SC = aStudy->FindComponent("GEOM");
581 // if (!CORBA::is_nil(SC))
582 // aStudyBuilder->LoadWith(SC,driver);
586 MESSAGE("Component is null");
591 obj.reset( anIter->Value() );
601 void GEOMToolsGUI::OnSelectOnly(int mode)
603 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
605 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
606 GEOM_Displayer aDisp (appStudy);
607 aDisp.GlobalSelection(mode);
608 getGeometryGUI()->setLocalSelectionMode(mode);