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"
33 #include "GeometryGUI.h"
34 #include "GEOMToolsGUI_TransparencyDlg.h"
35 #include "GEOMToolsGUI_NbIsosDlg.h" // Method ISOS adjustement
36 #include "GEOMToolsGUI_NameDlg.h"
38 #include "GEOM_Actor.h"
41 #include <SALOME_ListIO.hxx>
42 #include <SALOME_ListIteratorOfListIO.hxx>
44 #include <VTKViewer_ViewModel.h>
45 #include <OCCViewer_ViewModel.h>
46 #include <OCCViewer_ViewWindow.h>
48 #include <SVTK_ViewWindow.h>
49 #include <SVTK_RenderWindowInteractor.h>
51 #include <SUIT_ViewManager.h>
52 #include <SUIT_Application.h>
53 #include <SUIT_Desktop.h>
54 #include <SUIT_ResourceMgr.h>
55 #include <SUIT_Session.h>
56 #include <SUIT_OverrideCursor.h>
57 #include <SUIT_MessageBox.h>
59 #include <SalomeApp_Application.h>
60 #include <SalomeApp_SelectionMgr.h>
61 #include <SalomeApp_Study.h>
62 #include <SalomeApp_Module.h>
64 #include "SALOMEDSClient.hxx"
66 #include "utilities.h"
69 #include <AIS_Drawer.hxx>
70 #include <AIS_ListOfInteractive.hxx>
71 #include <AIS_ListIteratorOfListOfInteractive.hxx>
72 #include <Prs3d_IsoAspect.hxx>
75 #include <vtkBMPReader.h>
76 #include <vtkTexture.h>
77 #include <vtkTextureMapToPlane.h>
78 #include <vtkTransformTextureCoords.h>
79 #include <vtkDataSetMapper.h>
80 #include <vtkRenderer.h>
83 #include <qfileinfo.h>
84 #include <qcolordialog.h>
86 #include <qapplication.h>
91 void GEOMToolsGUI::OnSettingsColor()
93 SUIT_Session* sess = SUIT_Session::session();
94 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
95 SUIT_Desktop* desk = sess->activeApplication()->desktop();
97 QColor anInitColor = resMgr->colorValue( "Geometry", "SettingsShadingColor", QColor( "yellow" ) );
99 QColor aDialogColor = QColorDialog::getColor(anInitColor, desk );
100 if( aDialogColor.isValid() )
102 QString type = desk->activeWindow()->getViewManager()->getType();
103 if( type != OCCViewer_Viewer::Type() && type != VTKViewer_Viewer::Type() )
104 MESSAGE("Settings Color is not supported for current Viewer");
106 resMgr->setValue( "Geometry", "SettingsShadingColor", aDialogColor );
110 void GEOMToolsGUI::OnSettingsIsos()
113 SUIT_Session* sess = SUIT_Session::session();
114 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
115 SUIT_Desktop* desk = sess->activeApplication()->desktop();
117 SUIT_ViewManager* vman = desk->activeWindow()->getViewManager();
118 QString type = vman->getType();
120 if ( type != OCCViewer_Viewer::Type() )
123 OCCViewer_Viewer* vm = (OCCViewer_Viewer*)vman->getViewModel();
124 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
126 int IsoU = resMgr->integerValue( "Geometry:SettingsIsoU", 1 );
127 int IsoV = resMgr->integerValue( "Geometry:SettingsIsoV", 1 );
129 ic->DefaultDrawer()->UIsoAspect()->SetNumber( IsoU );
130 ic->DefaultDrawer()->VIsoAspect()->SetNumber( IsoV );
132 GEOMBase_NbIsosDlg* NbIsosDlg = new GEOMBase_NbIsosDlg(desk, tr("GEOM_MEN_ISOS"), TRUE);
134 NbIsosDlg->SpinBoxU->setValue(IsoU);
135 NbIsosDlg->SpinBoxV->setValue(IsoV);
137 if(NbIsosDlg->exec()) {
138 IsoU = NbIsosDlg->SpinBoxU->text().toInt();
139 IsoV = NbIsosDlg->SpinBoxV->text().toInt();
141 ic->DefaultDrawer()->UIsoAspect()->SetNumber(UIso);
142 ic->DefaultDrawer()->VIsoAspect()->SetNumber(VIso);
143 resMgr->setValue("Geometry:SettingsIsoU", isoU);
144 resMgr->setValue("Geometry:SettingsIsoV", isoV);
149 void GEOMToolsGUI::OnSettingsStep()
151 SUIT_Session* sess = SUIT_Session::session();
152 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
154 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100. );
156 Standard_Boolean res = false;
157 double dd = GEOMBase::Parameter( res, QString("%1").arg(step), tr("GEOM_MEN_STEP_LABEL"), tr("GEOM_STEP_TITLE"), 0.001, 10000.0, 3);
159 resMgr->setValue( "Geometry", "SettingsGeomStep", dd );
161 /* Emit signal to GeometryGUI_SpinBoxes */
162 getGeometryGUI()->EmitSignalDefaultStepValueChanged( dd );
165 sess->activeApplication()->putInfo(tr("GEOM_PRP_ABORT"));
168 void GEOMToolsGUI::OnRename()
170 SALOME_ListIO selected;
171 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
173 SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
174 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
175 if ( aSelMgr && appStudy ) {
176 aSelMgr->selectedObjects( selected );
177 if ( !selected.IsEmpty() ) {
178 _PTR(Study) aStudy = appStudy->studyDS();
180 bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
182 SUIT_MessageBox::warn1 ( app->desktop(),
183 QObject::tr("WRN_WARNING"),
184 QObject::tr("WRN_STUDY_LOCKED"),
185 QObject::tr("BUT_OK") );
189 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
190 Handle(SALOME_InteractiveObject) IObject = It.Value();
192 _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
193 _PTR(GenericAttribute) anAttr;
195 if( obj->FindAttribute(anAttr, "AttributeName") ) {
196 _PTR(AttributeName) aName (anAttr);
198 QString newName = GEOMToolsGUI_NameDlg::getName( app->desktop(), aName->Value().c_str() );
199 if ( !newName.isEmpty() ) {
200 aName->SetValue( newName.latin1() ); // rename the SObject
201 IObject->setName( newName.latin1() );// rename the InteractiveObject
202 (dynamic_cast<SalomeApp_Module*>(app->activeModule()))->updateObjBrowser( false );
204 } // if ( name attribute )
212 void GEOMToolsGUI::OnCheckGeometry()
214 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
215 PythonConsole* pyConsole = app->pythonConsole();
218 pyConsole->exec("from GEOM_usinggeom import *");
221 void GEOMToolsGUI::OnColor()
223 SALOME_ListIO selected;
224 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
226 SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
228 aSelMgr->selectedObjects( selected );
229 if ( !selected.IsEmpty() ) {
230 SUIT_ViewWindow* window = app->desktop()->activeWindow();
231 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
232 bool isVTK = ( window && window->getViewManager()->getType() == VTKViewer_Viewer::Type() );
234 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
237 SVTK_RenderWindowInteractor* rwi = vtkVW->getRWInteractor();
238 QColor initcolor = rwi->GetColor( selected.First() );
239 QColor c = QColorDialog::getColor( QColor(), app->desktop() );
241 SUIT_OverrideCursor();
242 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
243 rwi->SetColor( It.Value(), c );
248 Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
249 if ( !io.IsNull() ) {
250 Quantity_Color aColor;
252 QColor initcolor( (int)( aColor.Red() * 255.0 ), (int)( aColor.Green() * 255.0 ), (int)( aColor.Blue() * 255.0 ) );
253 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
255 SUIT_OverrideCursor();
256 aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
257 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
258 io = GEOMBase::GetAIS( It.Value(), true );
259 if ( !io.IsNull() ) {
260 io->SetColor( aColor );
261 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
262 Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aColor );
264 io->Redisplay( Standard_True );
268 } // first IO is not null
270 } // if ( selection not empty )
275 void GEOMToolsGUI::OnTransparency()
277 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
281 void GEOMToolsGUI::OnNbIsos()
283 SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
284 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
289 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
290 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
293 if ( ic->MoreCurrent() ) {
294 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
295 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
297 int UIso = CurDrawer->UIsoAspect()->Number();
298 int VIso = CurDrawer->VIsoAspect()->Number();
300 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
301 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
303 NbIsosDlg->setU( UIso );
304 NbIsosDlg->setV( VIso );
306 if ( NbIsosDlg->exec() ) {
307 SUIT_OverrideCursor();
308 for(; ic->MoreCurrent(); ic->NextCurrent()) {
309 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
310 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
312 int nbUIso = NbIsosDlg->getU();
313 int nbVIso = NbIsosDlg->getV();
315 CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbUIso) );
316 CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbVIso) );
318 ic->SetLocalAttributes(CurObject, CurDrawer);
319 ic->Redisplay(CurObject);
325 void GEOMToolsGUI::OnOpen()
328 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
329 _PTR(Study) aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
331 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
332 Handle(SALOME_InteractiveObject) anIObject;
333 for(;It.More();It.Next()) {
334 anIObject = It.Value();
335 _PTR(SObject) obj ( aStudy->FindObjectID(anIObject->getEntry()) );
336 _PTR(AttributePersistentRef) aPersist;
337 _PTR(AttributeIOR) anIOR;
339 // this SObject may be GEOM module root SObject
340 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator() );
341 _PTR(GenericAttribute) anAttr;
342 bool useSubItems = false;
343 while (anIter->More() && !useSubItems) {
344 _PTR(SObject) subobj ( anIter->Value() );
345 if (subobj->FindAttribute(anAttr, "AttributePersistentRef")) {
352 obj->FindAttribute(anAttr, "AttributePersistentRef");
354 while(useSubItems?anIter->More():!anAttr->_is_nil()) {
355 if(!obj->FindAttribute(anAttr, "AttributeIOR") &&
356 obj->FindAttribute(anAttr, "AttributePersistentRef")) {
357 _PTR(SComponent) FComp ( obj->GetFatherComponent() );
359 if (FComp->FindAttribute(anAttr, "AttributeName")) {
360 _PTR(AttributeName) aName ( anAttr );
361 QString compName = QAD_Application::getDesktop()->getComponentName(aName->Value().c_str());
362 // parent->loadComponentData(parent->getComponentName(aName->Value()));
363 Engines::Component_var comp ;
364 if ( compName.compare("SUPERV") == 0 ) {
365 comp = QAD_Application::getDesktop()->getEngine( "SuperVisionContainer", compName) ;
368 comp = QAD_Application::getDesktop()->getEngine( "FactoryServer", compName);
369 if ( comp->_is_nil() )
370 comp = QAD_Application::getDesktop()->getEngine( "FactoryServerPy", compName);
373 if (!CORBA::is_nil(comp)) {
374 SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
375 if (!CORBA::is_nil(driver)) {
376 SALOMEDS::StudyBuilder_var B = dynamic_cast<SALOMEDS_Study*>(aStudy.get())->GetStudy()->NewBuilder();
377 if (!CORBA::is_nil(B)) {
378 B->LoadWith(FComp,driver);
384 MESSAGE("loadComponentData(): Driver is null");
389 MESSAGE("loadComponentData(): Engine is null");
393 // Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer","GEOM");
394 // if (!CORBA::is_nil(comp)) {
395 // SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
396 // SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
397 // SALOMEDS::SComponent_var SC = aStudy->FindComponent("GEOM");
398 // if (!CORBA::is_nil(SC))
399 // aStudyBuilder->LoadWith(SC,driver);
403 MESSAGE("Component is null");
408 obj.reset( anIter->Value() );