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"
30 #include <GeometryGUI.h>
31 #include <GEOM_Displayer.h>
32 #include "GEOMToolsGUI_TransparencyDlg.h"
33 #include "GEOMToolsGUI_NbIsosDlg.h" // Method ISOS adjustement
37 #include <SALOME_ListIO.hxx>
38 #include <SALOME_ListIteratorOfListIO.hxx>
40 #include <SVTK_ViewModel.h>
41 #include <SVTK_ViewWindow.h>
42 #include <SVTK_View.h>
44 #include <OCCViewer_ViewModel.h>
46 #include <SUIT_ViewManager.h>
47 #include <SUIT_Desktop.h>
48 #include <SUIT_ResourceMgr.h>
49 #include <SUIT_Session.h>
50 #include <SUIT_OverrideCursor.h>
51 #include <SUIT_MessageBox.h>
53 #include <SalomeApp_Application.h>
54 #include <SalomeApp_Study.h>
55 #include <SalomeApp_Module.h>
57 #include <LightApp_SelectionMgr.h>
58 #include <LightApp_NameDlg.h>
60 #include "utilities.h"
63 #include <AIS_Drawer.hxx>
64 #include <Prs3d_IsoAspect.hxx>
65 #include <Prs3d_PointAspect.hxx>
66 #include <Graphic3d_AspectMarker3d.hxx>
69 #include <QColorDialog>
74 void GEOMToolsGUI::OnSettingsColor()
76 SUIT_Session* sess = SUIT_Session::session();
77 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
78 SUIT_Desktop* desk = sess->activeApplication()->desktop();
80 QColor anInitColor = resMgr->colorValue( "Geometry", "SettingsShadingColor", QColor( "yellow" ) );
82 QColor aDialogColor = QColorDialog::getColor(anInitColor, desk );
83 if( aDialogColor.isValid() )
85 QString type = desk->activeWindow()->getViewManager()->getType();
86 if( type != OCCViewer_Viewer::Type() && type != SVTK_Viewer::Type() )
87 MESSAGE("Settings Color is not supported for current Viewer");
89 resMgr->setValue( "Geometry", "SettingsShadingColor", aDialogColor );
93 void GEOMToolsGUI::OnRename()
95 SALOME_ListIO selected;
96 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
98 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
99 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
100 if ( aSelMgr && appStudy ) {
101 aSelMgr->selectedObjects( selected );
102 if ( !selected.IsEmpty() ) {
103 _PTR(Study) aStudy = appStudy->studyDS();
105 bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
107 SUIT_MessageBox::warning ( app->desktop(),
108 QObject::tr("WRN_WARNING"),
109 QObject::tr("WRN_STUDY_LOCKED"),
110 QObject::tr("BUT_OK") );
114 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
115 Handle(SALOME_InteractiveObject) IObject = It.Value();
117 _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
118 _PTR(GenericAttribute) anAttr;
120 if( obj->FindAttribute(anAttr, "AttributeName") ) {
121 _PTR(AttributeName) aName (anAttr);
123 QString newName = LightApp_NameDlg::getName( app->desktop(), aName->Value().c_str() );
124 if ( !newName.isEmpty() ) {
125 aName->SetValue( newName.toLatin1().constData() ); // rename the SObject
126 IObject->setName( newName.toLatin1() );// rename the InteractiveObject
127 // Rename the corresponding GEOM_Object
128 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
129 if (!CORBA::is_nil( anObj ))
130 anObj->SetName( newName.toLatin1() );
131 (dynamic_cast<SalomeApp_Module*>(app->activeModule()))->updateObjBrowser( false );
133 } // if ( name attribute )
140 app->updateActions(); //SRN: To update a Save button in the toolbar
143 void GEOMToolsGUI::OnCheckGeometry()
145 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
146 PyConsole_Console* pyConsole = app->pythonConsole();
149 pyConsole->exec("from GEOM_usinggeom import *");
152 void GEOMToolsGUI::OnColor()
154 SALOME_ListIO selected;
155 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
157 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
159 aSelMgr->selectedObjects( selected );
160 if ( !selected.IsEmpty() ) {
161 SUIT_ViewWindow* window = app->desktop()->activeWindow();
162 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
163 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
165 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
168 SVTK_View* aView = vtkVW->getView();
169 QColor initcolor = aView->GetColor( selected.First() );
170 QColor c = QColorDialog::getColor( QColor(), app->desktop() );
172 SUIT_OverrideCursor();
173 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
174 aView->SetColor( It.Value(), c );
179 Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
180 if ( !io.IsNull() ) {
181 Quantity_Color aColor;
183 QColor initcolor( (int)( aColor.Red() * 255.0 ), (int)( aColor.Green() * 255.0 ), (int)( aColor.Blue() * 255.0 ) );
184 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
186 SUIT_OverrideCursor();
187 aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
188 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
189 io = GEOMBase::GetAIS( It.Value(), true );
190 if ( !io.IsNull() ) {
191 // Set color for a point
192 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
193 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
194 Handle(AIS_Drawer) aCurDrawer = io->Attributes();
195 Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
196 Quantity_Color aCurColor;
197 Standard_Real aCurScale;
198 Aspect_TypeOfMarker aCurTypeOfMarker;
199 aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
200 aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aColor, aCurScale) );
201 ic->SetLocalAttributes(io, aCurDrawer);
203 io->SetColor( aColor );
204 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
205 Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aColor );
207 io->Redisplay( Standard_True );
211 } // first IO is not null
213 } // if ( selection not empty )
217 app->updateActions(); //SRN: To update a Save button in the toolbar
220 void GEOMToolsGUI::OnTransparency()
222 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
226 void GEOMToolsGUI::OnNbIsos()
228 SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
229 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
234 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
235 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
238 if ( ic->MoreCurrent() ) {
239 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
240 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
242 int UIso = CurDrawer->UIsoAspect()->Number();
243 int VIso = CurDrawer->VIsoAspect()->Number();
245 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
246 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
248 NbIsosDlg->setU( UIso );
249 NbIsosDlg->setV( VIso );
251 if ( NbIsosDlg->exec() ) {
252 SUIT_OverrideCursor();
253 for(; ic->MoreCurrent(); ic->NextCurrent()) {
254 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
255 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
257 int nbUIso = NbIsosDlg->getU();
258 int nbVIso = NbIsosDlg->getV();
260 CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbUIso) );
261 CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbVIso) );
263 ic->SetLocalAttributes(CurObject, CurDrawer);
264 ic->Redisplay(CurObject);
270 void GEOMToolsGUI::OnOpen()
273 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
274 _PTR(Study) aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
276 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
277 Handle(SALOME_InteractiveObject) anIObject;
278 for(;It.More();It.Next()) {
279 anIObject = It.Value();
280 _PTR(SObject) obj ( aStudy->FindObjectID(anIObject->getEntry()) );
281 _PTR(AttributePersistentRef) aPersist;
282 _PTR(AttributeIOR) anIOR;
284 // this SObject may be GEOM module root SObject
285 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator() );
286 _PTR(GenericAttribute) anAttr;
287 bool useSubItems = false;
288 while (anIter->More() && !useSubItems) {
289 _PTR(SObject) subobj ( anIter->Value() );
290 if (subobj->FindAttribute(anAttr, "AttributePersistentRef")) {
297 obj->FindAttribute(anAttr, "AttributePersistentRef");
299 while(useSubItems?anIter->More():!anAttr->_is_nil()) {
300 if(!obj->FindAttribute(anAttr, "AttributeIOR") &&
301 obj->FindAttribute(anAttr, "AttributePersistentRef")) {
302 _PTR(SComponent) FComp ( obj->GetFatherComponent() );
304 if (FComp->FindAttribute(anAttr, "AttributeName")) {
305 _PTR(AttributeName) aName ( anAttr );
306 QString compName = QAD_Application::getDesktop()->getComponentName(aName->Value().c_str());
307 // parent->loadComponentData(parent->getComponentName(aName->Value()));
308 Engines::Component_var comp ;
309 if ( compName.compare("SUPERV") == 0 ) {
310 comp = QAD_Application::getDesktop()->getEngine( "SuperVisionContainer", compName) ;
313 comp = QAD_Application::getDesktop()->getEngine( "FactoryServer", compName);
314 if ( comp->_is_nil() )
315 comp = QAD_Application::getDesktop()->getEngine( "FactoryServerPy", compName);
318 if (!CORBA::is_nil(comp)) {
319 SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
320 if (!CORBA::is_nil(driver)) {
321 SALOMEDS::StudyBuilder_var B = dynamic_cast<SALOMEDS_Study*>(aStudy.get())->GetStudy()->NewBuilder();
322 if (!CORBA::is_nil(B)) {
323 B->LoadWith(FComp,driver);
329 MESSAGE("loadComponentData(): Driver is null");
334 MESSAGE("loadComponentData(): Engine is null");
338 // Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer","GEOM");
339 // if (!CORBA::is_nil(comp)) {
340 // SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
341 // SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
342 // SALOMEDS::SComponent_var SC = aStudy->FindComponent("GEOM");
343 // if (!CORBA::is_nil(SC))
344 // aStudyBuilder->LoadWith(SC,driver);
348 MESSAGE("Component is null");
353 obj.reset( anIter->Value() );
363 void GEOMToolsGUI::OnSelectOnly(int mode)
365 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
367 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
368 GEOM_Displayer aDisp (appStudy);
369 aDisp.GlobalSelection(mode);
370 getGeometryGUI()->setLocalSelectionMode(mode);