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 = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
105 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
106 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
107 if ( aSelMgr && appStudy ) {
108 aSelMgr->selectedObjects( selected );
109 if ( !selected.IsEmpty() ) {
110 _PTR(Study) aStudy = appStudy->studyDS();
112 bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
114 SUIT_MessageBox::warning ( app->desktop(),
115 QObject::tr("WRN_WARNING"),
116 QObject::tr("WRN_STUDY_LOCKED"),
117 QObject::tr("BUT_OK") );
121 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
122 Handle(SALOME_InteractiveObject) IObject = It.Value();
124 _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
125 _PTR(GenericAttribute) anAttr;
127 if( obj->FindAttribute(anAttr, "AttributeName") ) {
128 _PTR(AttributeName) aName (anAttr);
130 QString newName = LightApp_NameDlg::getName( app->desktop(), aName->Value().c_str() );
131 if ( !newName.isEmpty() ) {
132 aName->SetValue( newName.toLatin1().constData() ); // rename the SObject
133 IObject->setName( newName.toLatin1() );// rename the InteractiveObject
134 // Rename the corresponding GEOM_Object
135 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
136 if (!CORBA::is_nil( anObj ))
137 anObj->SetName( newName.toLatin1() );
138 (dynamic_cast<SalomeApp_Module*>(app->activeModule()))->updateObjBrowser( false );
140 } // if ( name attribute )
147 app->updateActions(); //SRN: To update a Save button in the toolbar
150 void GEOMToolsGUI::OnCheckGeometry()
152 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
153 PyConsole_Console* pyConsole = app->pythonConsole();
156 pyConsole->exec("from GEOM_usinggeom import *");
159 void GEOMToolsGUI::OnAutoColor()
161 QList<SALOME_Prs> aListOfGroups;
163 SALOME_ListIO selected;
164 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
168 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
169 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
170 if( !aSelMgr || !appStudy )
173 aSelMgr->selectedObjects( selected );
174 if( selected.IsEmpty() )
177 Handle(SALOME_InteractiveObject) anIObject = selected.First();
179 _PTR(Study) aStudy = appStudy->studyDS();
180 _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
181 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
182 if( CORBA::is_nil( aMainObject ) )
185 aMainObject->SetAutoColor( true );
187 QList<SALOMEDS::Color> aReservedColors;
189 GEOM_Displayer aDisp (appStudy);
191 SALOME_View* vf = aDisp.GetActiveView();
193 SUIT_ViewWindow* window = app->desktop()->activeWindow();
194 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
195 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
197 for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
199 _PTR(SObject) aChildSObject( it->Value() );
200 GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
201 if( CORBA::is_nil( aChildObject ) )
204 if( aChildObject->GetType() != GEOM_GROUP )
207 SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
208 aChildObject->SetColor( aColor );
209 aReservedColors.append( aColor );
211 QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
213 SALOME_Prs* aPrs = vf->CreatePrs( aChildSObject->GetID().c_str() );
217 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
220 SVTK_View* aView = vtkVW->getView();
221 SUIT_OverrideCursor();
222 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() )
223 aView->SetColor( It.Value(), c );
227 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
228 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
230 SOCC_Prs* anOCCPrs = dynamic_cast<SOCC_Prs*>( aPrs );
234 AIS_ListOfInteractive aList;
235 anOCCPrs->GetObjects( aList );
236 if( !aList.Extent() )
239 Handle(AIS_InteractiveObject) io = aList.First();
243 Quantity_Color aQuanColor( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
245 // Set color for a point
246 Handle(AIS_Drawer) aCurDrawer = io->Attributes();
247 Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
248 Quantity_Color aCurColor;
249 Standard_Real aCurScale;
250 Aspect_TypeOfMarker aCurTypeOfMarker;
251 aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
252 aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aQuanColor, aCurScale) );
253 ic->SetLocalAttributes( io, aCurDrawer );
255 io->SetColor( aQuanColor );
256 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
257 Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aQuanColor );
259 io->Redisplay( Standard_True );
263 app->updateActions(); //SRN: To update a Save button in the toolbar
266 void GEOMToolsGUI::OnDisableAutoColor()
268 SALOME_ListIO selected;
269 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
273 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
274 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
275 if( !aSelMgr || !appStudy )
278 aSelMgr->selectedObjects( selected );
279 if( selected.IsEmpty() )
282 Handle(SALOME_InteractiveObject) anIObject = selected.First();
284 _PTR(Study) aStudy = appStudy->studyDS();
285 _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
286 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
287 if( CORBA::is_nil( aMainObject ) )
290 aMainObject->SetAutoColor( false );
294 void GEOMToolsGUI::OnColor()
296 SALOME_ListIO selected;
297 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
298 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
299 if ( app && appStudy ) {
300 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
302 aSelMgr->selectedObjects( selected );
303 if ( !selected.IsEmpty() ) {
304 SUIT_ViewWindow* window = app->desktop()->activeWindow();
305 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
306 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
308 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
311 SVTK_View* aView = vtkVW->getView();
312 QColor initcolor = aView->GetColor( selected.First() );
313 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
315 SUIT_OverrideCursor();
316 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
317 aView->SetColor( It.Value(), c );
322 Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
323 if ( !io.IsNull() ) {
324 Quantity_Color aColor;
326 QColor initcolor( (int)( aColor.Red() * 255.0 ), (int)( aColor.Green() * 255.0 ), (int)( aColor.Blue() * 255.0 ) );
327 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
329 SUIT_OverrideCursor();
330 aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
331 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
332 io = GEOMBase::GetAIS( It.Value(), true );
333 if ( !io.IsNull() ) {
334 // Set color for a point
335 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
336 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
337 Handle(AIS_Drawer) aCurDrawer = io->Attributes();
338 Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
339 Quantity_Color aCurColor;
340 Standard_Real aCurScale;
341 Aspect_TypeOfMarker aCurTypeOfMarker;
342 aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
343 aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aColor, aCurScale) );
344 ic->SetLocalAttributes(io, aCurDrawer);
346 io->SetColor( aColor );
347 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
348 Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aColor );
350 io->Redisplay( Standard_True );
352 // store color to GEOM_Object
353 _PTR(Study) aStudy = appStudy->studyDS();
354 _PTR(SObject) aSObject( aStudy->FindObjectID( It.Value()->getEntry() ) );
355 GEOM::GEOM_Object_var anObject =
356 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObject));
358 SALOMEDS::Color aSColor;
359 aSColor.R = (double)c.red() / 255.0;
360 aSColor.G = (double)c.green() / 255.0;
361 aSColor.B = (double)c.blue() / 255.0;
362 anObject->SetColor( aSColor );
363 anObject->SetAutoColor( false );
367 } // first IO is not null
369 } // if ( selection not empty )
373 app->updateActions(); //SRN: To update a Save button in the toolbar
376 void GEOMToolsGUI::OnTransparency()
378 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
382 void GEOMToolsGUI::OnNbIsos()
384 SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
386 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
387 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
389 if(isOCC){ // if is OCCViewer
391 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
392 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
395 if ( ic->MoreCurrent() ) {
396 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
397 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
399 int UIso = CurDrawer->UIsoAspect()->Number();
400 int VIso = CurDrawer->VIsoAspect()->Number();
402 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
403 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
405 NbIsosDlg->setU( UIso );
406 NbIsosDlg->setV( VIso );
408 if ( NbIsosDlg->exec() ) {
409 SUIT_OverrideCursor();
410 for(; ic->MoreCurrent(); ic->NextCurrent()) {
411 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
412 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
414 int nbUIso = NbIsosDlg->getU();
415 int nbVIso = NbIsosDlg->getV();
417 CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbUIso) );
418 CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbVIso) );
420 ic->SetLocalAttributes(CurObject, CurDrawer);
421 ic->Redisplay(CurObject);
426 else if(isVTK){ // if is VTKViewer
428 // Warning. It's works incorrect. must be recheked.
430 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
433 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
436 SALOME_ListIO selected;
437 aSelMgr->selectedObjects( selected );
438 if ( selected.IsEmpty() )
441 Handle(SALOME_InteractiveObject) FirstIOS = selected.First();
442 if ( FirstIOS.IsNull() )
445 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
449 SVTK_View* aView = vtkVW->getView();
450 vtkActorCollection* aCollection = aView->getRenderer()->GetActors();
455 aCollection->InitTraversal();
458 vtkActor *anAct = aCollection->GetNextActor();
459 if(GEOM_Actor *anActor = dynamic_cast<GEOM_Actor*>(anAct)){
460 anActor->GetNbIsos(UIso,VIso);
463 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
464 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
466 NbIsosDlg->setU( UIso );
467 NbIsosDlg->setV( VIso );
469 if ( NbIsosDlg->exec() ) {
470 SUIT_OverrideCursor();
472 while(anAct = aCollection->GetNextActor()) {
473 if(GEOM_Actor *anActor = dynamic_cast<GEOM_Actor*>(anAct)){
474 // There are no casting to needed actor.
475 UIso = NbIsosDlg->getU();
476 VIso = NbIsosDlg->getV();
477 int aIsos[2]={UIso,VIso};
478 anActor->SetNbIsos(aIsos);
485 void GEOMToolsGUI::OnOpen()
488 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
489 _PTR(Study) aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
491 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
492 Handle(SALOME_InteractiveObject) anIObject;
493 for(;It.More();It.Next()) {
494 anIObject = It.Value();
495 _PTR(SObject) obj ( aStudy->FindObjectID(anIObject->getEntry()) );
496 _PTR(AttributePersistentRef) aPersist;
497 _PTR(AttributeIOR) anIOR;
499 // this SObject may be GEOM module root SObject
500 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator() );
501 _PTR(GenericAttribute) anAttr;
502 bool useSubItems = false;
503 while (anIter->More() && !useSubItems) {
504 _PTR(SObject) subobj ( anIter->Value() );
505 if (subobj->FindAttribute(anAttr, "AttributePersistentRef")) {
512 obj->FindAttribute(anAttr, "AttributePersistentRef");
514 while(useSubItems?anIter->More():!anAttr->_is_nil()) {
515 if(!obj->FindAttribute(anAttr, "AttributeIOR") &&
516 obj->FindAttribute(anAttr, "AttributePersistentRef")) {
517 _PTR(SComponent) FComp ( obj->GetFatherComponent() );
519 if (FComp->FindAttribute(anAttr, "AttributeName")) {
520 _PTR(AttributeName) aName ( anAttr );
521 QString compName = QAD_Application::getDesktop()->getComponentName(aName->Value().c_str());
522 // parent->loadComponentData(parent->getComponentName(aName->Value()));
523 Engines::Component_var comp ;
524 if ( compName.compare("SUPERV") == 0 ) {
525 comp = QAD_Application::getDesktop()->getEngine( "SuperVisionContainer", compName) ;
528 comp = QAD_Application::getDesktop()->getEngine( "FactoryServer", compName);
529 if ( comp->_is_nil() )
530 comp = QAD_Application::getDesktop()->getEngine( "FactoryServerPy", compName);
533 if (!CORBA::is_nil(comp)) {
534 SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
535 if (!CORBA::is_nil(driver)) {
536 SALOMEDS::StudyBuilder_var B = dynamic_cast<SALOMEDS_Study*>(aStudy.get())->GetStudy()->NewBuilder();
537 if (!CORBA::is_nil(B)) {
538 B->LoadWith(FComp,driver);
544 MESSAGE("loadComponentData(): Driver is null");
549 MESSAGE("loadComponentData(): Engine is null");
553 // Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer","GEOM");
554 // if (!CORBA::is_nil(comp)) {
555 // SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
556 // SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
557 // SALOMEDS::SComponent_var SC = aStudy->FindComponent("GEOM");
558 // if (!CORBA::is_nil(SC))
559 // aStudyBuilder->LoadWith(SC,driver);
563 MESSAGE("Component is null");
568 obj.reset( anIter->Value() );
578 void GEOMToolsGUI::OnSelectOnly(int mode)
580 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
582 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
583 GEOM_Displayer aDisp (appStudy);
584 aDisp.GlobalSelection(mode);
585 getGeometryGUI()->setLocalSelectionMode(mode);