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.org
24 // File : GEOMToolsGUI_1.cxx
25 // Author : Sergey ANIKIN
29 #include <PythonConsole_PyConsole.h>
31 #include "GEOMToolsGUI.h"
32 #include "GeometryGUI.h"
33 #include "GEOM_Actor.h"
35 #include "GEOMToolsGUI_TransparencyDlg.h"
36 #include "GEOMToolsGUI_NbIsosDlg.h" // Method ISOS adjustement
37 #include "GEOMToolsGUI_NameDlg.h"
39 #include <SALOME_ListIO.hxx>
40 #include <SALOME_ListIteratorOfListIO.hxx>
42 #include <VTKViewer_ViewModel.h>
43 #include <OCCViewer_ViewModel.h>
44 #include <OCCViewer_ViewWindow.h>
46 #include <SVTK_ViewWindow.h>
47 #include <SVTK_RenderWindowInteractor.h>
49 #include <SUIT_ViewManager.h>
50 #include <SUIT_Application.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_SelectionMgr.h>
59 #include <SalomeApp_Study.h>
60 #include <SalomeApp_Module.h>
62 #include <AIS_Drawer.hxx>
63 #include <AIS_ListOfInteractive.hxx>
64 #include <AIS_ListIteratorOfListOfInteractive.hxx>
65 #include <Prs3d_IsoAspect.hxx>
67 #include <vtkBMPReader.h>
68 #include <vtkTexture.h>
69 #include <vtkTextureMapToPlane.h>
70 #include <vtkTransformTextureCoords.h>
71 #include <vtkDataSetMapper.h>
72 #include <vtkRenderer.h>
74 #include <qfileinfo.h>
75 #include <qcolordialog.h>
77 #include <qapplication.h>
79 #include "utilities.h"
83 #include "SALOMEDSClient.hxx"
84 #include "SALOMEDS_Study.hxx"
88 void GEOMToolsGUI::OnSettingsColor()
90 SUIT_Session* sess = SUIT_Session::session();
91 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
92 SUIT_Desktop* desk = sess->activeApplication()->desktop();
94 QColor anInitColor = resMgr->colorValue( "Geometry:SettingsShadingColor", QColor( "yellow" ) );
96 QColor aDialogColor = QColorDialog::getColor(anInitColor, desk );
97 if( aDialogColor.isValid() )
99 QString type = desk->activeWindow()->getViewManager()->getType();
100 if( type != OCCViewer_Viewer::Type() && type != VTKViewer_Viewer::Type() )
101 MESSAGE("Settings Color is not supported for current Viewer");
103 resMgr->setValue( "Geometry:SettingsShadingColor", aDialogColor );
107 void GEOMToolsGUI::OnSettingsIsos()
110 SUIT_Session* sess = SUIT_Session::session();
111 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
112 SUIT_Desktop* desk = sess->activeApplication()->desktop();
114 SUIT_ViewManager* vman = desk->activeWindow()->getViewManager();
115 QString type = vman->getType();
117 if ( type != OCCViewer_Viewer::Type() )
120 OCCViewer_Viewer* vm = (OCCViewer_Viewer*)vman->getViewModel();
121 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
123 int IsoU = resMgr->integerValue( "Geometry:SettingsIsoU", 1 );
124 int IsoV = resMgr->integerValue( "Geometry:SettingsIsoV", 1 );
126 ic->DefaultDrawer()->UIsoAspect()->SetNumber( IsoU );
127 ic->DefaultDrawer()->VIsoAspect()->SetNumber( IsoV );
129 GEOMBase_NbIsosDlg* NbIsosDlg = new GEOMBase_NbIsosDlg(desk, tr("GEOM_MEN_ISOS"), TRUE);
131 NbIsosDlg->SpinBoxU->setValue(IsoU);
132 NbIsosDlg->SpinBoxV->setValue(IsoV);
134 if(NbIsosDlg->exec()) {
135 IsoU = NbIsosDlg->SpinBoxU->text().toInt();
136 IsoV = NbIsosDlg->SpinBoxV->text().toInt();
138 ic->DefaultDrawer()->UIsoAspect()->SetNumber(UIso);
139 ic->DefaultDrawer()->VIsoAspect()->SetNumber(VIso);
140 resMgr->setValue("Geometry:SettingsIsoU", isoU);
141 resMgr->setValue("Geometry:SettingsIsoV", isoV);
146 void GEOMToolsGUI::OnSettingsStep()
148 SUIT_Session* sess = SUIT_Session::session();
149 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
151 double step = resMgr->doubleValue( "Geometry:SettingsGeomStep", 100. );
153 Standard_Boolean res = false;
154 double dd = GEOMBase::Parameter(res, QString("%1").arg(step), tr("GEOM_MEN_STEP_LABEL"), tr("GEOM_STEP_TITLE"), 0.001, 10000.0, 3);
156 resMgr->setValue( "Geometry:SettingsGeomStep", dd );
158 /* Emit signal to GeometryGUI_SpinBoxes */
159 getGeometryGUI()->EmitSignalDefaultStepValueChanged( dd );
162 sess->activeApplication()->putInfo(tr("GEOM_PRP_ABORT"));
165 void GEOMToolsGUI::OnRename()
167 SALOME_ListIO selected;
168 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
170 SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
171 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
172 if ( aSelMgr && appStudy ) {
173 aSelMgr->selectedObjects( selected );
174 if ( !selected.IsEmpty() ) {
175 _PTR(Study) aStudy = appStudy->studyDS();
177 bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
179 SUIT_MessageBox::warn1 ( app->desktop(),
180 QObject::tr("WRN_WARNING"),
181 QObject::tr("WRN_STUDY_LOCKED"),
182 QObject::tr("BUT_OK") );
186 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
187 Handle(SALOME_InteractiveObject) IObject = It.Value();
189 _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
190 _PTR(GenericAttribute) anAttr;
192 if( obj->FindAttribute(anAttr, "AttributeName") ) {
193 _PTR(AttributeName) aName (anAttr);
195 QString newName = GEOMToolsGUI_NameDlg::getName( app->desktop(), aName->Value().c_str() );
196 if ( !newName.isEmpty() ) {
197 aName->SetValue( newName.latin1() ); // rename the SObject
198 IObject->setName( newName.latin1() );// rename the InteractiveObject
199 (dynamic_cast<SalomeApp_Module*>(app->activeModule()))->updateObjBrowser( false );
201 } // if ( name attribute )
209 void GEOMToolsGUI::OnCheckGeometry()
211 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
212 PythonConsole* pyConsole = app->pythonConsole();
215 pyConsole->exec("from GEOM_usinggeom import *");
218 void GEOMToolsGUI::OnColor()
220 SALOME_ListIO selected;
221 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
223 SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
225 aSelMgr->selectedObjects( selected );
226 if ( !selected.IsEmpty() ) {
227 SUIT_ViewWindow* window = app->desktop()->activeWindow();
228 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
229 bool isVTK = ( window && window->getViewManager()->getType() == VTKViewer_Viewer::Type() );
231 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
234 SVTK_RenderWindowInteractor* rwi = vtkVW->getRWInteractor();
235 QColor initcolor = rwi->GetColor( selected.First() );
236 QColor c = QColorDialog::getColor( QColor(), app->desktop() );
238 SUIT_OverrideCursor();
239 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
240 rwi->SetColor( It.Value(), c );
245 Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
246 if ( !io.IsNull() ) {
247 Quantity_Color aColor;
249 QColor initcolor( (int)( aColor.Red() * 255.0 ), (int)( aColor.Green() * 255.0 ), (int)( aColor.Blue() * 255.0 ) );
250 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
252 SUIT_OverrideCursor();
253 aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
254 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
255 io = GEOMBase::GetAIS( It.Value(), true );
256 if ( !io.IsNull() ) {
257 io->SetColor( aColor );
258 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
259 Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aColor );
261 io->Redisplay( Standard_True );
265 } // first IO is not null
267 } // if ( selection not empty )
272 void GEOMToolsGUI::OnTransparency()
274 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
278 void GEOMToolsGUI::OnNbIsos()
280 SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
281 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
286 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
287 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
290 if ( ic->MoreCurrent() ) {
291 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
292 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
294 int UIso = CurDrawer->UIsoAspect()->Number();
295 int VIso = CurDrawer->VIsoAspect()->Number();
297 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
298 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
300 NbIsosDlg->setU( UIso );
301 NbIsosDlg->setV( VIso );
303 if ( NbIsosDlg->exec() ) {
304 SUIT_OverrideCursor();
305 for(; ic->MoreCurrent(); ic->NextCurrent()) {
306 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
307 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
309 int nbUIso = NbIsosDlg->getU();
310 int nbVIso = NbIsosDlg->getV();
312 CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbUIso) );
313 CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbVIso) );
315 ic->SetLocalAttributes(CurObject, CurDrawer);
316 ic->Redisplay(CurObject);
322 void GEOMToolsGUI::OnOpen()
325 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
326 _PTR(Study) aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
328 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
329 Handle(SALOME_InteractiveObject) anIObject;
330 for(;It.More();It.Next()) {
331 anIObject = It.Value();
332 _PTR(SObject) obj ( aStudy->FindObjectID(anIObject->getEntry()) );
333 _PTR(AttributePersistentRef) aPersist;
334 _PTR(AttributeIOR) anIOR;
336 // this SObject may be GEOM module root SObject
337 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator() );
338 _PTR(GenericAttribute) anAttr;
339 bool useSubItems = false;
340 while (anIter->More() && !useSubItems) {
341 _PTR(SObject) subobj ( anIter->Value() );
342 if (subobj->FindAttribute(anAttr, "AttributePersistentRef")) {
349 obj->FindAttribute(anAttr, "AttributePersistentRef");
351 while(useSubItems?anIter->More():!anAttr->_is_nil()) {
352 if(!obj->FindAttribute(anAttr, "AttributeIOR") &&
353 obj->FindAttribute(anAttr, "AttributePersistentRef")) {
354 _PTR(SComponent) FComp ( obj->GetFatherComponent() );
356 if (FComp->FindAttribute(anAttr, "AttributeName")) {
357 _PTR(AttributeName) aName ( anAttr );
358 QString compName = QAD_Application::getDesktop()->getComponentName(aName->Value().c_str());
359 // parent->loadComponentData(parent->getComponentName(aName->Value()));
360 Engines::Component_var comp ;
361 if ( compName.compare("SUPERV") == 0 ) {
362 comp = QAD_Application::getDesktop()->getEngine( "SuperVisionContainer", compName) ;
365 comp = QAD_Application::getDesktop()->getEngine( "FactoryServer", compName);
366 if ( comp->_is_nil() )
367 comp = QAD_Application::getDesktop()->getEngine( "FactoryServerPy", compName);
370 if (!CORBA::is_nil(comp)) {
371 SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
372 if (!CORBA::is_nil(driver)) {
373 SALOMEDS::StudyBuilder_var B = dynamic_cast<SALOMEDS_Study*>(aStudy.get())->GetStudy()->NewBuilder();
374 if (!CORBA::is_nil(B)) {
375 B->LoadWith(FComp,driver);
381 MESSAGE("loadComponentData(): Driver is null");
386 MESSAGE("loadComponentData(): Engine is null");
390 // Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer","GEOM");
391 // if (!CORBA::is_nil(comp)) {
392 // SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
393 // SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
394 // SALOMEDS::SComponent_var SC = aStudy->FindComponent("GEOM");
395 // if (!CORBA::is_nil(SC))
396 // aStudyBuilder->LoadWith(SC,driver);
400 MESSAGE("Component is null");
405 obj.reset( anIter->Value() );