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
24 // File : GEOMToolsGUI_1.cxx
25 // Author : Sergey ANIKIN
29 #include <PythonConsole_PyConsole.h>
31 #include "GEOMToolsGUI.h"
33 #include "GeometryGUI.h"
34 #include "GEOMToolsGUI_TransparencyDlg.h"
35 #include "GEOMToolsGUI_NbIsosDlg.h" // Method ISOS adjustement
37 #include "GEOM_Actor.h"
40 #include "SALOME_ListIO.hxx"
41 #include "SALOME_ListIteratorOfListIO.hxx"
43 #include <SVTK_ViewModel.h>
44 #include <SVTK_ViewWindow.h>
45 #include <SVTK_View.h>
47 #include <OCCViewer_ViewModel.h>
48 #include <OCCViewer_ViewWindow.h>
50 #include <SUIT_ViewManager.h>
51 #include <SUIT_Application.h>
52 #include <SUIT_Desktop.h>
53 #include <SUIT_ResourceMgr.h>
54 #include <SUIT_Session.h>
55 #include <SUIT_OverrideCursor.h>
56 #include <SUIT_MessageBox.h>
58 #include <SalomeApp_Application.h>
59 #include <SalomeApp_Study.h>
60 #include <SalomeApp_Module.h>
62 #include <LightApp_SelectionMgr.h>
63 #include <LightApp_NameDlg.h>
65 #include "SALOMEDSClient.hxx"
67 #include "utilities.h"
70 #include <AIS_Drawer.hxx>
71 #include <AIS_ListOfInteractive.hxx>
72 #include <AIS_ListIteratorOfListOfInteractive.hxx>
73 #include <Prs3d_IsoAspect.hxx>
76 #include <vtkBMPReader.h>
77 #include <vtkTexture.h>
78 #include <vtkTextureMapToPlane.h>
79 #include <vtkTransformTextureCoords.h>
80 #include <vtkDataSetMapper.h>
81 #include <vtkRenderer.h>
84 #include <qfileinfo.h>
85 #include <qcolordialog.h>
87 #include <qapplication.h>
92 void GEOMToolsGUI::OnSettingsColor()
94 SUIT_Session* sess = SUIT_Session::session();
95 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
96 SUIT_Desktop* desk = sess->activeApplication()->desktop();
98 QColor anInitColor = resMgr->colorValue( "Geometry", "SettingsShadingColor", QColor( "yellow" ) );
100 QColor aDialogColor = QColorDialog::getColor(anInitColor, desk );
101 if( aDialogColor.isValid() )
103 QString type = desk->activeWindow()->getViewManager()->getType();
104 if( type != OCCViewer_Viewer::Type() && type != SVTK_Viewer::Type() )
105 MESSAGE("Settings Color is not supported for current Viewer");
107 resMgr->setValue( "Geometry", "SettingsShadingColor", aDialogColor );
111 void GEOMToolsGUI::OnSettingsIsos()
114 SUIT_Session* sess = SUIT_Session::session();
115 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
116 SUIT_Desktop* desk = sess->activeApplication()->desktop();
118 SUIT_ViewManager* vman = desk->activeWindow()->getViewManager();
119 QString type = vman->getType();
121 if ( type != OCCViewer_Viewer::Type() )
124 OCCViewer_Viewer* vm = (OCCViewer_Viewer*)vman->getViewModel();
125 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
127 int IsoU = resMgr->integerValue( "Geometry:SettingsIsoU", 1 );
128 int IsoV = resMgr->integerValue( "Geometry:SettingsIsoV", 1 );
130 ic->DefaultDrawer()->UIsoAspect()->SetNumber( IsoU );
131 ic->DefaultDrawer()->VIsoAspect()->SetNumber( IsoV );
133 GEOMBase_NbIsosDlg* NbIsosDlg = new GEOMBase_NbIsosDlg(desk, tr("GEOM_MEN_ISOS"), TRUE);
135 NbIsosDlg->SpinBoxU->setValue(IsoU);
136 NbIsosDlg->SpinBoxV->setValue(IsoV);
138 if(NbIsosDlg->exec()) {
139 IsoU = NbIsosDlg->SpinBoxU->text().toInt();
140 IsoV = NbIsosDlg->SpinBoxV->text().toInt();
142 ic->DefaultDrawer()->UIsoAspect()->SetNumber(UIso);
143 ic->DefaultDrawer()->VIsoAspect()->SetNumber(VIso);
144 resMgr->setValue("Geometry:SettingsIsoU", isoU);
145 resMgr->setValue("Geometry:SettingsIsoV", isoV);
150 void GEOMToolsGUI::OnSettingsStep()
152 SUIT_Session* sess = SUIT_Session::session();
153 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
155 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100. );
157 Standard_Boolean res = false;
158 double dd = GEOMBase::Parameter( res, QString("%1").arg(step), tr("GEOM_MEN_STEP_LABEL"), tr("GEOM_STEP_TITLE"), 0.001, 10000.0, 3);
160 resMgr->setValue( "Geometry", "SettingsGeomStep", dd );
162 /* Emit signal to GeometryGUI_SpinBoxes */
163 getGeometryGUI()->EmitSignalDefaultStepValueChanged( dd );
166 sess->activeApplication()->putInfo(tr("GEOM_PRP_ABORT"));
169 void GEOMToolsGUI::OnRename()
171 SALOME_ListIO selected;
172 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
174 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
175 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
176 if ( aSelMgr && appStudy ) {
177 aSelMgr->selectedObjects( selected );
178 if ( !selected.IsEmpty() ) {
179 _PTR(Study) aStudy = appStudy->studyDS();
181 bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
183 SUIT_MessageBox::warn1 ( app->desktop(),
184 QObject::tr("WRN_WARNING"),
185 QObject::tr("WRN_STUDY_LOCKED"),
186 QObject::tr("BUT_OK") );
190 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
191 Handle(SALOME_InteractiveObject) IObject = It.Value();
193 _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
194 _PTR(GenericAttribute) anAttr;
196 if( obj->FindAttribute(anAttr, "AttributeName") ) {
197 _PTR(AttributeName) aName (anAttr);
199 QString newName = LightApp_NameDlg::getName( app->desktop(), aName->Value().c_str() );
200 if ( !newName.isEmpty() ) {
201 aName->SetValue( newName.latin1() ); // rename the SObject
202 IObject->setName( newName.latin1() );// rename the InteractiveObject
203 (dynamic_cast<SalomeApp_Module*>(app->activeModule()))->updateObjBrowser( false );
205 } // if ( name attribute )
212 app->updateActions(); //SRN: To update a Save button in the toolbar
215 void GEOMToolsGUI::OnCheckGeometry()
217 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
218 PythonConsole* pyConsole = app->pythonConsole();
221 pyConsole->exec("from GEOM_usinggeom import *");
224 void GEOMToolsGUI::OnColor()
226 SALOME_ListIO selected;
227 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
229 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
231 aSelMgr->selectedObjects( selected );
232 if ( !selected.IsEmpty() ) {
233 SUIT_ViewWindow* window = app->desktop()->activeWindow();
234 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
235 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
237 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
240 SVTK_View* aView = vtkVW->getView();
241 QColor initcolor = aView->GetColor( selected.First() );
242 QColor c = QColorDialog::getColor( QColor(), app->desktop() );
244 SUIT_OverrideCursor();
245 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
246 aView->SetColor( It.Value(), c );
251 Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
252 if ( !io.IsNull() ) {
253 Quantity_Color aColor;
255 QColor initcolor( (int)( aColor.Red() * 255.0 ), (int)( aColor.Green() * 255.0 ), (int)( aColor.Blue() * 255.0 ) );
256 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
258 SUIT_OverrideCursor();
259 aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
260 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
261 io = GEOMBase::GetAIS( It.Value(), true );
262 if ( !io.IsNull() ) {
263 io->SetColor( aColor );
264 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
265 Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aColor );
267 io->Redisplay( Standard_True );
271 } // first IO is not null
273 } // if ( selection not empty )
277 app->updateActions(); //SRN: To update a Save button in the toolbar
280 void GEOMToolsGUI::OnTransparency()
282 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
286 void GEOMToolsGUI::OnNbIsos()
288 SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
289 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
294 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
295 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
298 if ( ic->MoreCurrent() ) {
299 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
300 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
302 int UIso = CurDrawer->UIsoAspect()->Number();
303 int VIso = CurDrawer->VIsoAspect()->Number();
305 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
306 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
308 NbIsosDlg->setU( UIso );
309 NbIsosDlg->setV( VIso );
311 if ( NbIsosDlg->exec() ) {
312 SUIT_OverrideCursor();
313 for(; ic->MoreCurrent(); ic->NextCurrent()) {
314 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
315 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
317 int nbUIso = NbIsosDlg->getU();
318 int nbVIso = NbIsosDlg->getV();
320 CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbUIso) );
321 CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbVIso) );
323 ic->SetLocalAttributes(CurObject, CurDrawer);
324 ic->Redisplay(CurObject);
330 void GEOMToolsGUI::OnOpen()
333 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
334 _PTR(Study) aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
336 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
337 Handle(SALOME_InteractiveObject) anIObject;
338 for(;It.More();It.Next()) {
339 anIObject = It.Value();
340 _PTR(SObject) obj ( aStudy->FindObjectID(anIObject->getEntry()) );
341 _PTR(AttributePersistentRef) aPersist;
342 _PTR(AttributeIOR) anIOR;
344 // this SObject may be GEOM module root SObject
345 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator() );
346 _PTR(GenericAttribute) anAttr;
347 bool useSubItems = false;
348 while (anIter->More() && !useSubItems) {
349 _PTR(SObject) subobj ( anIter->Value() );
350 if (subobj->FindAttribute(anAttr, "AttributePersistentRef")) {
357 obj->FindAttribute(anAttr, "AttributePersistentRef");
359 while(useSubItems?anIter->More():!anAttr->_is_nil()) {
360 if(!obj->FindAttribute(anAttr, "AttributeIOR") &&
361 obj->FindAttribute(anAttr, "AttributePersistentRef")) {
362 _PTR(SComponent) FComp ( obj->GetFatherComponent() );
364 if (FComp->FindAttribute(anAttr, "AttributeName")) {
365 _PTR(AttributeName) aName ( anAttr );
366 QString compName = QAD_Application::getDesktop()->getComponentName(aName->Value().c_str());
367 // parent->loadComponentData(parent->getComponentName(aName->Value()));
368 Engines::Component_var comp ;
369 if ( compName.compare("SUPERV") == 0 ) {
370 comp = QAD_Application::getDesktop()->getEngine( "SuperVisionContainer", compName) ;
373 comp = QAD_Application::getDesktop()->getEngine( "FactoryServer", compName);
374 if ( comp->_is_nil() )
375 comp = QAD_Application::getDesktop()->getEngine( "FactoryServerPy", compName);
378 if (!CORBA::is_nil(comp)) {
379 SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
380 if (!CORBA::is_nil(driver)) {
381 SALOMEDS::StudyBuilder_var B = dynamic_cast<SALOMEDS_Study*>(aStudy.get())->GetStudy()->NewBuilder();
382 if (!CORBA::is_nil(B)) {
383 B->LoadWith(FComp,driver);
389 MESSAGE("loadComponentData(): Driver is null");
394 MESSAGE("loadComponentData(): Engine is null");
398 // Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer","GEOM");
399 // if (!CORBA::is_nil(comp)) {
400 // SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
401 // SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
402 // SALOMEDS::SComponent_var SC = aStudy->FindComponent("GEOM");
403 // if (!CORBA::is_nil(SC))
404 // aStudyBuilder->LoadWith(SC,driver);
408 MESSAGE("Component is null");
413 obj.reset( anIter->Value() );