X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOMGUI%2FGeometryGUI.cxx;h=18022605da0b5cf38ba45ec058af7bef4f44b591;hb=2e77f1c4451dd5a9329677b9b4eb90b9ce9e653d;hp=998f271efe19114a6b2914e2cd93a4847d19c8fb;hpb=7842cbd70affcdb5232fe0b1397f75fbdadc495d;p=modules%2Fgeom.git diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index 998f271ef..18022605d 100644 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -1,7129 +1,1816 @@ -using namespace std; -// File : GeometryGUI.cxx -// Created : -// Author : Lucien PIGNOLONI -// Project : SALOME -// Module : GeometryGUI -// Copyright : OPEN CASCADE +// GEOM GEOMGUI : GUI for Geometry component +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : GeometryGUI.cxx +// Author : Lucien PIGNOLONI +// Module : GEOM // $Header$ #include "GeometryGUI.h" +#include "GEOMGUI_OCCSelector.h" +#include "GEOMGUI_Selection.h" +#include "GEOM_Displayer.h" + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +// External includes +#include +#include -// SALOME Includes -# include "Utils_ORB_INIT.hxx" -# include "Utils_SINGLETON.hxx" - -#include "QAD.h" -#include "QAD_Tools.h" -#include "QAD_Config.h" -#include "QAD_Settings.h" -#include "QAD_RightFrame.h" -#include "QAD_MessageBox.h" -#include "QAD_Resource.h" -#include "QAD_FileDlg.h" - -#include "OCCViewer_ViewPort.h" -#include "OCCViewer_ViewPort3d.h" -#include "OCCViewer_Viewer3d.h" - -#include "VTKViewer_RenderWindowInteractor.h" -#include "VTKViewer_ViewFrame.h" - -#include "GEOM_Actor.h" -#include "GEOM_Client.hxx" -#include "GEOM_AISShape.hxx" -#include "GEOM_AssemblyBuilder.h" -#include "GEOM_InteractiveObject.hxx" - -#include "SALOME_NamingService.hxx" -#include "SALOME_ListIteratorOfListIO.hxx" -#include "SALOME_InteractiveObject.hxx" - -#include "SALOMEGUI_ImportOperation.h" -#include "SALOMEGUI_QtCatchCorbaException.hxx" -#include "SALOMEGUI_NameDlg.h" -#include "utilities.h" - -// Open CASCADE Includes -#include -#include -#include -#include -#include #include #include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -//VRV: OCC 4.0 migration -#include -#include -#include -//#include -//VRV: OCC 4.0 migration - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -// QT Includes -#define INCLUDE_MENUITEM_DEF -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "GeometryGUI_aParameterDlg.h" - -#include "GeometryGUI_PointDlg.h" // Method POINT -#include "GeometryGUI_BoxDlg.h" // Method BOX -#include "GeometryGUI_VectorDlg.h" // Method VECTOR -#include "GeometryGUI_PlaneDlg.h" // Method PLANE -#include "GeometryGUI_PrismDlg.h" // Method PRISM -#include "GeometryGUI_FuseDlg.h" // Method FUSE -#include "GeometryGUI_CommonDlg.h" // Method COMMON -#include "GeometryGUI_CutDlg.h" // Method CUT -#include "GeometryGUI_SectionDlg.h" // Method SECTION - -#include "GeometryGUI_LineDlg.h" // Method LINE -#include "GeometryGUI_ScaleDlg.h" // Method SCALE -#include "GeometryGUI_MirrorDlg.h" // Method MIRROR -#include "GeometryGUI_SphereDlg.h" // Method SPHERE -#include "GeometryGUI_CircleDlg.h" // Method CIRCLE -#include "GeometryGUI_RevolDlg.h" // Method REVOL -#include "GeometryGUI_RotationDlg.h" // Method ROTATION -#include "GeometryGUI_TranslationDlg.h" // Method TRANSLATION -#include "GeometryGUI_MultiTranslationDlg.h" // Method MULTI TRANSLATION -#include "GeometryGUI_MultiRotationDlg.h" // Method MULTI ROTATION -#include "GeometryGUI_ArcDlg.h" // Method ARC -#include "GeometryGUI_PipeDlg.h" // Method PIPE -#include "GeometryGUI_CylinderDlg.h" // Method CYLINDER -#include "GeometryGUI_ConeDlg.h" // Method CONE -#include "GeometryGUI_TorusDlg.h" // Method TORUS -#include "GeometryGUI_FillingDlg.h" // Method FILLING -#include "GeometryGUI_SewingDlg.h" // Method SEWING -#include "GeometryGUI_CompoundDlg.h" // Method GEOM::COMPOUND -#include "GeometryGUI_EdgeDlg.h" // Method GEOM::EDGE -#include "GeometryGUI_OrientationDlg.h" // Method ORIENTATION -#include "GeometryGUI_PartitionDlg.h" // Method PARTITION -#include "GeometryGUI_SubShapeDlg.h" // Method EXPLODE -#include "GeometryGUI_WireDlg.h" // Method GEOM::WIRE -#include "GeometryGUI_WorkingPlaneDlg.h" // Method WORKING PLANE -#include "GeometryGUI_PropertiesDlg.h" // Method PROPERTIES -#include "GeometryGUI_CenterMassDlg.h" // Method CENTER MASS -#include "GeometryGUI_InertiaDlg.h" // Method INERTIA -#include "GeometryGUI_FaceDlg.h" // Method GEOM::FACE -#include "GeometryGUI_FilletDlg.h" // Method FILLET -#include "GeometryGUI_ChamferDlg.h" // Method CHAMFER -#include "GeometryGUI_FillingHoleDlg.h" // Method FILLING HOLE -#include "GeometryGUI_SuppressFacesDlg.h" // Method SUPPRESS FACES -#include "GeometryGUI_CheckShape.h" // Method CHECKSHAPE -#include "GeometryGUI_ArchimedeDlg.h" // Method ARCHIMEDE -#include "GeometryGUI_TransparencyDlg.h" // Method TRANSPARENCY adjustement -#include "GeometryGUI_NbIsosDlg.h" // Method ISOS adjustement -#include "GeometryGUI_BndBoxDlg.h" // Method BNDBOX -#include "GeometryGUI_MaxToleranceDlg.h" // Method MAXTOLERANCE -#include "GeometryGUI_WhatisDlg.h" // Method WHATIS -#include "GeometryGUI_DistanceDlg.h" // Method DISTANCE -#include "GeometryGUI_SuppressHoleDlg.h" // Method SUPPRESS HOLE - - -static Handle(AIS_Shape) theConstructionShape = new AIS_Shape(TopoDS_Shape()); -static Handle(GEOM_AISShape) theSelectedShape = new GEOM_AISShape(TopoDS_Shape(), ""); - -static AIS_ListOfInteractive ListDisplayedObject; - -static bool Settings_AddInStudy = false; -static bool Settings_Copy = false; -static Standard_CString Fatherior = ""; -static GEOM_Client ShapeReader; - -/* The object itself created in the static method 'GetOrCreateGeometryGUI()' */ -static GeometryGUI* GeomGUI = 0; +#include +#include +#include +#include +#include -//======================================================================= -// class : CustomItem -// purpose : Set Font to a text. -//======================================================================= -class CustomItem : public QCustomMenuItem -{ -public: - CustomItem( const QString& s, const QFont& f ) - : string( s ), font( f ){}; - ~CustomItem(){} - - void paint( QPainter* p, const QColorGroup& /*cg*/, bool /*act*/, bool /*enabled*/, int x, int y, int w, int h ) - { - p->setFont ( font ); - p->drawText( x, y, w, h, AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string ); - } - - QSize sizeHint() - { - return QFontMetrics( font ).size( AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string ); + +extern "C" { + Standard_EXPORT CAM_Module* createModule() { + return new GeometryGUI(); } -private: - QString string; - QFont font; -}; +} +GEOM::GEOM_Gen_var GeometryGUI::myComponentGeom = GEOM::GEOM_Gen::_nil(); -//======================================================================= -// function : GeometryGUI() -// purpose : Constructor -//======================================================================= -GeometryGUI::GeometryGUI() : - QObject() +GEOM::GEOM_Gen_var GeometryGUI::GetGeomGen() { + // Bug 12290: exception in Mesh GUI on GEOMBase::GetShape() if Geometry GUI hasn't been loaded + if (CORBA::is_nil(myComponentGeom)) + InitGeomGen(); + return GeometryGUI::myComponentGeom; } -//======================================================================= -// function : ~GeometryGUI() -// purpose : Destructor -//======================================================================= -GeometryGUI::~GeometryGUI() +bool GeometryGUI::InitGeomGen() { + GeometryGUI aGG; + if( CORBA::is_nil( myComponentGeom ) ) return false; + return true; } - //======================================================================= -// function : GetGeometryGUI() static -// purpose : Returns current 'GeomGUI' a static pointer +// function : ClientSObjectToObject +// purpose : //======================================================================= -GeometryGUI* GeometryGUI::GetGeometryGUI( ) +CORBA::Object_var GeometryGUI::ClientSObjectToObject (_PTR(SObject) theSObject) { - return GeomGUI; + _PTR(GenericAttribute) anAttr; + CORBA::Object_var anObj; + try { + std::string aValue = theSObject->GetIOR(); + if (strcmp(aValue.c_str(), "") != 0) { + CORBA::ORB_ptr anORB = SalomeApp_Application::orb(); + anObj = anORB->string_to_object(aValue.c_str()); + } + } catch(...) { + INFOS("ClientSObjectToObject - Unknown exception was occured!!!"); + } + return anObj._retn(); } - -//===================================================================================== -// function : GetIndex() -// purpose : Get the index of a sub shape in a main shape : index start at 1 -//===================================================================================== -int GeometryGUI::GetIndex(const TopoDS_Shape& subshape, - const TopoDS_Shape& shape, - int /*ShapeType*/) -{ - if( shape.IsNull() || subshape.IsNull() ) - return -1 ; - - int index = 1; - if (subshape.ShapeType() == TopAbs_COMPOUND) - { - TopoDS_Iterator it; - TopTools_ListOfShape CL; - CL.Append( shape ); - TopTools_ListIteratorOfListOfShape itC; - for (itC.Initialize( CL ); itC.More(); itC.Next()) - { - for (it.Initialize( itC.Value() ); it.More(); it.Next()) - { - if ( it.Value().ShapeType() == TopAbs_COMPOUND) - { - if (it.Value().IsSame(subshape)) - return index; - else - index++; - CL.Append( it.Value() ); - } - } - } - } - else - { - TopExp_Explorer Exp ( shape, subshape.ShapeType() ); - TopTools_MapOfShape M; - while ( Exp.More() ) - { - if ( M.Add(Exp.Current()) ) - { - if ( Exp.Current().IsSame(subshape) ) - return index; - index++; - } - Exp.Next(); - } - } - return -1; -} - //======================================================================= -// function : GetOrCreateGeometryGUI() -// purpose : Gets or create an object 'GeometryGUI' with initialisations -// : Returns 'GeomGUI' as a pointer +// function : ClientStudyToStudy +// purpose : //======================================================================= -GeometryGUI* GeometryGUI::GetOrCreateGeometryGUI( QAD_Desktop* desktop ) -{ - if( GeomGUI == 0 ) { - GeomGUI = new GeometryGUI; - GeomGUI->myActiveDialogBox = 0 ; - GeomGUI->mySimulationShape = new AIS_Shape(TopoDS_Shape()); - GeomGUI->myState = -1 ; - GeomGUI->myDesktop = desktop ; - GeomGUI->myActiveStudy = desktop->getActiveStudy(); - GeomGUI->mySimulationActor = vtkActorCollection::New() ; - - GeomGUI->myShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD ); - - Engines::Component_var comp = desktop->getEngine("FactoryServer", "GEOM"); - GeomGUI->myComponentGeom = GEOM::GEOM_Gen::_narrow(comp); - - /* GetCurrentStudy */ - int studyId = GeomGUI->myActiveStudy->getStudyId(); - GeomGUI->myComponentGeom->GetCurrentStudy(studyId); - - GeomGUI->myNbGeom = GeomGUI->myComponentGeom->NbLabels(); - } else { - /* study may have changed */ - GeomGUI->myActiveStudy = desktop->getActiveStudy(); - } - return GeomGUI; -} - - -//================================================================================= -// function : VertexToPoint() -// purpose : If S can be converted in a gp_Pnt returns true and the result is P -//================================================================================= -bool GeometryGUI::VertexToPoint( const TopoDS_Shape& S, gp_Pnt& P ) -{ - if( S.IsNull() || S.ShapeType() != TopAbs_VERTEX ) - return false ; - P = BRep_Tool::Pnt(TopoDS::Vertex( S )); - return true ; -} - - -//================================================================================= -// function : LinearEdgeExtremities() -// purpose : If S can be converted in a linear edge and if initial an final points -// : distance is sufficient, returns true else returns false. -// : Resulting points are respectively P1 and P2 -//================================================================================= -bool GeometryGUI::LinearEdgeExtremities( const TopoDS_Shape& S, gp_Pnt& P1, gp_Pnt& P2 ) +SALOMEDS::Study_var GeometryGUI::ClientStudyToStudy (_PTR(Study) theStudy) { - if( S.IsNull() || S.ShapeType() != TopAbs_EDGE ) - return false ; - BRepAdaptor_Curve curv(TopoDS::Edge(S)); - if (curv.GetType() != GeomAbs_Line) - return false ; - - curv.D0( curv.FirstParameter(), P1 ); - curv.D0( curv.LastParameter(), P2 ); - - if( P1.Distance(P2) <= Precision::Confusion() ) - return false ; - - return true ; + SALOME_NamingService *aNamingService = SalomeApp_Application::namingService(); + CORBA::Object_var aSMObject = aNamingService->Resolve("/myStudyManager"); + SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject); + int aStudyID = theStudy->StudyId(); + SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID(aStudyID); + return aDSStudy._retn(); } //================================================================================= -// function : GetBipointDxDyDz() -// purpose : +// class : CustomItem +// purpose : Set Font to a text. //================================================================================= -void GeometryGUI::GetBipointDxDyDz( gp_Pnt P1, gp_Pnt P2, double& dx, double& dy, double& dz ) +class CustomItem : public QCustomMenuItem { - dx = P2.X() - P1.X() ; - dy = P2.Y() - P1.Y() ; - dz = P2.Z() - P1.Z() ; - return ; -} +public: + CustomItem(const QString& s, const QFont& f) : myString(s), myFont(f) {} + ~CustomItem() {} -//======================================================================= -// function : GetTopoFromSelection() -// purpose : Define tds from a single selection and retuen true -//======================================================================= -bool GeometryGUI::GetTopoFromSelection(SALOME_Selection *Sel, TopoDS_Shape& tds) -{ - if(Sel->IObjectCount() != 1) - return false ; - - Handle(SALOME_InteractiveObject) IO = Sel->firstIObject(); - /* case SObject */ - if ( IO->hasEntry() ) { - SALOMEDS::Study_var aStudy = GeomGUI->myActiveStudy->getStudyDocument(); - SALOMEDS::SObject_var obj = aStudy->FindObjectID( IO->getEntry() ); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeIOR_var anIOR; - if ( !obj->_is_nil() ) { - if (obj->FindAttribute(anAttr, "AttributeIOR")) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - tds = this->GetShapeFromIOR(anIOR->Value()); - if(tds.IsNull() ) - return false ; - else - return true ; - } - } + void paint(QPainter* p, const QColorGroup& cg, bool act, bool /*enabled*/, int x, int y, int w, int h) + { + p->save(); + p->fillRect( x, y, w, h, act ? cg.highlight() : cg.mid() ); + p->setPen( act ? cg.highlightedText() : cg.buttonText() ); + p->setFont( myFont ); + p->drawText( x, y, w, h, AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString ); + p->restore(); } - if ( IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject)) ) { - Standard_CString ior = ""; - Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast( IO ); - ior = GIObject->getIOR(); - tds = this->GetShapeFromIOR(ior); - if(tds.IsNull() ) - return false ; - else - return true ; + QSize sizeHint() + { + return QFontMetrics( myFont ).size( AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString ); } - - return false; -} - - -//===================================================================================== -// function : PrepareSubShapeSelection() -// purpose : ( localContextId of the method is opened and defined here) -//===================================================================================== -bool GeometryGUI::PrepareSubShapeSelection(const int SubShapeType, Standard_Integer& returnLocalContextId) -{ - //* Test the type of viewer */ - if ( this->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) - return false; - - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - - /* local context opening */ - SetDisplayedObjectList() ; - OnDisplayOnly(); - - returnLocalContextId = ic->OpenLocalContext(Standard_False, Standard_True, Standard_False, Standard_False) ; - SALOME_Selection* Sel = SALOME_Selection::Selection( this->myActiveStudy->getSelection() ); - SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() ); - for(;It.More();It.Next()) { - Handle(SALOME_InteractiveObject) IObject = It.Value(); - Standard_Boolean found; - Handle(GEOM_AISShape) Shape = ConvertIOinGEOMAISShape(IObject, found); - if ( found && SubShapeType >= Shape->Shape().ShapeType()) { - ic->Load(Shape, (8 - SubShapeType), Standard_True); - ic->HilightWithColor(Shape, Quantity_NOC_RED); - } + bool fullSpan() const + { + return true; } - myDesktop->putInfo (tr("GEOM_PRP_SELECT_SUBSHAPES")); - return true ; -} - - - -//===================================================================================== -// function : PrepareSubShapeSelectionArgumentShape() -// purpose : ( localContextId of the method is opened and defined here ) -//===================================================================================== -bool GeometryGUI::PrepareSubShapeSelectionArgumentShape( const TopoDS_Shape& aShape, - const int SubShapeType, - Standard_Integer& returnLocalContextId ) -{ - //* Test the type of viewer */ - if ( this->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) - return false; - - if( aShape.IsNull() ) - return false ; - - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - - /* local context opening */ - SetDisplayedObjectList() ; - OnDisplayOnly(); - - returnLocalContextId = ic->OpenLocalContext(Standard_False, Standard_True, Standard_False, Standard_False) ; - - Handle(GEOM_AISShape) Shape = new GEOM_AISShape(aShape, "") ; - ic->Display(Shape, 0, (8 - SubShapeType)); - - // Not Load(...) but Display(...) - // ic->Load(Shape, (8 - SubShapeType), Standard_True); - ic->HilightWithColor(Shape, Quantity_NOC_RED); - - myDesktop->putInfo (tr("GEOM_PRP_SELECT_SUBSHAPES")); - return true ; -} - +private: + QString myString; + QFont myFont; +}; //======================================================================= -// function : GetNameOfSelectedIObjects() -// purpose : Define the name geom++ or other name of mono or multi sel. +// function : GeometryGUI::GeometryGUI() +// purpose : Constructor //======================================================================= -int GeometryGUI::GetNameOfSelectedIObjects( SALOME_Selection* Sel, - QString& aName ) +GeometryGUI::GeometryGUI() : + SalomeApp_Module( "GEOM" ) { - int nbSel = Sel->IObjectCount() ; - if ( nbSel == 1 ) { - Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject(); - aName = IObject->getName(); - } else { - aName = tr( "%1_objects" ).arg( nbSel ); + if ( CORBA::is_nil( myComponentGeom ) ) + { + SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA( getApp()->namingService() ); + Engines::Component_var comp = ls->FindOrLoad_Component( "FactoryServer", "GEOM" ); + myComponentGeom = GEOM::GEOM_Gen::_narrow( comp ); } - return nbSel; -} + myState = -1; + myActiveDialogBox = 0; + myFatherior = ""; -//======================================================================= -// function : ConvertIOinGEOMAISShape() -// purpose : -//======================================================================= -Handle(GEOM_AISShape) GeometryGUI::ConvertIOinGEOMAISShape( const Handle(SALOME_InteractiveObject)& IO, - Standard_Boolean& testResult, - bool onlyInActiveView ) -{ - Handle(GEOM_AISShape) res; - int nbSf = myActiveStudy->getStudyFramesCount(); - for ( int i = 0; i < nbSf; i++ ) { - QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i); - if ( sf->getTypeView() == VIEW_OCC ) { - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); + gp_Pnt origin = gp_Pnt(0., 0., 0.); + gp_Dir direction = gp_Dir(0., 0., 1.); + myWorkingPlane = gp_Ax3(origin, direction); - AIS_ListOfInteractive List; - ic->DisplayedObjects(List); - AIS_ListOfInteractive List1; - ic->ObjectsInCollector(List1); - List.Append(List1); - - AIS_ListIteratorOfListOfInteractive ite(List); - while (ite.More()) { - if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) { - Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value()); - if ( aSh->hasIO() ) { - Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(aSh->getIO()); - if ( GIO->isSame( IO ) ) { - if ( onlyInActiveView ) { - if ( sf == myActiveStudy->getActiveStudyFrame() ) { - testResult = true; - return aSh; - } - } else { - testResult = true; - return aSh; - } - } - } - } - ite.Next(); - } - } - } - testResult = false; - return res; + myOCCSelectors.setAutoDelete( true ); + myVTKSelectors.setAutoDelete( true ); + + myDisplayer = 0; + myLocalSelectionMode = GEOM_ALLOBJECTS; } //======================================================================= -// function : ConvertIORinGEOMAISShape() -// purpose : +// function : GeometryGUI::~GeometryGUI() +// purpose : Destructor //======================================================================= -Handle(GEOM_AISShape) GeometryGUI::ConvertIORinGEOMAISShape( const char * IOR, - Standard_Boolean& testResult, - bool onlyInActiveView ) +GeometryGUI::~GeometryGUI() { -Handle(GEOM_AISShape) resultShape; -testResult = false; - int nbSf = myActiveStudy->getStudyFramesCount(); - for ( int i = 0; i < nbSf; i++ ) - { - QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i); - if ( sf->getTypeView() == VIEW_OCC ) - { - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - - AIS_ListOfInteractive List; - ic->DisplayedObjects(List); - AIS_ListOfInteractive List1; - ic->ObjectsInCollector(List1); - List.Append(List1); - - AIS_ListIteratorOfListOfInteractive ite(List); - while (ite.More()) - { - if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) - { - Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value()); - if ( aSh->hasIO() ) - { - Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(aSh->getIO()); - Standard_CString theIOR = GIO->getIOR(); - if ( strcmp( IOR, theIOR ) == 0 ) - { - if ( onlyInActiveView ) - { - if ( sf == myActiveStudy->getActiveStudyFrame() ) - { - testResult = true; - resultShape = aSh; - return resultShape; - } - } - else - { - testResult = true; - resultShape = aSh; - return resultShape; - } - } - } - } - ite.Next(); - } - } - } -return resultShape; } + //======================================================================= -// function : ConvertIORinGEOMActor() -// purpose : -//======================================================================= -GEOM_Actor* GeometryGUI::ConvertIORinGEOMActor( const char * IOR, - Standard_Boolean& testResult, - bool onlyInActiveView ) -{ - int nbSf = GeomGUI->myActiveStudy->getStudyFramesCount(); - for ( int i = 0; i < nbSf; i++ ) { - QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i); - if ( sf->getTypeView() == VIEW_VTK ) { - vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRenderer(); - vtkActorCollection* theActors = Renderer->GetActors(); - theActors->InitTraversal(); - vtkActor *ac = theActors->GetNextActor(); - while(!(ac==NULL)) { - if ( ac->IsA("GEOM_Actor") ) { - GEOM_Actor* anActor = GEOM_Actor::SafeDownCast( ac ); - if ( anActor->hasIO() ) { - Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(anActor->getIO()); - Standard_CString theIOR = GIO->getIOR(); - if ( strcmp( IOR, theIOR ) == 0 ) { - if ( onlyInActiveView ) { - if ( sf == GeomGUI->myActiveStudy->getActiveStudyFrame() ) { - testResult = true; - return anActor; - } - } else { - testResult = true; - return anActor; - } +// function : GeometryGUI::getLibrary() +// purpose : get or load GUI library by name [ internal ] +//======================================================================= +typedef GEOMGUI* (*LibraryGUI)( GeometryGUI* ); +GEOMGUI* GeometryGUI::getLibrary( const QString& libraryName ) +{ + if ( !myGUIMap.contains( libraryName ) ) { + // try to load library if it is not loaded yet + QCString libs; +#ifndef WNT + if( ( libs = getenv( "LD_LIBRARY_PATH" ) ) ) { + QStringList dirList = QStringList::split( ":", libs, false ); // skip empty entries +#else + if( ( libs = getenv( "PATH" ) ) ) { + QStringList dirList = QStringList::split( ";", libs, false ); // skip empty entries +#endif + for( int i = dirList.count()-1; i >= 0; i-- ) { + QString dir = dirList[ i ]; + QFileInfo fi( Qtx::addSlash( dirList[ i ] ) + libraryName ); + if( fi.exists() ) { + OSD_SharedLibrary aSharedLibrary( (char*)fi.fileName().latin1() ); + bool res = aSharedLibrary.DlOpen( OSD_RTLD_LAZY ); + if( !res ) { + MESSAGE( "Can't open library : " << aSharedLibrary.DlError() ); + continue; // continue search further + } + OSD_Function osdF = aSharedLibrary.DlSymb( "GetLibGUI" ); + if ( osdF != NULL ) { + LibraryGUI func = (GEOMGUI* (*) (GeometryGUI*))osdF; + GEOMGUI* libGUI = (*func)(this); + if ( libGUI ) { + myGUIMap[ libraryName ] = libGUI; + break; // found and loaded! } } } - ac = theActors->GetNextActor(); } } } - testResult = false; - return GEOM_Actor::New(); + if ( myGUIMap.contains( libraryName ) ) + // library is successfully loaded + return myGUIMap[ libraryName ]; + return 0; } //======================================================================= -// function : ConvertIOinGEOMShape() -// purpose : +// function : GeometryGUI::ActiveWorkingPlane() +// purpose : Activate Working Plane View //======================================================================= -GEOM::GEOM_Shape_ptr GeometryGUI::ConvertIOinGEOMShape( const Handle(SALOME_InteractiveObject)& IO, - Standard_Boolean& testResult ) +void GeometryGUI::ActiveWorkingPlane() { - GEOM::GEOM_Shape_ptr aShape ; - testResult = false ; - - /* case SObject */ - if ( IO->hasEntry() ) { - SALOMEDS::Study_var aStudy = GeomGUI->myActiveStudy->getStudyDocument(); - SALOMEDS::SObject_var obj = aStudy->FindObjectID( IO->getEntry() ); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeIOR_var anIOR; - if ( !obj->_is_nil() ) { - if (obj->FindAttribute(anAttr, "AttributeIOR")) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - aShape = myComponentGeom->GetIORFromString(anIOR->Value()) ; - testResult = true ; - return aShape; - } - } - } - /* case Graphical Object */ - if ( IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject)) ) { - Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast( IO ); - Standard_CString ior = GIObject->getIOR(); - testResult = true ; - aShape = myComponentGeom->GetIORFromString(ior) ; - return aShape; - } - return aShape ; -} + gp_Dir DZ = myWorkingPlane.Direction(); + gp_Dir DY = myWorkingPlane.YDirection(); + SUIT_ViewWindow* window = application()->desktop()->activeWindow(); + bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() ); + bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() ); -//======================================================================= -// function : ConvertListOfIOInListOfIOR() -// purpose : -//======================================================================= -void GeometryGUI::ConvertListOfIOInListOfIOR( const SALOME_ListIO& aList, - GEOM::GEOM_Gen::ListOfIOR& listIOR ) -{ - int nbSel = aList.Extent(); - listIOR.length(nbSel) ; - int j=0; - SALOME_ListIteratorOfListIO It( aList ); - for ( int i=0; It.More(); It.Next(), i++ ) - { - Handle(SALOME_InteractiveObject) IObject = It.Value(); - - if ( IObject->hasEntry() ) - { - SALOMEDS::Study_var aStudy = GeomGUI->myActiveStudy->getStudyDocument(); - SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() ); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeIOR_var anIOR; - if ( !obj->_is_nil() && obj->FindAttribute(anAttr, "AttributeIOR") ) - { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - ORB_INIT &init = *SINGLETON_::Instance() ; - CORBA::ORB_var& _orb = init.orb() ; - CORBA::String_var theValue = anIOR->Value(); - CORBA::Object_var theObj = _orb->string_to_object(theValue); - if (theObj->_is_a("IDL:GEOM/GEOM_Shape:1.0")) - { - listIOR[j] = strdup(theValue) ; - j++; - } - } - } - else if ( IObject->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject)) ) { - Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast( IObject ); - Standard_CString ior = GIObject->getIOR(); - listIOR[j] = strdup(ior) ; - j++; - } - } - listIOR.length(j) ; -} + if( ViewOCC ) { + OCCViewer_ViewWindow* vw = dynamic_cast( window ); + if ( vw ) { + Handle(V3d_View) view3d = vw->getViewPort()->getView(); + view3d->SetProj(DZ.X(), DZ.Y(), DZ.Z()); + view3d->SetUp(DY.X(), DY.Y(), DY.Z()); -//================================================================================= -// function : GetShapeTypeString() -// purpose : for a single shape -//================================================================================= -bool GeometryGUI::GetShapeTypeString( const TopoDS_Shape& aShape, Standard_CString& aTypeString ) -{ - if( aShape.IsNull() ) { - aTypeString = "aNullShape" ; - return false ; - } - switch (aShape.ShapeType() ) - { - case TopAbs_COMPOUND: - { aTypeString = strdup(tr("GEOM_COMPOUND")) ; return true ; } - case TopAbs_COMPSOLID: - { aTypeString = strdup(tr("GEOM_COMPOUNDSOLID")) ; return true ; } - case TopAbs_SOLID: - { aTypeString = strdup(tr("GEOM_SOLID")) ; return true ; } - case TopAbs_SHELL: - { aTypeString = strdup(tr("GEOM_SHELL")) ; return true ; } - case TopAbs_FACE: - { - BRepAdaptor_Surface surf(TopoDS::Face(aShape)); - if ( surf.GetType() == GeomAbs_Plane ) { - aTypeString = strdup(tr("GEOM_PLANE")) ; - return true ; - } else if ( surf.GetType() == GeomAbs_Cylinder ) { - aTypeString = strdup(tr("GEOM_SURFCYLINDER")) ; - return true ; - } else if ( surf.GetType() == GeomAbs_Sphere ) { - aTypeString = strdup(tr("GEOM_SURFSPHERE")) ; - return true ; - } else if ( surf.GetType() == GeomAbs_Torus ) { - aTypeString = strdup(tr("GEOM_SURFTORUS")) ; - return true ; - } else if ( surf.GetType() == GeomAbs_Cone ) { - aTypeString = strdup(tr("GEOM_SURFCONE")) ; - return true ; - } else { - aTypeString = strdup(tr("GEOM_FACE")) ; - return true ; - } - } - case TopAbs_WIRE: - { aTypeString = strdup(tr("GEOM_WIRE")) ; return true ; } - case TopAbs_EDGE: - { - BRepAdaptor_Curve curv(TopoDS::Edge(aShape)); - if ( curv.GetType() == GeomAbs_Line ) { - if ( (Abs(curv.FirstParameter()) >= 1E6 ) || - (Abs(curv.LastParameter()) >= 1E6 )) { - aTypeString = strdup(tr("GEOM_LINE")) ; - } else - aTypeString = strdup(tr("GEOM_EDGE")) ; - return true ; - } else if ( curv.GetType() == GeomAbs_Circle ) { - if ( curv.IsClosed() ) - aTypeString = strdup(tr("GEOM_CIRCLE")) ; - else - aTypeString = strdup(tr("GEOM_ARC")) ; - return true ; - } else { - aTypeString = strdup(tr("GEOM_EDGE")) ; - return true ; - } + vw->onViewFitAll(); } - case TopAbs_VERTEX: - { aTypeString = strdup(tr("GEOM_VERTEX")) ; return true ; } - case TopAbs_SHAPE: - { aTypeString = strdup(tr("GEOM_SHAPE")) ; return true ; } } - return false ; -} + else if( ViewVTK ) { + SVTK_ViewWindow* vw = dynamic_cast( window ); + if ( vw ) { + vtkCamera* camera = vw->getRenderer()->GetActiveCamera(); + camera->SetPosition(DZ.X(), DZ.Y(), DZ.Z()); + camera->SetViewUp(DY.X(), DY.Y(), DY.Z()); + camera->SetFocalPoint(0,0,0); -//================================================================================= -// function : CreateArrowForLinearEdge() -// purpose : Create a cone topology to be used to display an arrow in the middle -// : of an edge showing its orientation. (For simulation and Viewer OCC only) -//================================================================================= -bool GeometryGUI::CreateArrowForLinearEdge( const TopoDS_Shape& tds, TopoDS_Shape& ArrowCone ) -{ - if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_OCC || tds.ShapeType() != TopAbs_EDGE ) - return false; - - OCCViewer_ViewPort* vp = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewPort(); - Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)vp)->getView(); - Standard_Real Width, Height ; - view3d->Size(Width, Height) ; - const Standard_Real aHeight = (Width + Height) / 50.0 ; - - try { - Standard_Real first, last ; - Handle(Geom_Curve) curv = BRep_Tool::Curve(TopoDS::Edge(tds), first, last); - if( !curv->IsCN(1) ) - return false ; - - const Standard_Real param = (first+last) / 2.0 ; - gp_Pnt middleParamPoint ; - gp_Vec V1 ; - curv->D1( param, middleParamPoint, V1) ; - if ( V1.Magnitude() < Precision::Confusion() ) - return false ; - - /* Topology orientation not geom orientation */ - if( tds.Orientation() == TopAbs_REVERSED ) - V1 *= -1.0 ; - - gp_Ax2 anAxis( middleParamPoint, gp_Dir(V1) ) ; - const Standard_Real radius1 = aHeight / 5.0 ; - if( radius1 > 10.0 * Precision::Confusion() && aHeight > 10.0 * Precision::Confusion() ) { - ArrowCone = BRepPrimAPI_MakeCone( anAxis, radius1, 0.0, aHeight ).Shape() ; - return true ; + vw->onFitAll(); } } - catch(Standard_Failure) { - // OCC failures are hard to catch in GUI. - // This because of the position for #include that is very critic to find - // in SALOME environment : compilation error ! - } - return false ; } - //======================================================================= -// function : SelectionByNameInDialogs() -// purpose : Called when user has entered a name of object in a LineEdit. -// : The selection is changed. Dialog box will receive the -// : corresponding signal to manage this event. +// function : GeometryGUI::SetActiveDialogBox() +// purpose : Set active dialog box //======================================================================= -bool GeometryGUI::SelectionByNameInDialogs( QWidget* aWidget, const QString& objectUserName, SALOME_Selection* Sel ) +void GeometryGUI::SetActiveDialogBox( QDialog* aDlg ) { - - /* Find SObject with name in component GEOM */ - SALOMEDS::Study_var ST = this->myActiveStudy->getStudyDocument() ; - SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject ; - listSO = ST->FindObjectByName( objectUserName, "GEOM" ) ; - - if ( listSO->length() < 1 ) { - const QString caption = tr("GEOM_WRN_WARNING") ; - const QString text = tr("GEOM_NAME_INCORRECT") ; - const QString button0 = tr("GEOM_BUT_OK") ; - QMessageBox::warning( aWidget, caption, text, button0 ) ; - return false ; - } - /* More than one object with same name */ - if ( listSO->length() > 1 ) { - const QString caption = tr("GEOM_WRN_WARNING") ; - const QString text = tr("GEOM_IDENTICAL_NAMES_SELECT_BY_MOUSE") ; - const QString button0 = tr("GEOM_BUT_OK") ; - QMessageBox::warning( aWidget, caption, text, button0 ) ; - return false ; - } - - SALOMEDS::SObject_var theObj = listSO[0] ; - /* Create a SALOME_InteractiveObject with a SALOME::SObject */ - Standard_CString anEntry = theObj->GetID() ; - Handle(SALOME_InteractiveObject) SI = new SALOME_InteractiveObject( anEntry, "GEOM", strdup(objectUserName) ) ; - - /* Add as a selected object */ - /* Clear any previous selection : */ - /* Warning the LineEdit is purged because of signal currentSelectionChanged ! */ - Sel->ClearIObjects() ; - Sel->AddIObject( SI ) ; - return true ; + myActiveDialogBox = (QDialog*)aDlg; } - //======================================================================= -// function : MakePointAndDisplay -// purpose : +// function : GeometryGUI::EmitSignalDeactivateDialog() +// purpose : Emit a signal to deactivate the active dialog Box //======================================================================= -void GeometryGUI::MakePointAndDisplay( const double x, const double y, const double z ) +void GeometryGUI::EmitSignalDeactivateDialog() { - try { - GEOM::GEOM_Shape_var P = myComponentGeom->MakeVertex( x, y, z ); - P->NameType( tr("GEOM_VERTEX") ); - if ( Display( P, "") ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - return ; + emit SignalDeactivateActiveDialog(); } - - //======================================================================= -// function : MakeVectorAndDisplay() -// purpose : +// function : GeometryGUI::EmitSignalCloseAllDialogs() +// purpose : Emit a signal to close all non modal dialogs box //======================================================================= -void GeometryGUI::MakeVectorAndDisplay( const gp_Pnt P1, const gp_Pnt P2 ) +void GeometryGUI::EmitSignalCloseAllDialogs() { - try { - GEOM::PointStruct pstruct1 = myComponentGeom->MakePointStruct( P1.X(), P1.Y(), P1.Z() ) ; - GEOM::PointStruct pstruct2 = myComponentGeom->MakePointStruct( P2.X(), P2.Y(), P2.Z() ) ; - GEOM::GEOM_Shape_var Vector = myComponentGeom->MakeVector( pstruct1, pstruct2 ); - Vector->NameType(tr("GEOM_VECTOR")); - if ( Display( Vector, "") ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } + emit SignalCloseAllDialogs(); } - //======================================================================= -// function : MakeBoxAndDisplay() -// purpose : +// function : GeometryGUI::EmitSignalDefaultStepValueChanged() +// purpose : Emit a signal to inform that default real spin box step has +// been changed //======================================================================= -void GeometryGUI::MakeBoxAndDisplay( const gp_Pnt P1, const gp_Pnt P2 ) +void GeometryGUI::EmitSignalDefaultStepValueChanged(double newVal) { - try { - GEOM::GEOM_Shape_var box = myComponentGeom->MakeBox( P1.X(), P1.Y(), P1.Z(), P2.X(), P2.Y(), P2.Z() ); - box->NameType(tr("GEOM_BOX")); - if ( Display( box, "") ) { - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - } - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } + emit SignalDefaultStepValueChanged(newVal); } - - - //======================================================================= -// function : MakePlaneAndDisplay() -// purpose : Plane point is P1 and dx, dy, dz define a normal vector +// function : GeometryGUI::OnGUIEvent() +// purpose : common slot for all menu/toolbar actions //======================================================================= -void GeometryGUI::MakePlaneAndDisplay( const gp_Pnt P1, const Standard_Real dx, - const Standard_Real dy, const Standard_Real dz, - const Standard_Real TrimSize ) +void GeometryGUI::OnGUIEvent() { - try { - gp_Dir aDirection; - aDirection.SetCoord(dx, dy, dz) ; - gp_Ax2 Axis( P1, aDirection ); - - GEOM::PointStruct pstruct = myComponentGeom->MakePointStruct(P1.X(), P1.Y(), P1.Z() ) ; - GEOM::PointStruct d = myComponentGeom->MakePointStruct(aDirection.X(), aDirection.Y(), aDirection.Z()) ; - GEOM::DirStruct dstruct = myComponentGeom->MakeDirection(d) ; - GEOM::GEOM_Shape_ptr plane = myComponentGeom->MakePlane(pstruct, dstruct, TrimSize) ; - plane->NameType(tr("GEOM_PLANE")); - if ( Display( plane, "") ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } + const QObject* obj = sender(); + if ( !obj || !obj->inherits( "QAction" ) ) + return; + int id = actionId((QAction*)obj); + if ( id != -1 ) + OnGUIEvent( id ); } - //======================================================================= -// function : MakeWorkingPlane() -// purpose : Change the point of view3d +// function : GeometryGUI::OnGUIEvent() +// purpose : manage all events on GUI [static] //======================================================================= -void GeometryGUI::MakeWorkingPlane( const gp_Pnt P, const gp_Dir D) +void GeometryGUI::OnGUIEvent( int id ) { - if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_OCC) { - GeomGUI->myDesktop->putInfo( tr("GEOM_PRP_NOT_FOR_VTK_VIEWER") ) ; - return ; - } - OCCViewer_ViewPort* vp = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewPort(); - Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)vp)->getView(); - view3d->SetAt( P.X(), P.Y(), P.Z() ); - view3d->SetProj( D.X(), D.Y(), D.Z() ); - myDesktop->putInfo(tr("GEOM_PRP_DONE")); -} + SUIT_Application* anApp = application(); + if (!anApp) return; + SUIT_Desktop* desk = anApp->desktop(); + // check type of the active viewframe + SUIT_ViewWindow* window = desk->activeWindow(); + bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() ); + bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() ); + // if current viewframe is not of OCC and not of VTK type - return immediately + // fix for IPAL8958 - allow some commands to execute even when NO viewer is active (rename for example) + bool NotViewerDependentCommand = ( id == 901 || id == 216 || id == 213 ); + if ( !ViewOCC && !ViewVTK && !NotViewerDependentCommand ) + return; -//======================================================================= -// function : MakePrismAndDisplay() -// purpose : P1 and P2 is to define a vector for prism -//======================================================================= -void GeometryGUI::MakePrismAndDisplay( GEOM::GEOM_Shape_ptr BaseShape, const gp_Pnt P1, const gp_Pnt P2 ) -{ - try { - GEOM::PointStruct PS1 = myComponentGeom->MakePointStruct(P1.X(), P1.Y(), P1.Z() ) ; - GEOM::PointStruct PS2 = myComponentGeom->MakePointStruct(P2.X(), P2.Y(), P2.Z() ) ; - if( BaseShape->_is_nil() ) { - myDesktop->putInfo (tr("GEOM_PRP_NULLSHAPE")) ; - return ; - } - - GEOM::GEOM_Shape_ptr result = myComponentGeom->MakePrism( BaseShape, PS1, PS2 ) ; - if (result->_is_nil()) { - myDesktop->putInfo (tr("GEOM_PRP_NULLSHAPE")) ; - return ; - } - - TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, result); - Standard_CString type; - GetShapeTypeString(S,type); - result->NameType( type ); - - if ( Display( result, "") ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); + // fix for IPAL9103, point 2 + if ( CORBA::is_nil( GetGeomGen() ) ) { + SUIT_MessageBox::error1( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_GET_ENGINE" ), tr( "GEOM_BUT_OK" ) ); + return; } - return ; -} - -//===================================================================================== -// function : MakeLineAndDisplay() -// purpose : Create an infinite oriented line (linear edge in fact) -//===================================================================================== -void GeometryGUI::MakeLineAndDisplay( const gp_Pnt InitPoint, const gp_Pnt LastPoint ) -{ - gp_Pnt P1,P2; - double dx, dy, dz ; - GetBipointDxDyDz( InitPoint, LastPoint, dx, dy, dz ) ; - Standard_Real length = InitPoint.Distance(LastPoint) ; - if( length <= Precision::Confusion() ) { - myDesktop->putInfo(tr("GEOM_PRP_ABORT")); - return ; - } - - Standard_Real coeff = 1E6 / length ; - - /* To create a line with length = 1E6 */ - /* Precision::Infinite() is 1E100 in OCC */ - P1.SetX( InitPoint.X() - (coeff * dx) ) ; - P1.SetY( InitPoint.Y() - (coeff * dy) ) ; - P1.SetZ( InitPoint.Z() - (coeff * dz) ) ; - - P2.SetX( LastPoint.X() + (coeff * dx) ) ; - P2.SetY( LastPoint.Y() + (coeff * dy) ) ; - P2.SetZ( LastPoint.Z() + (coeff * dz) ) ; - - try { - GEOM::PointStruct pstruct = myComponentGeom->MakePointStruct(P1.X(), P1.Y(), P1.Z()) ; - GEOM::PointStruct d = myComponentGeom->MakePointStruct(P2.X(), P2.Y(), P2.Z()) ; - GEOM::DirStruct dstruct = myComponentGeom->MakeDirection(d) ; - - GEOM::GEOM_Shape_ptr result = myComponentGeom->MakeLine(pstruct, dstruct) ; - if(result->_is_nil()) { - myDesktop->putInfo(tr("GEOM_PRP_ABORT")); - return ; - } - result->NameType(tr("GEOM_LINE")); - - if ( Display( result, "") ) - myDesktop->putInfo(tr("GEOM_PRP_READY")); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - return ; + GEOMGUI* library = 0; + // try to get-or-load corresponding GUI library + if( id == 111 || // MENU FILE - IMPORT BREP + id == 112 || // MENU FILE - IMPORT IGES + id == 113 || // MENU FILE - IMPORT STEP + id == 121 || // MENU FILE - EXPORT BREP + id == 122 || // MENU FILE - EXPORT IGES + id == 123 || // MENU FILE - EXPORT STEP + id == 2171 || // POPUP VIEWER - SELECT ONLY - VERTEX + id == 2172 || // POPUP VIEWER - SELECT ONLY - EDGE + id == 2173 || // POPUP VIEWER - SELECT ONLY - WIRE + id == 2174 || // POPUP VIEWER - SELECT ONLY - FACE + id == 2175 || // POPUP VIEWER - SELECT ONLY - SHELL + id == 2176 || // POPUP VIEWER - SELECT ONLY - SOLID + id == 2177 || // POPUP VIEWER - SELECT ONLY - COMPOUND + id == 2178 || // POPUP VIEWER - SELECT ONLY - SELECT ALL + id == 31 || // MENU EDIT - COPY + id == 33 || // MENU EDIT - DELETE + id == 411 || // MENU SETTINGS - ADD IN STUDY + id == 412 || // MENU SETTINGS - SHADING COLOR + id == 413 || // MENU SETTINGS - ISOS + id == 414 || // MENU SETTINGS - STEP VALUE FOR SPIN BOXES + id == 5103 || // MENU TOOLS - CHECK GEOMETRY + id == 8032 || // POPUP VIEWER - COLOR + id == 8033 || // POPUP VIEWER - TRANSPARENCY + id == 8034 || // POPUP VIEWER - ISOS + id == 804 || // POPUP VIEWER - ADD IN STUDY + id == 901 || // OBJECT BROWSER - RENAME + id == 9024 ) { // OBJECT BROWSER - OPEN + //cout << "id " << id << " received" << endl; +#ifndef WNT + library = getLibrary( "libGEOMToolsGUI.so" ); +#else + library = getLibrary( "GEOMToolsGUI.dll" ); +#endif + } + else if( id == 211 || // MENU VIEW - WIREFRAME/SHADING + id == 212 || // MENU VIEW - DISPLAY ALL + id == 213 || // MENU VIEW - DISPLAY ONLY + id == 214 || // MENU VIEW - ERASE ALL + id == 215 || // MENU VIEW - ERASE + id == 216 || // MENU VIEW - DISPLAY + id == 80311 || // POPUP VIEWER - WIREFRAME + id == 80312 ) { // POPUP VIEWER - SHADING +#ifndef WNT + library = getLibrary( "libDisplayGUI.so" ); +#else + library = getLibrary( "DisplayGUI.dll" ); +#endif + } + else if( id == 4011 || // MENU BASIC - POINT + id == 4012 || // MENU BASIC - LINE + id == 4013 || // MENU BASIC - CIRCLE + id == 4014 || // MENU BASIC - ELLIPSE + id == 4015 || // MENU BASIC - ARC + id == 4016 || // MENU BASIC - VECTOR + id == 4017 || // MENU BASIC - PLANE + id == 4018 || // MENU BASIC - WPLANE + id == 4019 || // MENU BASIC - CURVE + id == 4020 ) { // MENU BASIC - REPAIR +#ifndef WNT + library = getLibrary( "libBasicGUI.so" ); +#else + library = getLibrary( "BasicGUI.dll" ); +#endif + } + else if( id == 4021 || // MENU PRIMITIVE - BOX + id == 4022 || // MENU PRIMITIVE - CYLINDER + id == 4023 || // MENU PRIMITIVE - SPHERE + id == 4024 || // MENU PRIMITIVE - TORUS + id == 4025 ) { // MENU PRIMITIVE - CONE +#ifndef WNT + library = getLibrary( "libPrimitiveGUI.so" ); +#else + library = getLibrary( "PrimitiveGUI.dll" ); +#endif + } + else if( id == 4031 || // MENU GENERATION - PRISM + id == 4032 || // MENU GENERATION - REVOLUTION + id == 4033 || // MENU GENERATION - FILLING + id == 4034 ) { // MENU GENERATION - PIPE +#ifndef WNT + library = getLibrary( "libGenerationGUI.so" ); +#else + library = getLibrary( "GenerationGUI.dll" ); +#endif + } + else if( id == 404 || // MENU ENTITY - SKETCHER + id == 407 ) { // MENU ENTITY - EXPLODE +#ifndef WNT + library = getLibrary( "libEntityGUI.so" ); +#else + library = getLibrary( "EntityGUI.dll" ); +#endif + } + else if( id == 4081 || // MENU BUILD - EDGE + id == 4082 || // MENU BUILD - WIRE + id == 4083 || // MENU BUILD - FACE + id == 4084 || // MENU BUILD - SHELL + id == 4085 || // MENU BUILD - SOLID + id == 4086 ) { // MENU BUILD - COMPUND +#ifndef WNT + library = getLibrary( "libBuildGUI.so" ); +#else + library = getLibrary( "BuildGUI.dll" ); +#endif + } + else if( id == 5011 || // MENU BOOLEAN - FUSE + id == 5012 || // MENU BOOLEAN - COMMON + id == 5013 || // MENU BOOLEAN - CUT + id == 5014 ) { // MENU BOOLEAN - SECTION +#ifndef WNT + library = getLibrary( "libBooleanGUI.so" ); +#else + library = getLibrary( "BooleanGUI.dll" ); +#endif + } + else if( id == 5021 || // MENU TRANSFORMATION - TRANSLATION + id == 5022 || // MENU TRANSFORMATION - ROTATION + id == 5023 || // MENU TRANSFORMATION - LOCATION + id == 5024 || // MENU TRANSFORMATION - MIRROR + id == 5025 || // MENU TRANSFORMATION - SCALE + id == 5026 || // MENU TRANSFORMATION - OFFSET + id == 5027 || // MENU TRANSFORMATION - MULTI-TRANSLATION + id == 5028 ) { // MENU TRANSFORMATION - MULTI-ROTATION +#ifndef WNT + library = getLibrary( "libTransformationGUI.so" ); +#else + library = getLibrary( "TransformationGUI.dll" ); +#endif + } + else if( id == 503 || // MENU OPERATION - PARTITION + id == 504 || // MENU OPERATION - ARCHIMEDE + id == 505 || // MENU OPERATION - FILLET + id == 506 || // MENU OPERATION - CHAMFER + id == 507 ) { // MENU OPERATION - CLIPPING RANGE +#ifndef WNT + library = getLibrary( "libOperationGUI.so" ); +#else + library = getLibrary( "OperationGUI.dll" ); +#endif + } + else if( id == 601 || // MENU REPAIR - SEWING + id == 603 || // MENU REPAIR - SUPPRESS FACES + id == 604 || // MENU REPAIR - SUPPRESS HOLE + id == 605 || // MENU REPAIR - SHAPE PROCESSING + id == 606 || // MENU REPAIR - CLOSE CONTOUR + id == 607 || // MENU REPAIR - REMOVE INTERNAL WIRES + id == 608 || // MENU REPAIR - ADD POINT ON EDGE + id == 609 || // MENU REPAIR - FREE BOUNDARIES + id == 610 || // MENU REPAIR - FREE FACES + id == 611 || // MENU REPAIR - CHANGE ORIENTATION + id == 602 ) { // MENU REPAIR - GLUE FACES +#ifndef WNT + library = getLibrary( "libRepairGUI.so" ); +#else + library = getLibrary( "RepairGUI.dll" ); +#endif + } + else if( id == 701 || // MENU MEASURE - PROPERTIES + id == 702 || // MENU MEASURE - CDG + id == 703 || // MENU MEASURE - INERTIA + id == 7041 || // MENU MEASURE - BOUNDING BOX + id == 7042 || // MENU MEASURE - MIN DISTANCE + id == 705 || // MENU MEASURE - TOLERANCE + id == 706 || // MENU MEASURE - WHATIS + id == 707 || // MENU MEASURE - CHECK + id == 7072 || // MENU MEASURE - CHECK COMPOUND OF BLOCKS + id == 708 ) { // MENU MEASURE - POINT COORDINATES +#ifndef WNT + library = getLibrary( "libMeasureGUI.so" ); +#else + library = getLibrary( "MeasureGUI.dll" ); +#endif + } + else if( id == 800 || // MENU GROUP - CREATE + id == 8001 || // POPUP MENU - CREATE GROUP + id == 801 ) { // MENU GROUP - EDIT +#ifndef WNT + library = getLibrary( "libGroupGUI.so" ); +#else + library = getLibrary( "GroupGUI.dll" ); +#endif + } + else if( id == 9999 || // MENU BLOCKS - HEXAHEDRAL SOLID + id == 9998 || // MENU BLOCKS - MULTI-TRANSFORMATION + id == 9997 || // MENU BLOCKS - QUADRANGLE FACE + id == 99991 || // MENU BLOCKS - PROPAGATE + id == 9995 ) { // MENU BLOCKS - EXPLODE ON BLOCKS +#ifndef WNT + library = getLibrary( "libBlocksGUI.so" ); +#else + library = getLibrary( "BlocksGUI.dll" ); +#endif + } + + // call method of corresponding GUI library + if ( library ) + library->OnGUIEvent( id, desk ); + else + SUIT_MessageBox::error1( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_LIB_NOT_FOUND" ), tr( "GEOM_BUT_OK" ) ); } - -//======================================================================= -// function : MakeBooleanAndDisplay() -// purpose : -//======================================================================= -void GeometryGUI::MakeBooleanAndDisplay( GEOM::GEOM_Shape_ptr Shape1, GEOM::GEOM_Shape_ptr Shape2, const short operation ) +//================================================================================= +// function : GeometryGUI::OnKeyPress() +// purpose : Called when any key is pressed by user [static] +//================================================================================= +void GeometryGUI::OnKeyPress( SUIT_ViewWindow* win, QKeyEvent* pe ) { - try { - GEOM::GEOM_Shape_ptr result = myComponentGeom->MakeBoolean( Shape1, Shape2, operation ) ; - if (result->_is_nil()) { - myDesktop->putInfo (tr("GEOM_PRP_NULLSHAPE")) ; - return ; - } - - TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, result); - Standard_CString type; - GetShapeTypeString(S,type); - result->NameType( type ); - - if ( Display( result, "") ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); + GUIMap::Iterator it; + bool bOk = true; + for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it ) { + SUIT_Application* anApp = application(); + if (!anApp) return; + bOk = bOk && it.data()->OnKeyPress( pe, anApp->desktop(), win ); } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - return ; +// return bOk; } -//===================================================================================== -// function : MakeSphere() -// purpose : -//===================================================================================== -void GeometryGUI::MakeSphereAndDisplay( const gp_Pnt aCenterPoint, const double aRadius ) +//================================================================================= +// function : GeometryGUI::OnMouseMove() +// purpose : Manages mouse move events [static] +//================================================================================= +void GeometryGUI::OnMouseMove( SUIT_ViewWindow* win, QMouseEvent* pe ) { - try { - if( aRadius <= Precision::Confusion() ) { - QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("GEOM_WRN_WARNING"), - tr ("GEOM_WRN_RADIUS_NULL"), tr ("GEOM_BUT_YES") ); - return ; - } - GEOM::GEOM_Shape_ptr result = myComponentGeom->MakeSphere(aCenterPoint.X(),aCenterPoint.Y(),aCenterPoint.Z(), aRadius); - result->NameType(tr("GEOM_SPHERE")); - if ( Display( result, "") ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); + GUIMap::Iterator it; + bool bOk = true; + for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it ) { + SUIT_Application* anApp = application(); + if (!anApp) return; + bOk = bOk && it.data()->OnMouseMove( pe, anApp->desktop(), win ); } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - return ; +// return bOk; } -//===================================================================================== -// function : MakeConeAndDisplay() -// purpose : -//===================================================================================== -void GeometryGUI::MakeConeAndDisplay( const gp_Pnt BasePoint, - const gp_Dir aDir, - const double Radius1, - const double Radius2, - const double aHeight ) -{ - try { - if( ( Radius1 <= Precision::Confusion() && Radius2 <= Precision::Confusion() ) || aHeight <= Precision::Confusion() ) - return ; - GEOM::PointStruct pstruct = myComponentGeom->MakePointStruct( BasePoint.X(), BasePoint.Y(), BasePoint.Z() ) ; - GEOM::PointStruct d = myComponentGeom->MakePointStruct( aDir.X(), aDir.Y(), aDir.Z() ) ; - GEOM::DirStruct dstruct = myComponentGeom->MakeDirection(d) ; - - GEOM::GEOM_Shape_var result = myComponentGeom->MakeCone( pstruct, dstruct, Radius1, Radius2, aHeight ) ; - if ( result->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_ABORT")); - return ; +//================================================================================= +// function : GeometryGUI::0nMousePress() +// purpose : Manage mouse press events [static] +//================================================================================= +void GeometryGUI::OnMousePress( SUIT_ViewWindow* win, QMouseEvent* pe ) +{ + GUIMap::Iterator it; + // OnMousePress() should return false if this event should be processed further + // (see OCCViewer_Viewer3d::onMousePress() for explanation) + bool processed = false; + for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it ) { + SUIT_Application* anApp = application(); + if (!anApp) return; + processed = processed || it.data()->OnMousePress( pe, anApp->desktop(), win ); + } +// return processed; +} + +/* +static void UpdateVtkSelection() +{ + QPtrList winList = application()->desktop()->windows(); + SUIT_ViewWindow* win = 0; + for ( win = winList.first(); win; win = winList.next() ) { + if ( win->getViewManager()->getTypeView() == VIEW_VTK ) { + SVTK_ViewWindow* vw = dynamic_cast( window ); + if ( vw ) { + SVTK_RenderWindowInteractor* anInteractor = vw->getRWInteractor(); + anInteractor->SetSelectionProp(); + anInteractor->SetSelectionTolerance(); + SVTK_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME(); + if (aStyle) { + aStyle->setPreselectionProp(); + } + } } - result->NameType(tr("GEOM_CONE")); - if ( Display( result, "") ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); } - return ; } - -//===================================================================================== -// function : MakeCylinderAndDisplay() -// purpose : -//===================================================================================== -void GeometryGUI::MakeCylinderAndDisplay( const gp_Pnt BasePoint, - const gp_Dir aDir, - const double Radius, - const double aHeight ) +//================================================================================= +// function : GeometryGUI::SetSettings() +// purpose : Called when GEOM module is activated [static] +//================================================================================= +bool GeometryGUI::SetSettings() { - try { - if( Radius <= Precision::Confusion() || aHeight <= Precision::Confusion() ) - return ; - GEOM::PointStruct pstruct = myComponentGeom->MakePointStruct( BasePoint.X(), BasePoint.Y(), BasePoint.Z() ) ; - GEOM::PointStruct d = myComponentGeom ->MakePointStruct( aDir.X(), aDir.Y(), aDir.Z() ) ; - GEOM::DirStruct dstruct = myComponentGeom->MakeDirection(d) ; - - GEOM::GEOM_Shape_var result = myComponentGeom->MakeCylinder(pstruct, dstruct, Radius, aHeight) ; - if ( result->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_ABORT")); - return ; - } - result->NameType(tr("GEOM_CYLINDER")); - if ( Display( result, "") ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - return ; -} - + QMenuBar* Mb = parent->getMainMenuBar(); + SUIT_Study* ActiveStudy = application()->activeStudy(); -//===================================================================================== -// function : MakeTorusAndDisplay() -// purpose : -//===================================================================================== -void GeometryGUI::MakeTorusAndDisplay( const gp_Pnt BasePoint, - const gp_Dir aDir, - const double Radius1, - const double Radius2 ) -{ - try { - if( Radius1 <= Precision::Confusion() || Radius2 <= Precision::Confusion() ) - return ; - - GEOM::PointStruct pstruct = myComponentGeom->MakePointStruct( BasePoint.X(), BasePoint.Y(), BasePoint.Z() ) ; - GEOM::PointStruct d = myComponentGeom ->MakePointStruct( aDir.X(), aDir.Y(), aDir.Z() ) ; - GEOM::DirStruct dstruct = myComponentGeom->MakeDirection(d) ; - - GEOM::GEOM_Shape_var result = myComponentGeom->MakeTorus(pstruct, dstruct, Radius1, Radius2) ; - if ( result->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_ABORT")); - return ; +// Wireframe or Shading + int DisplayMode = 0; + SUIT_ViewWindow* window = application()->desktop()->activeWindow(); + bool ViewOCC = ( window && window->getViewManager()->getType() == VIEW_OCC ); + bool ViewVTK = ( window && window->getViewManager()->getType() == VIEW_VTK ); + if ( ViewOCC ) { + OCCViewer_ViewManager* vm = dynamic_cast( window->getViewManager() ); + if ( vm ) { + Handle(AIS_InteractiveContext) ic = vm->getOCCViewer()->getAISContext(); + DisplayMode = ic->DisplayMode(); } - result->NameType(tr("GEOM_TORUS")); - if ( Display( result, "") ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); + else if ( ViewVTK ) { + SVTK_ViewWindow* vw = dynamic_cast( window ); + if ( vw ) { + SVTK_RenderWindowInteractor* myRenderInter = vw->getRWInteractor(); + DisplayMode = myRenderInter->GetDisplayMode(); + } } - return ; -} + if( DisplayMode == 1 ) + getApp()-> + Mb->changeItem( 211, tr( "GEOM_MEN_WIREFRAME" ) ); + else + Mb->changeItem( 211, tr( "GEOM_MEN_SHADING" ) ); -//===================================================================================== -// function : MakePipeAndDisplay() -// purpose : -//===================================================================================== -void GeometryGUI::MakePipeAndDisplay( GEOM::GEOM_Shape_ptr aPath, GEOM::GEOM_Shape_ptr aBase ) -{ - try { - GEOM::GEOM_Shape_ptr result = myComponentGeom->MakePipe(aPath, aBase); - if ( !result->_is_nil() && Display( result, "") ) { - TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, result); - Standard_CString type; - GetShapeTypeString(S,type); - result->NameType( type ); - - myDesktop->putInfo( tr("GEOM_PRP_DONE") ); - } - else { - myDesktop->putInfo(tr("GEOM_PRP_ABORT")); - } - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - return ; -} - - -//===================================================================================== -// function : MakeFillingAndDisplay() -// purpose : -//===================================================================================== -void GeometryGUI::MakeFillingAndDisplay( GEOM::GEOM_Shape_ptr SectionShape, - const short mindeg, - const short maxdeg, - const double tol3d, - const double tol2d, - const short nbiter ) -{ - try { - GEOM::GEOM_Shape_ptr result = myComponentGeom->MakeFilling( SectionShape, - mindeg, maxdeg, - tol3d, tol2d, nbiter ); - if (result->_is_nil()) { - myDesktop->putInfo (tr("GEOM_PRP_NULLSHAPE")) ; - return ; - } - - TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, result); - Standard_CString type; - GetShapeTypeString(S,type); - result->NameType( type ); - - if ( Display( result, "") ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - return ; - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } -} - - - -//===================================================================================== -// function : MakeMirrorAndDisplay() -// purpose : -//===================================================================================== -void GeometryGUI::MakeMirrorAndDisplay( GEOM::GEOM_Shape_ptr Shape1, GEOM::GEOM_Shape_ptr Shape2 ) -{ - try { - GEOM::GEOM_Shape_var result = myComponentGeom->MakeMirrorByPlane( Shape1, Shape2 ); - if (result->_is_nil()) { - myDesktop->putInfo (tr("GEOM_PRP_NULLSHAPE")) ; - return ; - } - result->NameType( Shape1->NameType() ); - if ( Display( result, "") ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - return ; -} - - -//===================================================================================== -// function : MakeSewingAndDisplay() -// purpose : -//===================================================================================== -void GeometryGUI::MakeSewingAndDisplay( GEOM::GEOM_Gen::ListOfIOR& listShapesIOR, - const Standard_Real precision ) -{ - try { - GEOM::GEOM_Shape_var result = myComponentGeom->MakeSewing(listShapesIOR, precision) ; - if( result->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_NULLSHAPE")) ; - return ; - } - - TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, result); - Standard_CString type; - GetShapeTypeString(S,type); - result->NameType( type ); - - if( Display( result, "") ) - myDesktop ->putInfo(tr("GEOM_PRP_DONE")) ; - return ; - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } -} - - -//===================================================================================== -// function : MakeCompoundAndDisplay() -// purpose : -//===================================================================================== -void GeometryGUI::MakeCompoundAndDisplay( GEOM::GEOM_Gen::ListOfIOR& listShapesIOR ) -{ - try { - GEOM::GEOM_Shape_var result = myComponentGeom->MakeCompound(listShapesIOR) ; - if( result->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_NULLSHAPE")) ; - return ; - } - result->NameType(tr("GEOM_COMPOUND")); - if( Display( result, "" )) - myDesktop->putInfo(tr("GEOM_PRP_DONE")) ; - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - return ; -} - - -//===================================================================================== -// function : MakeFaceAndDisplay() -// purpose : -//===================================================================================== -void GeometryGUI::MakeFaceAndDisplay( GEOM::GEOM_Shape_ptr aWire, const Standard_Boolean wantPlanar ) -{ - try { - GEOM::GEOM_Shape_var result = myComponentGeom->MakeFace( aWire, wantPlanar) ; - if( result->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_NULLSHAPE")) ; - return ; - } - if ( wantPlanar ) - result->NameType(tr("GEOM_PLANE")); - else - result->NameType(tr("GEOM_FACE")); - if( Display( result, "") ) - myDesktop ->putInfo(tr("GEOM_PRP_DONE")) ; - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - return ; -} - - - -//===================================================================================== -// function : MakeLinearEdgeAndDisplay() -// purpose : -//===================================================================================== -void GeometryGUI::MakeLinearEdgeAndDisplay( const gp_Pnt P1, const gp_Pnt P2 ) -{ - try { - GEOM::PointStruct ps1 = myComponentGeom->MakePointStruct( P1.X(), P1.Y(), P1.Z() ) ; - GEOM::PointStruct ps2 = myComponentGeom->MakePointStruct( P2.X(), P2.Y(), P2.Z() ) ; - GEOM::GEOM_Shape_var result = myComponentGeom->MakeEdge( ps1, ps2 ) ; - if( result->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_NULLSHAPE")) ; - return ; - } - result->NameType(tr("GEOM_EDGE")); - if( Display( result, "") ) - myDesktop ->putInfo(tr("GEOM_PRP_DONE")) ; - } - catch(const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - return ; -} - - -//===================================================================================== -// function : MakeOrientationChangeAndDisplay() -// purpose : -//===================================================================================== -void GeometryGUI::MakeOrientationChangeAndDisplay( GEOM::GEOM_Shape_ptr Shape ) -{ - try { - GEOM::GEOM_Shape_var result = myComponentGeom->OrientationChange( Shape ) ; - if( result->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_NULLSHAPE")) ; - return ; - } - result->NameType( Shape->NameType() ); - if ( Display( result, "" )) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - return ; - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } -} - - -//===================================================================================== -// function : MakeScaleAndDisplay() -// purpose : -//===================================================================================== -void GeometryGUI::MakeScaleAndDisplay( GEOM::GEOM_Shape_ptr Shape, const gp_Pnt centralPoint, const Standard_Real factor ) -{ - try { - GEOM::PointStruct P = myComponentGeom->MakePointStruct(centralPoint.X(), centralPoint.Y(), centralPoint.Z() ) ; - GEOM::GEOM_Shape_var result = myComponentGeom->MakeScaleTransform(Shape, P, factor) ; - // result->NameType(tr("GEOM_SCALE")); - result->NameType( Shape->NameType() ); - if ( Display( result, "") ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - else - myDesktop->putInfo (tr("GEOM_PRP_NULLSHAPE")) ; - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - return ; -} - - -//======================================================================================= -// function : MakeRevolutionAndDisplay() -// purpose : -//======================================================================================= -void GeometryGUI::MakeRevolutionAndDisplay( GEOM::GEOM_Shape_ptr Shape, const gp_Pnt loc, const gp_Dir dir, const Standard_Real revolAngle ) -{ - try { - GEOM::AxisStruct axis = myComponentGeom->MakeAxisStruct(loc.X(), loc.Y(), loc.Z(), dir.X(), dir.Y(), dir.Z() ) ; - GEOM::GEOM_Shape_ptr result = myComponentGeom->MakeRevolution(Shape, axis, revolAngle) ; - if ( result->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_ABORT")); - return ; - } - - TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, result); - Standard_CString type; - GetShapeTypeString(S,type); - result->NameType( type ); - - if ( Display( result ) ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - return ; -} - - -//======================================================================================= -// function : MakeRotationAndDisplay() -// purpose : -//======================================================================================= -void GeometryGUI::MakeRotationAndDisplay( GEOM::GEOM_Shape_ptr Shape, - const gp_Pnt loc, - const gp_Dir dir, - const Standard_Real angle ) -{ - try { - const GEOM::AxisStruct axis = myComponentGeom->MakeAxisStruct(loc.X(), loc.Y(), loc.Z(), dir.X(), dir.Y(), dir.Z() ) ; - GEOM::GEOM_Shape_var result = myComponentGeom->MakeRotation(Shape, axis, angle); - if ( result->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_ABORT") ); - return ; - } - result->NameType( Shape->NameType() ); - if ( Display( result ) ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - return ; -} - - -//================================================================================= -// function : MakeTranslationAndDisplay() -// purpose : Translate a shape -//================================================================================= -void GeometryGUI::MakeTranslationAndDisplay( GEOM::GEOM_Shape_ptr Shape, gp_Vec V ) -{ - try { - GEOM::GEOM_Shape_var result = myComponentGeom->MakeTranslation( Shape, V.X(), V.Y(), V.Z() ) ; - if ( result->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_ABORT") ); - return ; - } - result->NameType( Shape->NameType() ); - if ( Display( result ) ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - return ; -} - -//================================================================================= -// function : MakeMultiTranslation1DAndDisplay() -// purpose : Multi-Translate a shape -//================================================================================= -void GeometryGUI::MakeMultiTranslation1DAndDisplay( GEOM::GEOM_Shape_ptr Shape, const gp_Dir Dir, const double Step, const short NbTimes ) -{ - try { - GEOM::PointStruct d = myComponentGeom->MakePointStruct( Dir.X(), Dir.Y(), Dir.Z() ) ; - GEOM::DirStruct dstruct = myComponentGeom->MakeDirection(d) ; - - GEOM::GEOM_Shape_var result = myComponentGeom->MakeMultiTranslation1D( Shape, dstruct, Step, NbTimes ); - if ( result->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_ABORT") ); - return ; - } - result->NameType( tr("GEOM_COMPOUND") ); - if ( Display( result ) ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - return ; -} - - -//================================================================================= -// function : MakeMultiTranslation2DAndDisplay() -// purpose : Multi-Translate a shape -//================================================================================= -void GeometryGUI::MakeMultiTranslation2DAndDisplay( GEOM::GEOM_Shape_ptr Shape, const gp_Dir Dir1, const double Step1, const short NbTimes1, const gp_Dir Dir2, const double Step2, const short NbTimes2 ) -{ - try { - GEOM::PointStruct d1 = myComponentGeom->MakePointStruct( Dir1.X(), Dir1.Y(), Dir1.Z() ) ; - GEOM::DirStruct dstruct1 = myComponentGeom->MakeDirection(d1) ; - GEOM::PointStruct d2 = myComponentGeom->MakePointStruct( Dir2.X(), Dir2.Y(), Dir2.Z() ) ; - GEOM::DirStruct dstruct2 = myComponentGeom->MakeDirection(d2) ; - - GEOM::GEOM_Shape_var result = myComponentGeom->MakeMultiTranslation2D( Shape, dstruct1, Step1, NbTimes1, dstruct2, Step2, NbTimes2 ); - if ( result->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_ABORT") ); - return ; - } - result->NameType( tr("GEOM_COMPOUND") ); - if ( Display( result ) ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - return ; -} - - -//================================================================================= -// function : MakeMultiRotation1DAndDisplay() -// purpose : Multi-Rotate a shape -//================================================================================= -void GeometryGUI::MakeMultiRotation1DAndDisplay( GEOM::GEOM_Shape_ptr Shape, const gp_Dir Dir, const gp_Pnt Loc, const short NbTimes ) -{ - try { - GEOM::PointStruct d = myComponentGeom->MakePointStruct( Dir.X(), Dir.Y(), Dir.Z() ) ; - GEOM::DirStruct dstruct = myComponentGeom->MakeDirection(d) ; - GEOM::PointStruct pstruct = myComponentGeom->MakePointStruct( Loc.X(), Loc.Y(), Loc.Z() ) ; - - GEOM::GEOM_Shape_var result = myComponentGeom->MakeMultiRotation1D( Shape, dstruct, pstruct, NbTimes ); - if ( result->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_ABORT") ); - return ; - } - result->NameType( tr("GEOM_COMPOUND") ); - if ( Display( result ) ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - return ; -} - - -//================================================================================= -// function : MakeMultiRotation2DAndDisplay() -// purpose : Multi-Rotate a shape -//================================================================================= -void GeometryGUI::MakeMultiRotation2DAndDisplay( GEOM::GEOM_Shape_ptr Shape, const gp_Dir Dir, const gp_Pnt Loc, const double Ang, const short NbTimes1, const double Step, const short NbTimes2 ) -{ - try { - GEOM::PointStruct d = myComponentGeom->MakePointStruct( Dir.X(), Dir.Y(), Dir.Z() ) ; - GEOM::DirStruct dstruct = myComponentGeom->MakeDirection(d) ; - GEOM::PointStruct pstruct = myComponentGeom->MakePointStruct( Loc.X(), Loc.Y(), Loc.Z() ) ; - - GEOM::GEOM_Shape_var result = myComponentGeom->MakeMultiRotation2D( Shape, dstruct, pstruct, Ang, NbTimes1, Step, NbTimes2 ); - if ( result->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_ABORT") ); - return ; - } - result->NameType( tr("GEOM_COMPOUND") ); - if ( Display( result ) ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - return ; -} - - - -//======================================================================================= -// function : MakeArcAndDisplay() -// purpose : Make an arc of circle from InitPoint to CirclePoint and passing on EndPoint -//======================================================================================= -void GeometryGUI::MakeArcAndDisplay( gp_Pnt InitPoint, gp_Pnt CirclePoint, gp_Pnt EndPoint ) -{ - gp_Vec v1( CirclePoint, InitPoint ) ; - gp_Vec v2( CirclePoint, EndPoint ) ; - if( v1.IsParallel(v2, Precision::Angular() ) ) - return ; - - try { - GEOM::PointStruct pI = myComponentGeom->MakePointStruct( InitPoint.X(), InitPoint.Y(), InitPoint.Z() ); - GEOM::PointStruct pC = myComponentGeom->MakePointStruct( CirclePoint.X(), CirclePoint.Y(), CirclePoint.Z() ); - GEOM::PointStruct pE = myComponentGeom->MakePointStruct( EndPoint.X(), EndPoint.Y(), EndPoint.Z() ); - GEOM::GEOM_Shape_var result = myComponentGeom->MakeArc(pI, pC, pE) ; - if ( result->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_ABORT")); - return ; - } - result->NameType(tr("GEOM_ARC")); - if ( Display( result ) ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - return ; -} - - -//===================================================================================== -// function : MakeCircleAndDisplay() -// purpose : -//===================================================================================== -void GeometryGUI::MakeCircleAndDisplay( const gp_Pnt CenterPoint, const gp_Dir dir, const Standard_Real Radius ) -{ - try { - GEOM::PointStruct pstruct = myComponentGeom->MakePointStruct( CenterPoint.X(), CenterPoint.Y(), CenterPoint.Z() ) ; - GEOM::PointStruct d = myComponentGeom->MakePointStruct( dir.X(), dir.Y(), dir.Z() ) ; - GEOM::DirStruct dstruct = myComponentGeom->MakeDirection(d) ; - - GEOM::GEOM_Shape_var result = myComponentGeom->MakeCircle(pstruct, dstruct, Radius) ; - if ( result->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_ABORT") ); - return ; - } - result->NameType(tr("GEOM_CIRCLE")); - if ( Display( result ) ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - return ; -} - - - -//===================================================================================== -// function : MakeWireAndDisplay() -// purpose : -//===================================================================================== -void GeometryGUI::MakeWireAndDisplay( GEOM::GEOM_Gen::ListOfIOR& listShapesIOR ) -{ - try { - GEOM::GEOM_Shape_var result = myComponentGeom->MakeWire(listShapesIOR) ; - if( result->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_NULLSHAPE")) ; - return ; - } - result->NameType(tr("GEOM_WIRE")); - if( Display( result, "") ) - myDesktop ->putInfo(tr("GEOM_PRP_DONE")) ; - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - return ; -} - - -//===================================================================================== -// function : MakePartitionAndDisplay() -// purpose : -//===================================================================================== -void GeometryGUI::MakePartitionAndDisplay (const GEOM::GEOM_Gen::ListOfIOR& listShapesIOR, - const GEOM::GEOM_Gen::ListOfIOR& listToolsIOR, - const GEOM::GEOM_Gen::ListOfIOR& listKeepInsIOR, - const GEOM::GEOM_Gen::ListOfIOR& listRemoveInsIOR, - const GEOM::shape_type limit) -{ - try { - GEOM::GEOM_Shape_var result = myComponentGeom->Partition(listShapesIOR, - listToolsIOR, - listKeepInsIOR, - listRemoveInsIOR, - (CORBA::Short) limit); - if( result->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_NULLSHAPE")) ; - return ; - } - result->NameType(tr("GEOM_PARTITION")); - if( Display( result, "") ) - myDesktop ->putInfo(tr("GEOM_PRP_DONE")) ; - return ; - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } -} - -//======================================================================= -// function : SetState() -// purpose : Sets myState = aState a private field indicating which methode is active -//======================================================================= -void GeometryGUI::SetState(int aState ) -{ this->myState = aState ; return ; } - - -//======================================================================= -// function : ResetState() -// purpose : Sets myState = -1 a private field indicating which methode is active -//======================================================================= -void GeometryGUI::ResetState() -{ this->myState = -1 ; return ; } - - -//======================================================================= -// function : EmitSignalDeactivateDialog() -// purpose : Emit a signal to deactivate the active dialog Box -//======================================================================= -void GeometryGUI::EmitSignalDeactivateDialog() -{ - emit this->SignalDeactivateActiveDialog() ; - return ; -} - -//======================================================================= -// function : EmitSignalCloseAllDialogs() -// purpose : Emit a signal to deactivate all non modal dialogs box -//======================================================================= -void GeometryGUI::EmitSignalCloseAllDialogs() -{ - emit this->SignalCloseAllDialogs() ; - return ; -} - - -//======================================================================= -// function : GetActiveDialogBox() -// purpose : -//======================================================================= -QDialog* GeometryGUI::GetActiveDialogBox() -{ - return this->myActiveDialogBox ; -} - - -//======================================================================= -// function : SetActiveDialogBox() -// purpose : -//======================================================================= -void GeometryGUI::SetActiveDialogBox(QDialog* aDlg) -{ - this->myActiveDialogBox = (QDialog*)aDlg ; - return ; -} - - -//======================================================================= -// function : GetActiveStudy() -// purpose : -//======================================================================= -QAD_Study* GeometryGUI::GetActiveStudy() -{ - return this->myActiveStudy ; -} - - -//======================================================================= -// function : GetActiveDesktop() -// purpose : -//======================================================================= -QAD_Desktop* GeometryGUI::GetDesktop() -{ - return this->myDesktop ; -} - - -//===================================================================================== -// function : OnSubShapeGetAll() -// purpose : Explode a shape in all sub shapes with a SubShapeType -//===================================================================================== -bool GeometryGUI::OnSubShapeGetAll(const TopoDS_Shape& ShapeTopo, const char* ShapeTopoIOR, const int SubShapeType) -{ - SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument(); - SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR( ShapeTopoIOR ); - if ( theObj->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY")); - return false ; - } - - SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); - SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(myActiveStudy->getActiveStudyFrame()->entry()); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeName_var aName; - SALOMEDS::AttributeIOR_var anIOR; - SALOMEDS::AttributePixMap_var aPixmap; - - /* We create a sub object for each sub shape as attribute of the main object */ - /* Each sub object contains list (length=1) containing its index in the main shape */ - GEOM::GEOM_Shape_var aShape = myComponentGeom->GetIORFromString( ShapeTopoIOR ); - GEOM::GEOM_Gen::ListOfGeomShapes_var listGeomShapes = new GEOM::GEOM_Gen::ListOfGeomShapes; - GEOM::GEOM_Shape_var aResult ; - - try { - listGeomShapes = myComponentGeom->SubShapeAll( aShape, SubShapeType ); - if( listGeomShapes->length() < 1 ) { - myDesktop->putInfo (tr("GEOM_PRP_ABORT")); - return false ; - } - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - - /* open transaction */ - QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy ); - op->start(); - - TopoDS_Shape mainTopo = ShapeReader.GetShape(myComponentGeom, aShape); - TopoDS_Shape mainShape; - bool main = false; - while ( !main ) { - if ( aShape->IsMainShape() ) { - mainShape = ShapeReader.GetShape(myComponentGeom, aShape); - main = true; - } else - aShape = myComponentGeom->GetIORFromString( aShape->MainName() ); - } - - /* Loop on each sub shape created */ - /* int i = 1 ; /* index for the nameType */ - for( int j=0; jlength(); j++) { - - /* Get each sub shape extracted CORBA and OCC */ - aResult = listGeomShapes[j] ; - TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, aResult); - - if ( S.IsNull() ) { - myDesktop->putInfo (tr("GEOM_PRP_ABORT")); - return false; - } - -// NRI : Following lines are commented according to bugID SAL695 (see history) -// BRepCheck_Analyzer anAnalyzer(S); -// if(!anAnalyzer.IsValid()) { -// myDesktop->putInfo (tr("GEOM_PRP_ABORT")); -// MESSAGE("#### An exploded shape number "<< j << " is not valid"); -// op->abort(); -// return false; -// } - - /* Set the nameType of sub shape */ - char* nameG = (char *)malloc(20); - Standard_CString Type; - if ( GetShapeTypeString(S, Type) ) { - aResult->NameType( Type ); - sprintf (nameG, "%s_%d", Type, GetIndex( S, mainShape, SubShapeType ) ); - } - else { - aResult->NameType( tr("GEOM_SHAPE") ); - sprintf (nameG, "%s_%d", tr("GEOM_SHAPE").latin1(), this->myNbGeom++ ); - } - SALOMEDS::SObject_var SO = aStudy->FindObjectIOR( aResult->Name() ); - - bool allreadyexist = false; - - if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) { - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - - Handle(GEOM_AISShape) result = new GEOM_AISShape( S, nameG ); - Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(aResult->Name(), Fatherior, "GEOM"); - - MESSAGE ( "SO->_is_nil() " << SO->_is_nil() ) - - if ( SO->_is_nil() ) { - SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject( theObj ); - anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName"); - aName = SALOMEDS::AttributeName::_narrow(anAttr); - aName->SetValue(nameG); - anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR"); - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - anIOR->SetValue(aResult->Name()); - - anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePixMap"); - aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); - MESSAGE( " Type " << S.ShapeType() ) - if ( S.ShapeType() == TopAbs_COMPOUND ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" ); - } else if ( S.ShapeType() == TopAbs_COMPSOLID ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" ); - } else if ( S.ShapeType() == TopAbs_SOLID ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" ); - } else if ( S.ShapeType() == TopAbs_SHELL ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" ); - } else if ( S.ShapeType() == TopAbs_FACE ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" ); - } else if ( S.ShapeType() == TopAbs_WIRE ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" ); - } else if ( S.ShapeType() == TopAbs_EDGE ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" ); - } else if ( S.ShapeType() == TopAbs_VERTEX ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" ); - } - - MESSAGE ( " aPixmap->GetPixMap " << aPixmap->GetPixMap() ) - - SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF); - aStudyBuilder->Addreference(newObj1, newObj); - IO->setEntry(newObj->GetID()); - - aResult->StudyShapeId( newObj->GetID() ); - } else { - allreadyexist = true; - if ( ! SObjectExist(theObj, aResult->Name()) ) { - SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(theObj); - aStudyBuilder->Addreference(newObj1, SO); - IO->setEntry(SO->GetID()); - aResult->StudyShapeId( SO->GetID() ); - } - } - - result->setIO( IO ); - result->setName( nameG ); - if ( !allreadyexist ) - ic->Display(result); - - } else if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { - VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor(); - - int themode = myRenderInter->GetDisplayMode(); - vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer(); - vtkRenderWindow *renWin = theRenderer->GetRenderWindow(); - - Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(aResult->Name(), Fatherior,"GEOM"); - - if ( SO->_is_nil() ) { - SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject( theObj ); - anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR"); - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - anIOR->SetValue(aResult->Name()); - anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName"); - aName = SALOMEDS::AttributeName::_narrow(anAttr); - aName->SetValue(nameG); - - anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePixMap"); - aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); - if ( S.ShapeType() == TopAbs_COMPOUND ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" ); - } else if ( S.ShapeType() == TopAbs_COMPSOLID ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" ); - } else if ( S.ShapeType() == TopAbs_SOLID ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" ); - } else if ( S.ShapeType() == TopAbs_SHELL ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" ); - } else if ( S.ShapeType() == TopAbs_FACE ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" ); - } else if ( S.ShapeType() == TopAbs_WIRE ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" ); - } else if ( S.ShapeType() == TopAbs_EDGE ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" ); - } else if ( S.ShapeType() == TopAbs_VERTEX ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" ); - } - - SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF); - aStudyBuilder->Addreference(newObj1, newObj); - IO->setEntry(newObj->GetID()); - } else { - allreadyexist = true; - if ( ! SObjectExist(theObj, aResult->Name()) ) { - SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(theObj); - aStudyBuilder->Addreference(newObj1, SO); - IO->setEntry(SO->GetID()); - } - } - - if ( !allreadyexist ) { - vtkActorCollection* theActors = - GEOM_AssemblyBuilder::BuildActors(S,0,themode,Standard_True); - theActors->InitTraversal(); - vtkActor* anActor = (vtkActor*)theActors->GetNextActor(); - while(!(anActor==NULL)) { - GEOM_Actor* GActor = GEOM_Actor::SafeDownCast( anActor ); - GActor->setIO( IO ); - GActor->setName( nameG ); - theRenderer->AddActor(GActor); - renWin->Render(); - anActor = (vtkActor*)theActors->GetNextActor(); - } - } - } - } - - /* commit transaction */ - op->finish(); - - myActiveStudy->updateObjBrowser(); - myDesktop->putInfo (tr("GEOM_PRP_READY")); - return true ; -} - - - -//===================================================================================== -// function : GetIndexSubShapeSelected() -// purpose : Define a ListOfID of sub shapes selected in ShapeTopo with SubShapeType -// : Method used by Dialogs -//===================================================================================== -bool GeometryGUI::GetIndexSubShapeSelected( const TopoDS_Shape& ShapeTopo, - const int SubShapeType, - GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID, - Standard_Integer& aLocalContextId, - bool& myUseLocalContext ) -{ - //* Test the type of viewer */ - if ( this->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) { - return false; - } - - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)this->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - - ic->InitSelected(); - int nbSelected = ic->NbSelected(); - ListOfID.length(nbSelected); - - - //***************** DEFINE INDEX OF EACH SELECTION *********************// - int i = 0 ; - ic->InitSelected(); /* to restart */ - while( ic->MoreSelected() ) { - - /* Find index of sub shape into main shape */ - TopExp_Explorer Exp ( ShapeTopo, TopAbs_ShapeEnum(SubShapeType) ); - int index = 1; - bool found = false ; - while ( Exp.More() ) { - if ( (Exp.Current()).IsSame( ic->SelectedShape()) ) { - found = true ; - break; - } - index++; - Exp.Next(); - } - if( !found ) { - /* Manage local context from DialogBox */ - ic->CloseLocalContext(aLocalContextId) ; - myUseLocalContext = false ; - return false ; - } - ListOfID[i] = index ; - i++; - ic->NextSelected(); - } - //***************** END *********************// - - /* Manage local context from DialogBox */ - ic->CloseLocalContext(aLocalContextId) ; - myUseLocalContext = false ; - - return true ; -} - - -//===================================================================================== -// function : OnSubShapeGetSelected() -// purpose : -//===================================================================================== -bool GeometryGUI::OnSubShapeGetSelected( const TopoDS_Shape& ShapeTopo, - const char* ShapeTopoIOR, - const int SubShapeType, - Standard_Integer& aLocalContextId, - bool& myUseLocalContext ) -{ - //* Test the type of viewer */ - if ( this->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) { - return false; - } - - SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument(); - SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR( ShapeTopoIOR ); - if ( theObj->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY")); - return false ; - } - - - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - - if( myUseLocalContext == false ) { - /* local context is from DialogBox */ - MESSAGE("Error : No local context opened for sub shapes method" << endl ) ; - return false ; - } - - GEOM::GEOM_Shape_var aShape = myComponentGeom->GetIORFromString( ShapeTopoIOR ); - TopoDS_Shape mainTopo = ShapeReader.GetShape(myComponentGeom, aShape); - - TopoDS_Shape mainShape; - bool main = false; - while ( !main ) { - if ( aShape->IsMainShape() ) { - mainShape = ShapeReader.GetShape(myComponentGeom, aShape); - main = true; - } else - aShape = myComponentGeom->GetIORFromString( aShape->MainName() ); - } - - GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID; - ic->InitSelected(); - int nbSelected = ic->NbSelected(); - ListOfID->length(nbSelected); - - TopoDS_Compound compound; - ic->InitSelected(); /* to init again */ - BRep_Builder B; - B.MakeCompound( compound ); - - int i = 0; - /* We create a unique compound containing all the sub shapes selected by user as attribute of the main shape */ - /* the compound is homogenous by selection */ - while(ic->MoreSelected()) { - int index = GetIndex( ic->SelectedShape(), mainShape, SubShapeType ); - ListOfID[i] = index ; - B.Add( compound, ic->SelectedShape() ); - i++; - ic->NextSelected(); - } - - /* Test if user has selected sub shapes */ - if( ListOfID->length() < 1 ) - return false ; - - GEOM::GEOM_Shape_var aResult ; - try { - aResult = myComponentGeom->SubShape( aShape, SubShapeType, ListOfID ); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - - /* local context from DialogBox */ - ic->CloseLocalContext(aLocalContextId) ; - myUseLocalContext = false ; - - char* nameG = (char *)malloc(20); - Standard_CString Type; - - Handle(GEOM_AISShape) result; - Handle(GEOM_InteractiveObject) IO ; - - // if ( ! SObjectExist(theObj, aResult->Name()) ) { - if ( nbSelected == 1 ) { - TopExp_Explorer Exp ( compound, TopAbs_ShapeEnum(SubShapeType) ); - if ( Exp.More() ) { - if ( GetShapeTypeString(Exp.Current(),Type) ) { - aResult->NameType( Type ); - sprintf (nameG, "%s_%d", Type, GetIndex( Exp.Current(), mainTopo, SubShapeType ) ); - } else { - aResult->NameType( tr("GEOM_SHAPE") ); - sprintf (nameG, "%s_%d", tr("GEOM_SHAPE").latin1(), this->myNbGeom++ ); - } - result = new GEOM_AISShape( Exp.Current(), nameG ); - IO = new GEOM_InteractiveObject(aResult->Name(), Fatherior, "GEOM"); - } - } - else { - if ( GetShapeTypeString(compound,Type) ) { - aResult->NameType( Type ); - sprintf (nameG, "%s_%d", Type, this->myNbGeom++ ); - } else { - aResult->NameType( tr("GEOM_SHAPE") ); - sprintf (nameG, "%s_%d", tr("GEOM_SHAPE").latin1(), this->myNbGeom++ ); - } - result = new GEOM_AISShape( compound, nameG ); - IO = new GEOM_InteractiveObject(aResult->Name(), Fatherior, "GEOM"); - } - - SALOMEDS::SObject_var SO = aStudy->FindObjectIOR( aResult->Name() ); - - /* open transaction */ - QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy ); - op->start(); - - SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); - SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(myActiveStudy->getActiveStudyFrame()->entry()); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeName_var aName; - SALOMEDS::AttributeIOR_var anIOR; - SALOMEDS::AttributePixMap_var aPixmap; - - bool allreadyexist = false; - - if ( SO->_is_nil() ) { - SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject( theObj ); - anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR"); - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - anIOR->SetValue(aResult->Name()); - anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName"); - aName = SALOMEDS::AttributeName::_narrow(anAttr); - aName->SetValue(result->getName()); - - anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePixMap"); - aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); - if ( result->Shape().ShapeType() == TopAbs_COMPOUND ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" ); - } else if ( result->Shape().ShapeType() == TopAbs_COMPSOLID ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" ); - } else if ( result->Shape().ShapeType() == TopAbs_SOLID ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" ); - } else if ( result->Shape().ShapeType() == TopAbs_SHELL ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" ); - } else if ( result->Shape().ShapeType() == TopAbs_FACE ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" ); - } else if ( result->Shape().ShapeType() == TopAbs_WIRE ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" ); - } else if ( result->Shape().ShapeType() == TopAbs_EDGE ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" ); - } else if ( result->Shape().ShapeType() == TopAbs_VERTEX ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" ); - } - - SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF); - aStudyBuilder->Addreference(newObj1, newObj); - - IO->setEntry(newObj->GetID()); - aResult->StudyShapeId(newObj->GetID()); - } else { - allreadyexist = true; - if ( ! SObjectExist(theObj, aResult->Name()) ) { - SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(theObj); - aStudyBuilder->Addreference(newObj1, SO); - - IO->setEntry(SO->GetID()); - aResult->StudyShapeId(SO->GetID()); - } - } - - /* commit transaction */ - op->finish(); - - result->setIO( IO ); - result->setName( nameG ); - - if ( !allreadyexist ) - ic->Display(result); - - this->OnDisplayAll(true); - myActiveStudy->updateObjBrowser(); - myDesktop->putInfo (tr("GEOM_PRP_READY")); - - return true ; -} - - -//===================================================================================== -// function : OnSuppressFaces() -// purpose : To suppress faces from a shape -// : The result is one or more shells/faces as main shapes ! -//===================================================================================== -bool GeometryGUI::OnSuppressFaces( const TopoDS_Shape& ShapeTopo, - const char* ShapeTopoIOR, - const Standard_Integer& aLocalContextId, - bool& myUseLocalContext ) -{ - /* Test the type of viewer */ - if ( this->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) { - return false; - } - - SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument(); - SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR( ShapeTopoIOR ); - if ( theObj->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY")); - return false ; - } - - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - - if( myUseLocalContext == false ) { - /* local context is from DialogBox */ - MESSAGE("Error : No local context opened for suppress faces method" << endl ) ; - return false ; - } - - GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID; - ic->InitSelected(); - int nbSelected = ic->NbSelected(); - ListOfID->length(nbSelected); - - /* Create a list of indices of faces to be suppressed */ - int i = 0; - const int SubShapeType = 4 ; /* GEOM::FACE type */ - ic->InitSelected(); /* to repositioning at beginning */ - while( ic->MoreSelected() ) { - int index = GetIndex( ic->SelectedShape(), ShapeTopo, SubShapeType ); - ListOfID[i] = index ; - i++; - ic->NextSelected(); - } - - /* Close local context opened in DialogBox */ - ic->CloseLocalContext(aLocalContextId) ; - myUseLocalContext = false ; - - /* Here is the main shape */ - GEOM::GEOM_Shape_var aShape = myComponentGeom->GetIORFromString( ShapeTopoIOR ); - GEOM::GEOM_Gen::ListOfGeomShapes_var listGeomShapes = new GEOM::GEOM_Gen::ListOfGeomShapes; - - /* Call geom method that return a list of shells/faces as result of suppress */ - try { - listGeomShapes = myComponentGeom->SuppressFaces( aShape, ListOfID ); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - - /* Test list of shells/faces */ - if( listGeomShapes->length() < 1 ) { - return false ; - } - - /* Loop on each object created */ - for( int i=0; ilength(); i++ ) { - - GEOM::GEOM_Shape_var aShellOrFace = listGeomShapes[i] ; - TopoDS_Shape S = ShapeReader.GetShape( this->myComponentGeom, aShellOrFace ); - - if( S.IsNull() ) { - return false ; - } - - char* nameG = (char *)malloc(20); - Standard_CString Type; - if ( GetShapeTypeString(S, Type) ) { - aShellOrFace->NameType( Type ); - sprintf (nameG, "%s_%d", Type, this->myNbGeom++); - } - else { - aShellOrFace->NameType( tr("GEOM_SHAPE") ); - sprintf (nameG, "%s_%d", tr("GEOM_SHAPE").latin1(), this->myNbGeom++ ); - } - - /* Display with name */ - if( !Display( aShellOrFace, nameG) ) { - myDesktop->putInfo(tr("GEOM_PRP_ABORT")); - return false ; - } - } - - myDesktop->putInfo (tr("GEOM_PRP_READY")); - return true ; -} - - -//===================================================================================== -// function : OnSuppressHole() -// purpose : To suppress an hole on a shape 'ShapeTopo'. -// : 'ListOfIdEndFace' may be an empty list. -// : This means that hole do not traverse ShapeTopo. -// : Warning : the hole to be suppressed must be defined by one or two single closed wires ! -//===================================================================================== -bool GeometryGUI::OnSuppressHole( const char* ShapeTopoIOR, - const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfIdFace, - const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfIdWire, - const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfIdEndFace ) -{ - /* Test the type of viewer */ - if ( this->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) { - return false; - } - - try { - GEOM::GEOM_Shape_var aShape = myComponentGeom->GetIORFromString( ShapeTopoIOR ); - GEOM::GEOM_Shape_var aResult = myComponentGeom->SuppressHole( aShape, ListOfIdFace, ListOfIdWire, ListOfIdEndFace ) ; - - TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, aResult); - Standard_CString type; - GetShapeTypeString(S,type); - aResult->NameType( type ); - - if ( Display( aResult, "" ) ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - return true ; -} - - -//===================================================================================== -// function : OnSuppressHolesInFaceOrShell() -// purpose : To suppress one or more holes on a face -// : 'ListOfIdWires' contains indices or wires/holes. -//===================================================================================== -bool GeometryGUI::OnSuppressHolesInFaceOrShell( const char* ShapeTopoIOR, - const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfIdWires ) -{ - /* Test the type of viewer */ - if ( this->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) { - return false; - } - - try { - GEOM::GEOM_Shape_var aShape = myComponentGeom->GetIORFromString( ShapeTopoIOR ); - GEOM::GEOM_Shape_var aResult = myComponentGeom->SuppressHolesInFaceOrShell( aShape, ListOfIdWires ) ; - - TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, aResult); - Standard_CString type; - GetShapeTypeString(S,type); - aResult->NameType( type ); - - if ( Display( aResult, "") ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - return true ; -} - - - -//======================================================================= -// function : activeStudyChanged() -// purpose : static -//======================================================================= -void GeometryGUI::activeStudyChanged( QAD_Desktop* parent ) -{ - MESSAGE ("GeometryGUI::activeStudyChanged init.") - /* Create or retrieve an object GeomGUI */ - GeometryGUI::GetOrCreateGeometryGUI(parent); - if(GeomGUI != 0) { - - if (GeomGUI->myState == CURRENT_SKETCH) { - GeomGUI->mySketcher.Clear(); - GeomGUI->ResetState(); - } - - QMenuBar* Mb = GeomGUI->myDesktop->getMainMenuBar(); - bool ViewOCC = false; - if ( GeomGUI->myDesktop->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) - ViewOCC = true; - - Mb->setItemEnabled( 312, ViewOCC); //Sketch - Mb->setItemEnabled( 309, ViewOCC); //SuppressFace - Mb->setItemEnabled( 314, ViewOCC); //SuppressHole - - Mb->setItemEnabled( 703, ViewOCC);// ShadingColor Settings - Mb->setItemEnabled( 704, ViewOCC);// Isos Settings - - GeomGUI->EraseSimulationShape() ; - GeomGUI->EmitSignalCloseAllDialogs() ; - GeomGUI = 0 ; - } - - // GeomGUI->SetSettings( parent ); - // MESSAGE ("GeometryGUI::activeStudyChanged done.") - return ; -} - - -//======================================================================= -// function : DefineDlgPosition() -// purpose : Define x and y the default position for a dialog box -//======================================================================= -bool GeometryGUI::DefineDlgPosition(QWidget* aDlg, int& x, int& y) -{ - /* Here the position is on the bottom right corner - 10 */ - QAD_Desktop* PP = QAD_Application::getDesktop() ; - x = abs ( PP->x() + PP->size().width() - aDlg->size().width() - 10 ) ; - y = abs ( PP->y() + PP->size().height() - aDlg->size().height() - 10 ) ; - return true ; -} - -//======================================================================= -// function : OnGUIEvent() [static] -// purpose : manage all events on GUI -//======================================================================= -bool GeometryGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent) -{ - /* Create or retrieve an object GeomGUI */ - GeometryGUI::GetOrCreateGeometryGUI(parent); - - SALOMEDS::Study_var aStudy = GeomGUI->myActiveStudy->getStudyDocument(); - SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); - - OCCViewer_Viewer3d* v3d; - Handle(AIS_InteractiveContext) ic; - vtkRenderer* Renderer; - - QMenuBar* Mb = GeomGUI->myDesktop->getMainMenuBar(); - - bool ViewOCC = false; - - if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) { - v3d = ((OCCViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - ic = v3d->getAISContext(); - ViewOCC = true; - Mb->setItemEnabled( 312, ViewOCC);//Sketch - Mb->setItemEnabled( 309, ViewOCC);//SuppressFace - Mb->setItemEnabled( 314, ViewOCC);//SuppressHole - - Mb->setItemEnabled( 703, ViewOCC);// ShadingColor Settings - Mb->setItemEnabled( 704, ViewOCC);// Isos Settings - - } else if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { - Renderer = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer(); - - // OnSuppressFaces, OnSuppressHole, SETTINGS - SHADING COLOR, SETTINGS - ISOS, SETTINGS : STEP VALUE FOR SPIN BOXES, SKETCHER, ISOS - POPUP VIEWER, - Mb->setItemEnabled( 312, ViewOCC);//Sketch - Mb->setItemEnabled( 309, ViewOCC);//SuppressFace - Mb->setItemEnabled( 314, ViewOCC);//SuppressHole - - Mb->setItemEnabled( 703, ViewOCC);// ShadingColor Settings - Mb->setItemEnabled( 704, ViewOCC);// Isos Settings - } else { - return 0; - } - - if (GeomGUI->myState == CURRENT_SKETCH && theCommandID != 10000 && theCommandID != 10001 && theCommandID != 10002 && theCommandID != 10003 && theCommandID != 10004 && theCommandID != 10006 && theCommandID != 10007 && theCommandID != 10008 && theCommandID != 10010 && theCommandID != 10011 && theCommandID != 10012 && theCommandID != 10013 && theCommandID != 10014 && theCommandID != 3133 && theCommandID != 3134) - return false; - - switch (theCommandID) - { - case 31: // COPY - GeomGUI->OnEditCopy(); - break; - - case 33: // DELETE - GeomGUI->OnEditDelete(); - break; - - case 111: - { - GeomGUI->SetState(111); - GeomGUI->Import(); - GeomGUI->ResetState(); - break; - } - case 112: - { - GeomGUI->SetState(112); - GeomGUI->Import(); - GeomGUI->ResetState(); - break; - } - case 113: // IMPORT STEP - { - GeomGUI->SetState(113); - GeomGUI->Import(); - GeomGUI->ResetState(); - break; - } - - case 121: // EXPORT BREP - { - GeomGUI->SetState(121); - GeomGUI->Export(); - GeomGUI->ResetState(); - break; - } - - case 122: // EXPORT IGES - { - GeomGUI->SetState(122); - GeomGUI->Export(); - GeomGUI->ResetState(); - break; - } - - case 123: // EXPORT STEP - { - GeomGUI->SetState(123); - GeomGUI->Export(); - GeomGUI->ResetState(); - break; - } - - case 303: // EXPLODE : use ic - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_SubShapeDlg *aDlg = new GeometryGUI_SubShapeDlg( parent, "", Sel, ic ) ; - break ; - } - - case 304: // GEOM::EDGE - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_EdgeDlg *aDlg = new GeometryGUI_EdgeDlg( parent, "", Sel ) ; - break ; - } - - case 305: // GEOM::WIRE - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_WireDlg *aDlg = new GeometryGUI_WireDlg( parent, "", Sel ) ; - break ; - } - - case 306: // GEOM::FACE - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_FaceDlg *aDlg = new GeometryGUI_FaceDlg ( parent, "", Sel ) ; - break ; - } - - case 308: // GEOM::COMPOUND - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_CompoundDlg *aDlg = new GeometryGUI_CompoundDlg ( parent, "", Sel ) ; - break ; - } - - case 309: // SUPPRESS FACES : use ic - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_SuppressFacesDlg *aDlg = new GeometryGUI_SuppressFacesDlg( parent, "", Sel, ic ) ; - break ; - } - - case 314: // SUPPRESS HOLES : use ic - { - if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_SuppressHoleDlg *aDlg = new GeometryGUI_SuppressHoleDlg( parent, "", Sel, ic ) ; - } - else { - GeomGUI->myDesktop->putInfo( tr("GEOM_PRP_NOT_FOR_VTK_VIEWER") ) ; - } - break ; - } - case 501: // SEWING - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_SewingDlg *aDlg = new GeometryGUI_SewingDlg ( parent, "", Sel ) ; - break ; - } - - case 502: // ORIENTATION - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_OrientationDlg *aDlg = new GeometryGUI_OrientationDlg( parent, "", Sel ) ; - break ; - } - - case 601: // PROPERTIES (Length, surface, volume) - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_PropertiesDlg *aDlg = new GeometryGUI_PropertiesDlg( parent, "", Sel ) ; - break ; - } - - case 604: // CDG : Center of mass - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_CenterMassDlg *aDlg = new GeometryGUI_CenterMassDlg ( parent, "", Sel ) ; - break ; - } - - case 605: // INERTIA - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_InertiaDlg *aDlg = new GeometryGUI_InertiaDlg( parent, "", Sel ) ; - break ; - } - - case 607: // MAXTOLERANCE - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_MaxToleranceDlg *aDlg = new GeometryGUI_MaxToleranceDlg( parent, "", Sel ) ; - break ; - } - - case 608: // WHATIS - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_WhatisDlg *aDlg = new GeometryGUI_WhatisDlg( parent, "", Sel ) ; - break ; - } - - case 609: // CHECKSHAPE - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_CheckShape *aDlg = new GeometryGUI_CheckShape( parent, "", Sel ) ; - break ; - } - - case 701: // SETTINGS - COPY - { - QMenuData* pp; - QMenuItem* item = parent->menuBar()->findItem(701,&pp); - bool check = !pp->isItemChecked(701); - pp->setItemChecked(701,check); - Settings_Copy = check; - QAD_CONFIG->addSetting( "Geometry:SettingsCopy", Settings_Copy ); - break; - } - - case 702: // SETTINGS - ADD IN STUDY - { - QMenuData* pp; - QMenuItem* item = parent->menuBar()->findItem(702,&pp); - bool check = !pp->isItemChecked(702); - pp->setItemChecked(702,check); - Settings_AddInStudy = check; - - QAD_CONFIG->addSetting( "Geometry:SettingsAddInStudy", Settings_AddInStudy ); - break; - } - - case 703: // SETTINGS - SHADING COLOR - { - if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) - break; - - QString SCr = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorRed"); - QString SCg = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorGreen"); - QString SCb = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorBlue"); - QColor color; - if( !SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty() ) { - color = QColor (SCr.toInt(), - SCg.toInt(), - SCb.toInt()); - } else { - Quantity_Color Default = Quantity_Color(); - color = QColor ( (int)Default.Red() * 255.0, - (int)Default.Green()* 255.0, - (int)Default.Blue() * 255.0 ); - } - - QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() ); - if ( c.isValid() ) { - GeomGUI->myShadingColor = Quantity_Color(c.red() / 255.0, - c.green()/ 255.0, - c.blue() / 255.0, - Quantity_TOC_RGB); - - AIS_ListOfInteractive List; - ic->DisplayedObjects(List); - AIS_ListOfInteractive List1; - ic->ObjectsInCollector(List1); - List.Append(List1); - - AIS_ListIteratorOfListOfInteractive ite(List); - while (ite.More()) { - if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) { - Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value()); - aSh->SetShadingColor( GeomGUI->myShadingColor ); - ic->Redisplay( aSh, Standard_True, Standard_True); - } - ite.Next(); - } - - ic->UpdateCurrentViewer(); - - QAD_CONFIG->addSetting("Geometry:SettingsShadingColorRed", c.red() ); - QAD_CONFIG->addSetting("Geometry:SettingsShadingColorGreen", c.green() ); - QAD_CONFIG->addSetting("Geometry:SettingsShadingColorBlue", c.blue() ); - } - break; - } - - - case 704: // SETTINGS - ISOS - { - if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) - break; - - QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU"); - QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV"); - if ( !IsoU.isEmpty() ) - ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt()); - else - IsoU = "1"; - if ( !IsoV.isEmpty() ) - ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt()); - else - IsoV = "1"; - - GeometryGUI_NbIsosDlg * NbIsosDlg = new GeometryGUI_NbIsosDlg( QAD_Application::getDesktop(), - tr("GEOM_MEN_ISOS"), TRUE ); - int UIso = IsoU.toInt(); - int VIso = IsoV.toInt(); - - NbIsosDlg->SpinBoxU->setValue(UIso) ; - NbIsosDlg->SpinBoxV->setValue(VIso) ; - - if ( NbIsosDlg->exec() ) { - UIso = NbIsosDlg->SpinBoxU->text().toInt() ; - VIso = NbIsosDlg->SpinBoxV->text().toInt() ; - - ic->DefaultDrawer()->UIsoAspect()->SetNumber(UIso); - ic->DefaultDrawer()->VIsoAspect()->SetNumber(VIso); - QAD_CONFIG->addSetting( "Geometry:SettingsIsoU", NbIsosDlg->SpinBoxU->text() ); /* text format */ - QAD_CONFIG->addSetting( "Geometry:SettingsIsoV", NbIsosDlg->SpinBoxV->text() ); /* text format */ - } - - AIS_ListOfInteractive List; - ic->DisplayedObjects(List); - AIS_ListOfInteractive List1; - ic->ObjectsInCollector(List1); - List.Append(List1); - - AIS_ListIteratorOfListOfInteractive ite(List); - ic->InitCurrent(); - if ( ic-> NbCurrents() ) - while (ite.More()) { - if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) { - - Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value()); - Handle (AIS_Drawer) CurDrawer; - CurDrawer = ic->Current()->Attributes(); - CurDrawer->UIsoAspect()->SetNumber( UIso ); - CurDrawer->VIsoAspect()->SetNumber( VIso ); - ic->SetLocalAttributes(aSh, CurDrawer); - ic->Redisplay(aSh); - } - ite.Next(); - } - ic->UpdateCurrentViewer(); - break; - } - - case 705: // SETTINGS : STEP VALUE FOR SPIN BOXES - { - //NRI if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) - //NRI break; - - QString step = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" ); - if( step.isEmpty() ) - step = "100.0" ; - - Standard_Boolean res = false ; - double dd = Parameter( res, QString("%1").arg(step), tr("GEOM_MEN_STEP_LABEL"), tr("GEOM_STEP_TITLE"), 0.001, 10000.0, 3 ) ; - if( res ) { - QAD_CONFIG->addSetting( "Geometry:SettingsGeomStep", QString("%1").arg(dd) ) ; - - /* Emit signal to GeometryGUI_SpinBoxes */ - GeomGUI->SignalDefaultStepValueChanged( dd ) ; - } - else - parent->putInfo(tr("GEOM_PRP_ABORT")); - - break ; - } - - case 801: // ADD IN STUDY - POPUP VIEWER - { - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - const SALOME_ListIO& ListSelected = Sel->StoredIObjects(); - SALOME_ListIteratorOfListIO It( ListSelected ); - for ( ; It.More(); It.Next() ) { - Handle(SALOME_InteractiveObject) IObject = It.Value(); - GeomGUI->AddInStudy(true, IObject); - } - /* Is set on the dialog box */ - QApplication::restoreOverrideCursor(); - break; - } - - case 901: // RENAME - { - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() ); - for ( ; It.More(); It.Next() ) { - Handle(SALOME_InteractiveObject) IObject = It.Value(); - - SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() ); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeName_var aName; - if ( !obj->_is_nil() ) { - if (obj->FindAttribute(anAttr, "AttributeName")) { - aName = SALOMEDS::AttributeName::_narrow(anAttr); - - QString nm = QString( aName->Value() ); - nm = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), nm ); - if ( !nm.isEmpty() ) { - QApplication::setOverrideCursor( Qt::waitCursor ); - GeomGUI->myActiveStudy->renameIObject( IObject, nm ); - QApplication::restoreOverrideCursor(); - } - } - } - } - break; - } - - case 903: // DISPLAY OBJECT BROWSER - { - if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { - // VTK - QApplication::setOverrideCursor( Qt::waitCursor ); - - SALOMEDS::SObject_var fatherSF = - aStudy->FindObjectID(GeomGUI->myActiveStudy->getActiveStudyFrame()->entry()); - - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() ); - - for(;It.More();It.Next()) { - Handle(SALOME_InteractiveObject) IObject = It.Value(); - SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() ); - - VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor(); - - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeName_var aName; - SALOMEDS::AttributeIOR_var anIOR; - - if(myRenderInter->isInViewer(IObject)) { - myRenderInter->Display(IObject); - } - else { - // Create new actor - if ( !obj->_is_nil() ) { - if ( obj->FindAttribute(anAttr, "AttributeIOR")) { - // this SObject may be GEOM module root SObject - SALOMEDS::ChildIterator_var anIter = GeomGUI->myActiveStudy->getStudyDocument()->NewChildIterator(obj); - bool useSubItems = false; - while (anIter->More() && !useSubItems) { - SALOMEDS::SObject_var subobj = anIter->Value(); - SALOMEDS::GenericAttribute_var aTmpAttr; - if (subobj->FindAttribute(aTmpAttr, "AttributeIOR")) { - anAttr = aTmpAttr; - obj = subobj; - useSubItems = true; - } else anIter->Next(); - } - - while(useSubItems?anIter->More():!anAttr->_is_nil()) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - GEOM::GEOM_Shape_var aShape = GeomGUI->myComponentGeom->GetIORFromString(anIOR->Value()); - TopoDS_Shape Shape = ShapeReader.GetShape(GeomGUI->myComponentGeom,aShape); - - if (obj->FindAttribute(anAttr, "AttributeName")) { - aName = SALOMEDS::AttributeName::_narrow(anAttr); - - vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer(); - vtkActorCollection* theAllActors = theRenderer->GetActors(); - theAllActors->InitTraversal(); - vtkActor* actor = (vtkActor*)theAllActors->GetNextActor(); - Handle(SALOME_InteractiveObject) anIObj; - // don't create new study object if it already exists - bool isDisplayed = false; - while(!(actor==NULL)) { - SALOME_Actor* Gactor = SALOME_Actor::SafeDownCast(actor); - if (Gactor!=NULL) { - if (Gactor->hasIO()) { - if (strcmp(Gactor->getIO()->getEntry(),obj->GetID())==0) { - isDisplayed = true; - anIObj = Gactor->getIO(); - if (!anIObj.IsNull()) myRenderInter->Display(anIObj); - } - } - } - actor=(vtkActor*)(theAllActors->GetNextActor()); - } - if (!isDisplayed) { - // open transaction - QAD_Operation* op = new SALOMEGUI_ImportOperation( GeomGUI->myActiveStudy ); - op->start(); - - SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF); - aStudyBuilder->Addreference(newObj1, obj); - // commit transaction - op->finish(); - - vtkRenderWindow *renWin = theRenderer->GetRenderWindow(); - int themode = myRenderInter->GetDisplayMode(); - - vtkActorCollection* theActors = - GEOM_AssemblyBuilder::BuildActors(Shape,0,themode,Standard_True); - theActors->InitTraversal(); - vtkActor* anActor = (vtkActor*)theActors->GetNextActor(); - while(!(anActor==NULL)) { - GEOM_Actor* GActor = GEOM_Actor::SafeDownCast( anActor ); - Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(), Fatherior,"GEOM"); - IO->setEntry(obj->GetID()); - GActor->setIO( IO ); - GActor->setName( IObject->getName() ); - - theRenderer->AddActor(GActor); - renWin->Render(); - anActor = (vtkActor*)theActors->GetNextActor(); - } - } - } - // next item iteration - if (useSubItems) { - anIter->Next(); - anAttr = SALOMEDS::GenericAttribute::_nil(); - while (anIter->More() && anAttr->_is_nil()) { - SALOMEDS::SObject_var subobject = anIter->Value(); - SALOMEDS::GenericAttribute_var aTmpAttribute; - if (subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) { - anAttr = aTmpAttribute; - obj = subobject; - } else anIter->Next(); - } - } else anAttr = SALOMEDS::GenericAttribute::_nil(); - } - } - } - } - } - GeomGUI->myActiveStudy->updateObjBrowser( true ); - QApplication::restoreOverrideCursor(); - - } else if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) { - QApplication::setOverrideCursor( Qt::waitCursor ); - - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() ); - for(;It.More();It.Next()) { - Handle(SALOME_InteractiveObject) IObject = It.Value(); - - SALOMEDS::SObject_var fatherSF = - aStudy->FindObjectID( GeomGUI->myActiveStudy->getActiveStudyFrame()->entry()); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeName_var aName; - SALOMEDS::AttributeIOR_var anIOR; - - if ( v3d->isInViewer( IObject, true ) ) { - Standard_Boolean found; - Handle(GEOM_AISShape) aSh = GeomGUI->ConvertIOinGEOMAISShape( IObject, found, true ); - if ( found ) { - ic->Display(aSh); - ic->AddOrRemoveCurrentObject(aSh, true); - } - - } else { - SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() ); - if ( !obj->_is_nil() ) { - if ( obj->FindAttribute(anAttr, "AttributeIOR")) { - // this SObject may be GEOM module root SObject - SALOMEDS::ChildIterator_var anIter = GeomGUI->myActiveStudy->getStudyDocument()->NewChildIterator(obj); - bool useSubItems = false; - while (anIter->More() && !useSubItems) { - SALOMEDS::SObject_var subobj = anIter->Value(); - SALOMEDS::GenericAttribute_var aTmpAttr; - if (subobj->FindAttribute(aTmpAttr, "AttributeIOR")) { - anAttr = aTmpAttr; - obj = subobj; - useSubItems = true; - } else anIter->Next(); - } - while(useSubItems?anIter->More():!anAttr->_is_nil()) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - GEOM::GEOM_Shape_var aShape = GeomGUI->myComponentGeom->GetIORFromString(anIOR->Value()); - TopoDS_Shape Shape = ShapeReader.GetShape(GeomGUI->myComponentGeom,aShape); - if (obj->FindAttribute(anAttr, "AttributeName")) { - aName = SALOMEDS::AttributeName::_narrow(anAttr); - // searchin for already displayed objects with the same shape - AIS_ListOfInteractive aDisplayed; - ic->DisplayedObjects(aDisplayed); - AIS_ListIteratorOfListOfInteractive anIObjects(aDisplayed); - Handle(AIS_Shape) anAISShape; - for(;anIObjects.More();anIObjects.Next()) { - anAISShape = Handle(AIS_Shape)::DownCast(anIObjects.Value()); - if (!anAISShape.IsNull()) { - if (anAISShape->Shape().IsSame(Shape)) break; - anAISShape.Nullify(); - } - } - if (!anAISShape.IsNull()) { - if (!ic->IsDisplayed(anAISShape)) ic->Display(anAISShape); - } else { - if (!useSubItems) { - // open transaction - QAD_Operation* op = new SALOMEGUI_ImportOperation( GeomGUI->myActiveStudy ); - op->start(); - - SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF); - aStudyBuilder->Addreference(newObj1, obj); - // commit transaction - op->finish(); - } - - Handle(GEOM_AISShape) aSh = new GEOM_AISShape(Shape, aName->Value()); - aSh->SetShadingColor( GeomGUI->myShadingColor ); - Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(), - Fatherior, - "GEOM"); - IO->setEntry(obj->GetID()); - aSh->setIO( IO ); - aSh->setName( aName->Value() ); - ic->Display (aSh); - if (!useSubItems) ic->AddOrRemoveCurrentObject(aSh, true); - } - } - // next item iteration - if (useSubItems) { - anIter->Next(); - anAttr=SALOMEDS::GenericAttribute::_nil(); - while (anIter->More() && anAttr->_is_nil()) { - SALOMEDS::SObject_var subobject = anIter->Value(); - SALOMEDS::GenericAttribute_var aTmpAttribute; - if (subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) { - anAttr = aTmpAttribute; - obj = subobject; - } else anIter->Next(); - } - } else anAttr = SALOMEDS::GenericAttribute::_nil(); - } - } - } - } - } - GeomGUI->myActiveStudy->updateObjBrowser( true ); - QApplication::restoreOverrideCursor(); - } - break; - } - - case 3011: // POINT - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_PointDlg *aDlg = new GeometryGUI_PointDlg( parent, "", Sel, ic ) ; - break; - } - - case 3012: // LINE - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_LineDlg *aDlg = new GeometryGUI_LineDlg( parent, "", Sel ) ; - break ; - } - - case 3013: // CIRCLE - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_CircleDlg *aDlg = new GeometryGUI_CircleDlg( parent, "", Sel ) ; - break ; - } - - case 3015: // ARC - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_ArcDlg *aDlg = new GeometryGUI_ArcDlg( parent, "", Sel ) ; - break ; - } - - case 3016: // VECTOR - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_VectorDlg *aDlg = new GeometryGUI_VectorDlg( parent, "", Sel ) ; - break; - } - - case 3017: // PLANE - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_PlaneDlg *aDlg = new GeometryGUI_PlaneDlg( parent, "", Sel ) ; - break; - } - - case 3018: // WORKING PLANE - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_WorkingPlaneDlg *aDlg = new GeometryGUI_WorkingPlaneDlg( parent, "", Sel ) ; - break; - } - - case 312: // SKETCHER - { - if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC) - break; - - GeomGUI->EmitSignalDeactivateDialog() ; - - ((OCCViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->onViewTop(); // DCQ : 28/02/2002 - - GeomGUI->mySketcher = Sketch( v3d->getViewer3d() ); - GeomGUI->SetState(CURRENT_SKETCH); - - QMenuBar* Mb = GeomGUI->myDesktop->getMainMenuBar(); - QMenuData* pp; - - QMenuItem* item = Mb->findItem(10010,&pp); - GeomGUI->mySketcher.SetParameterVisibility(LENGTH_PARAMETER,pp->isItemChecked(10010)); - item = Mb->findItem(10011,&pp); - GeomGUI->mySketcher.SetParameterVisibility(ANGLE_PARAMETER,pp->isItemChecked(10011)); - item = Mb->findItem(10012,&pp); - GeomGUI->mySketcher.SetParameterVisibility(RADIUS_PARAMETER,pp->isItemChecked(10012)); - item = Mb->findItem(10013,&pp); - GeomGUI->mySketcher.SetParameterVisibility(XVALUE_PARAMETER,pp->isItemChecked(10013)); - item = Mb->findItem(10014,&pp); - GeomGUI->mySketcher.SetParameterVisibility(YVALUE_PARAMETER,pp->isItemChecked(10014)); - - GeomGUI->mySketcher.SetTransitionStatus(NOCONSTRAINT); - item = Mb->findItem(3133,&pp); - pp->setItemChecked(3133,false); - item = Mb->findItem(3134,&pp); - pp->setItemChecked(3134,false); - break; - } - - case 3021: // BOX - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_BoxDlg *aDlg = new GeometryGUI_BoxDlg( parent, "", Sel ) ; - break; - } - - case 3022: // CYLINDER - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_CylinderDlg *aDlg = new GeometryGUI_CylinderDlg( parent, "", Sel ) ; - break; - } - - case 3023: // SPHERE - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_SphereDlg *aDlg = new GeometryGUI_SphereDlg( parent, "", Sel ) ; - break; - } - - case 3024: // TORUS - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_TorusDlg *aDlg = new GeometryGUI_TorusDlg( parent, "", Sel ) ; - break; - } - - case 3025: // CONE - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_ConeDlg *aDlg = new GeometryGUI_ConeDlg( parent, "", Sel ) ; - break; - } - - case 3131: - { - break; - } - - case 3133: // sketcher - { - QMenuBar* Mb = GeomGUI->myDesktop->getMainMenuBar(); - QMenuData* pp; - QMenuItem* item = Mb->findItem(3133,&pp); - pp->setItemChecked(3133,!pp->isItemChecked(3133)); - if (pp->isItemChecked(3133) == true) - GeomGUI->mySketcher.SetTransitionStatus(TANGENT); - else - GeomGUI->mySketcher.SetTransitionStatus(NOCONSTRAINT); - - pp->setItemChecked(3134,false); - break; - } - - case 3134: // sketcher - { - QMenuBar* Mb = GeomGUI->myDesktop->getMainMenuBar(); - QMenuData* pp; - QMenuItem* item = Mb->findItem(3134,&pp); - pp->setItemChecked(3134,!pp->isItemChecked(3134)); - if (pp->isItemChecked(3134) == true) - GeomGUI->mySketcher.SetTransitionStatus(PERPENDICULAR); - else - GeomGUI->mySketcher.SetTransitionStatus(NOCONSTRAINT); - - pp->setItemChecked(3133,false); - break; - } - - case 4011: // FUSE - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_FuseDlg *aDlg = new GeometryGUI_FuseDlg( parent, "", Sel ) ; - break; - } - - case 4012: // COMMON - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_CommonDlg *aDlg = new GeometryGUI_CommonDlg( parent, "", Sel ) ; - break; - } - - case 4013: // CUT - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_CutDlg *aDlg = new GeometryGUI_CutDlg( parent, "", Sel ) ; - break; - } - - case 4014: // SECTION - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_SectionDlg *aDlg = new GeometryGUI_SectionDlg( parent, "", Sel ) ; - break; - } - - case 4021: // TRANSLATION - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_TranslationDlg *aDlg = new GeometryGUI_TranslationDlg( parent, "", Sel ) ; - break; - } - - case 4022: // ROTATION - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_RotationDlg *aDlg = new GeometryGUI_RotationDlg( parent, "", Sel ) ; - break; - } - - case 4030: // MULTI TRANSLATION - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_MultiTranslationDlg *aDlg = new GeometryGUI_MultiTranslationDlg( parent, "", Sel ) ; - break; - } - - case 4040: // MULTI ROTATION - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_MultiRotationDlg *aDlg = new GeometryGUI_MultiRotationDlg( parent, "", Sel ) ; - break; - } - - case 4023: // MIRROR - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_MirrorDlg *aDlg = new GeometryGUI_MirrorDlg( parent, "", Sel ) ; - break; - } - - case 4024: // SCALE - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_ScaleDlg *aDlg = new GeometryGUI_ScaleDlg( parent, "", Sel ) ; - break; - } - - case 4025: // PARTITION - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_PartitionDlg *aDlg = new GeometryGUI_PartitionDlg( parent, "", Sel ) ; - break; - } - - case 4026: // ARCHIMEDE - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_ArchimedeDlg *aDlg = new GeometryGUI_ArchimedeDlg( parent, "", Sel ) ; - break; - } - - case 4027: // FILLET - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_FilletDlg *aDlg = new GeometryGUI_FilletDlg( parent, "", Sel, ic ) ; - break; - } - - case 4028: // CHAMFER - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_ChamferDlg *aDlg = new GeometryGUI_ChamferDlg( parent, "", Sel, ic ) ; - break; - } - - case 4031: // PRISM - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_PrismDlg *aDlg = new GeometryGUI_PrismDlg( parent, "", Sel ) ; - break; - } - - case 4032: // REVOL - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_RevolDlg *aDlg = new GeometryGUI_RevolDlg( parent, "", Sel ) ; - break; - } - - case 4033: // FILLING - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_FillingDlg *aDlg = new GeometryGUI_FillingDlg( parent, "", Sel ) ; - break; - } - - case 4034: // PIPE - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_PipeDlg *aDlg = new GeometryGUI_PipeDlg(parent, "", Sel ) ; - break; - } - - case 5001: // CHECK GEOMETRY - { - QAD_PyEditor* PyEditor = GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getPyEditor(); - PyEditor->setText("from GEOM_usinggeom import *\n"); - PyEditor->setText(">>> "); - PyEditor->handleReturn(); - break; - } - - case 6021: // SHADING - WIREFRAME - { - if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { - VTKViewer_RenderWindowInteractor* myRenderInter= - ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor(); - - QApplication::setOverrideCursor(waitCursor); - - int themode = myRenderInter->GetDisplayMode(); - if( themode==0 ) { - myRenderInter->SetDisplayMode(1); - GeomGUI->GetDesktop()->menuBar()->changeItem(6021, tr("GEOM_MEN_WIREFRAME") ); - } else { - myRenderInter->SetDisplayMode(0); - GeomGUI->GetDesktop()->menuBar()->changeItem(6021, tr("GEOM_MEN_SHADING") ); - } - - QApplication::restoreOverrideCursor(); - - } else if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC) { - AIS_DisplayMode mode = ( AIS_DisplayMode )ic->DisplayMode(); - QApplication::setOverrideCursor( Qt::waitCursor ); - AIS_DisplayMode newmode = (mode == AIS_WireFrame ? AIS_Shaded : AIS_WireFrame); - - AIS_ListOfInteractive List; - ic->DisplayedObjects(List); - AIS_ListOfInteractive List1; - ic->ObjectsInCollector(List1); - List.Append(List1); - - AIS_ListIteratorOfListOfInteractive ite(List); - while (ite.More()) { - if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) { - Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value()); - ic->SetDisplayMode(aSh,Standard_Integer(newmode),true); - } - ite.Next(); - } - - ic->SetDisplayMode( newmode, Standard_False); - if ( newmode == 1 ) - GeomGUI->GetDesktop()->menuBar()->changeItem(6021, tr("GEOM_MEN_WIREFRAME") ); - else - GeomGUI->GetDesktop()->menuBar()->changeItem(6021, tr("GEOM_MEN_SHADING") ); - - QApplication::restoreOverrideCursor(); - } - break; - } - - case 6022: // DISPLAY ALL - { - if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) - //VTK - ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor()->DisplayAll(); - else if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) - GeomGUI->OnDisplayAll(); - break; - } - - case 6023: // DISPLAY ONLY - case 8023: // DISPLAY ONLY - POPUP VIEWER - { - if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { - // VTK - GeomGUI->OnVTKDisplayOnly(); - } - else if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC) - GeomGUI->OnDisplayOnly(); - break; - } - - case 6024: // ERASE ALL - { - if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { - //VTK - ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor()->EraseAll(); - } - else if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC) { - ic->EraseAll(Standard_True, Standard_False); - ic->Display(v3d->getTrihedron()); - } - - //NRI SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() ); - //NRI Sel->ClearInteractiveObjects(); - break; - } - - case 6025 : // ERASE ONLY - case 8022 : // ERASE - POPUP VIEWER - { - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { - // VTK - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() ); - Handle(SALOME_InteractiveObject) anIObject; - for(;It.More();It.Next()) { - anIObject = It.Value(); - VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor(); - - if(myRenderInter->isInViewer(anIObject)) { - myRenderInter->Erase(anIObject); - } else { - SALOMEDS::SObject_var obj = aStudy->FindObjectID( anIObject->getEntry() ); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeIOR_var anIOR; - if ( !obj->_is_nil() ) { - if ( obj->FindAttribute(anAttr, "AttributeIOR")) { - // this SObject may be GEOM module root SObject - SALOMEDS::ChildIterator_var anIter = GeomGUI->myActiveStudy->getStudyDocument()->NewChildIterator(obj); - bool useSubItems = false; - while (anIter->More() && !useSubItems) { - SALOMEDS::SObject_var subobj = anIter->Value(); - SALOMEDS::GenericAttribute_var aTmpAttr; - if (subobj->FindAttribute(aTmpAttr, "AttributeIOR")) { - anAttr = aTmpAttr; - obj = subobj; - useSubItems = true; - } else anIter->Next(); - } - - while(useSubItems?anIter->More():!anAttr->_is_nil()) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - GEOM::GEOM_Shape_var aShape = GeomGUI->myComponentGeom->GetIORFromString(anIOR->Value()); - TopoDS_Shape Shape = ShapeReader.GetShape(GeomGUI->myComponentGeom,aShape); - if (obj->FindAttribute(anAttr, "AttributeName")) { - // searchin for already displayed objects with the same shape - vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer(); - vtkActorCollection* theAllActors = theRenderer->GetActors(); - theAllActors->InitTraversal(); - vtkActor* actor = (vtkActor*)theAllActors->GetNextActor(); - Handle(SALOME_InteractiveObject) anIObj; - // don't create new study object if it already exists - bool isDisplayed = false; - while(!(actor==NULL)) { - SALOME_Actor* Gactor = SALOME_Actor::SafeDownCast(actor); - if (Gactor!=NULL) { - if (Gactor->hasIO()) { - if (strcmp(Gactor->getIO()->getEntry(),obj->GetID())==0) { - isDisplayed = true; - anIObj = Gactor->getIO(); - if (!anIObj.IsNull()) myRenderInter->Erase(anIObj); - } - } - } - actor=(vtkActor*)(theAllActors->GetNextActor()); - } - } - if (useSubItems) { - anIter->Next(); - anAttr=SALOMEDS::GenericAttribute::_nil(); - while (anIter->More() && anAttr->_is_nil()) { - SALOMEDS::SObject_var subobject = anIter->Value(); - SALOMEDS::GenericAttribute_var aTmpAttribute; - if (subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) { - anAttr = aTmpAttribute; - obj = subobject; - } else anIter->Next(); - } - } else anAttr = SALOMEDS::GenericAttribute::_nil(); - } - } - } - } - } -// SALOME_ListIteratorOfListIO It(Sel->StoredIObjects()); -// for(;It.More();It.Next()) { -// Handle(SALOME_InteractiveObject) IOS = It.Value(); - // GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getVTKView()->getRWInteractor()->Erase(IOS);; - } - else if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC) { - // OCC - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() ); - Handle(SALOME_InteractiveObject) anIObject; - for(;It.More();It.Next()) { - anIObject = It.Value(); - if ( v3d->isInViewer( anIObject, true ) ) { - Standard_Boolean found; - Handle(GEOM_AISShape) aSh = GeomGUI->ConvertIOinGEOMAISShape( anIObject, found, true ); - if ( found ) { - ic->Erase(aSh); - ic->AddOrRemoveCurrentObject(aSh, true); - } - } else { - SALOMEDS::SObject_var obj = aStudy->FindObjectID( anIObject->getEntry() ); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeIOR_var anIOR; - if ( !obj->_is_nil() ) { - if ( obj->FindAttribute(anAttr, "AttributeIOR")) { - // this SObject may be GEOM module root SObject - SALOMEDS::ChildIterator_var anIter = GeomGUI->myActiveStudy->getStudyDocument()->NewChildIterator(obj); - bool useSubItems = false; - while (anIter->More() && !useSubItems) { - SALOMEDS::SObject_var subobj = anIter->Value(); - SALOMEDS::GenericAttribute_var aTmpAttr; - if (subobj->FindAttribute(aTmpAttr, "AttributeIOR")) { - anAttr = aTmpAttr; - obj = subobj; - useSubItems = true; - } else anIter->Next(); - } - - while(useSubItems?anIter->More():!anAttr->_is_nil()) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - GEOM::GEOM_Shape_var aShape = GeomGUI->myComponentGeom->GetIORFromString(anIOR->Value()); - TopoDS_Shape Shape = ShapeReader.GetShape(GeomGUI->myComponentGeom,aShape); - if (obj->FindAttribute(anAttr, "AttributeName")) { - // searchin for already displayed objects with the same shape - AIS_ListOfInteractive aDisplayed; - ic->DisplayedObjects(aDisplayed); - AIS_ListIteratorOfListOfInteractive anIObjects(aDisplayed); - Handle(AIS_Shape) anAISShape; - for(;anIObjects.More();anIObjects.Next()) { - anAISShape = Handle(AIS_Shape)::DownCast(anIObjects.Value()); - if (!anAISShape.IsNull()) { - if (anAISShape->Shape().IsSame(Shape)) break; - anAISShape.Nullify(); - } - } - if (!anAISShape.IsNull()) { - if (ic->IsDisplayed(anAISShape)) ic->Erase(anAISShape); - } - } - if (useSubItems) { - anIter->Next(); - anAttr=SALOMEDS::GenericAttribute::_nil(); - while (anIter->More() && anAttr->_is_nil()) { - SALOMEDS::SObject_var subobject = anIter->Value(); - SALOMEDS::GenericAttribute_var aTmpAttribute; - if (subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) { - anAttr = aTmpAttribute; - obj = subobject; - } else anIter->Next(); - } - } else anAttr = SALOMEDS::GenericAttribute::_nil(); - } - } - } - } - } - } - Sel->ClearIObjects(); - break; - } - - - case 6060: // BOUNDING BOX - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_BndBoxDlg *aDlg = new GeometryGUI_BndBoxDlg(parent, "", Sel ) ; - break ; - } - - case 6061: // MIN DISTANCE - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_DistanceDlg *aDlg = new GeometryGUI_DistanceDlg(parent, "", Sel ) ; - break ; - } - - case 8021: // WIREFRAME-SHADING - { - if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { - // VTK - VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor(); - - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - SALOME_ListIteratorOfListIO It(Sel->StoredIObjects()); - - QApplication::setOverrideCursor( Qt::waitCursor ); - for(;It.More();It.Next()) { - Handle(SALOME_InteractiveObject) IOS = It.Value(); - myRenderInter->SwitchRepresentation(IOS, false); - } - myRenderInter->Render(); - QApplication::restoreOverrideCursor(); - } - else if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) { - QApplication::setOverrideCursor( Qt::waitCursor ); - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() ); - for(;It.More();It.Next()) { - Handle(SALOME_InteractiveObject) IObject = It.Value(); - Standard_Boolean found; - Handle(GEOM_AISShape) Shape = GeomGUI->ConvertIOinGEOMAISShape( IObject, found, true ); - if (!Shape.IsNull()) { - AIS_DisplayMode mode = ( AIS_DisplayMode )Shape->DisplayMode(); - if ( mode == -1 ) - mode = ( AIS_DisplayMode )ic->DisplayMode(); - - QApplication::setOverrideCursor( Qt::waitCursor ); - ic->SetDisplayMode(Shape, mode == AIS_WireFrame ? AIS_Shaded : AIS_WireFrame, false); - } - QApplication::restoreOverrideCursor(); - } - ic->UpdateCurrentViewer(); - } - QApplication::restoreOverrideCursor(); - break; - } - - case 8031: // COLOR - POPUP VIEWER - { - if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { - // VTK - VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor(); - - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - SALOME_ListIteratorOfListIO It(Sel->StoredIObjects()); - - Handle(SALOME_InteractiveObject) FirstIOS = Sel->firstIObject(); - if(!FirstIOS.IsNull()) { - - QColor initcolor = myRenderInter->GetColor(FirstIOS); - - QColor c = QColorDialog::getColor( initcolor, - QAD_Application::getDesktop() ); - - if ( c.isValid() ) { - QApplication::setOverrideCursor( Qt::waitCursor ); - for(;It.More();It.Next()) { - Handle(SALOME_InteractiveObject) IOS = It.Value(); - myRenderInter->SetColor(IOS,c); - } - } - QApplication::restoreOverrideCursor(); - } - } - else if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) { - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - Handle(SALOME_InteractiveObject) IO = Sel->firstIObject(); - Standard_Boolean found; - Handle(GEOM_AISShape) Shape = GeomGUI->ConvertIOinGEOMAISShape(IO, found, true); - if ( found ) { - Quantity_Color CSFColor; - Shape->Color( CSFColor ); - - QColor c = QColorDialog::getColor( QColor(CSFColor.Red() * 255.0, - CSFColor.Green()* 255.0, - CSFColor.Blue() * 255.0 ), - QAD_Application::getDesktop() ); - - if ( c.isValid() ) { - CSFColor = Quantity_Color ( c.red()/255., c.green()/255., c.blue()/255., Quantity_TOC_RGB ); - QApplication::setOverrideCursor( Qt::waitCursor ); - - SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() ); - for(;It.More();It.Next()) { - Handle(SALOME_InteractiveObject) IObject = It.Value(); - Standard_Boolean found; - Handle(GEOM_AISShape) Shape = GeomGUI->ConvertIOinGEOMAISShape(IObject, found, true); - if ( found ) { - Shape->SetColor ( CSFColor ); - Shape->SetShadingColor ( CSFColor ); - } - } - } - } - } - QApplication::restoreOverrideCursor(); - break; - } - - case 8032: // TRANSPARENCY - POPUP VIEWER - { - GeomGUI->EmitSignalDeactivateDialog() ; - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - GeometryGUI_TransparencyDlg *aDlg = new GeometryGUI_TransparencyDlg( parent, "", Sel, ic ) ; - break ; - } - - case 8033: // ISOS - POPUP VIEWER - { - if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) - break; - else { - ic->InitCurrent(); - if ( ic->MoreCurrent() ) { - Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current()); - QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU"); - QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV"); - - if ( !IsoU.isEmpty() ) - ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt()); - else - IsoU = "1"; - if ( !IsoV.isEmpty() ) - ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt()); - else - IsoV = "1"; - - GeometryGUI_NbIsosDlg * NbIsosDlg = - new GeometryGUI_NbIsosDlg(QAD_Application::getDesktop(), tr("GEOM_MEN_ISOS"), TRUE ); - - NbIsosDlg->SpinBoxU->setValue(IsoU.toInt()); - NbIsosDlg->SpinBoxV->setValue(IsoV.toInt()); - - if ( NbIsosDlg->exec() ) { - QApplication::setOverrideCursor( Qt::waitCursor ); - for ( ; ic->MoreCurrent (); ic->NextCurrent () ) { - Handle (AIS_Drawer) CurDrawer; - - CurDrawer = ic->Current()->Attributes(); - CurDrawer->UIsoAspect()->SetNumber( NbIsosDlg->SpinBoxU->text().toInt() ); - CurDrawer->VIsoAspect()->SetNumber( NbIsosDlg->SpinBoxV->text().toInt() ); - - ic->SetLocalAttributes(CurObject, CurDrawer); - ic->Redisplay(CurObject); - } - } - } - } - QApplication::restoreOverrideCursor(); - break; - } - - case 9022 : // ERASE - OBJBROSER POPUP - { - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { - // VTK - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() ); - Handle(SALOME_InteractiveObject) anIObject; - for(;It.More();It.Next()) { - anIObject = It.Value(); - VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor(); - -// Handle(SALOME_InteractiveObject) IObject; - if(myRenderInter->isInViewer(anIObject)) { - myRenderInter->Erase(anIObject); - } else { - SALOMEDS::SObject_var obj = aStudy->FindObjectID( anIObject->getEntry() ); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeIOR_var anIOR; - if ( !obj->_is_nil() ) { - if ( obj->FindAttribute(anAttr, "AttributeIOR")) { - // this SObject may be GEOM module root SObject - SALOMEDS::ChildIterator_var anIter = GeomGUI->myActiveStudy->getStudyDocument()->NewChildIterator(obj); - bool useSubItems = false; - while (anIter->More() && !useSubItems) { - SALOMEDS::SObject_var subobj = anIter->Value(); - SALOMEDS::GenericAttribute_var aTmpAttr; - if (subobj->FindAttribute(aTmpAttr, "AttributeIOR")) { - anAttr = aTmpAttr; - obj = subobj; - useSubItems = true; - } else anIter->Next(); - } - - while(useSubItems?anIter->More():!anAttr->_is_nil()) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - GEOM::GEOM_Shape_var aShape = GeomGUI->myComponentGeom->GetIORFromString(anIOR->Value()); - TopoDS_Shape Shape = ShapeReader.GetShape(GeomGUI->myComponentGeom,aShape); - if (obj->FindAttribute(anAttr, "AttributeName")) { - // searchin for already displayed objects with the same shape - vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer(); - vtkActorCollection* theAllActors = theRenderer->GetActors(); - theAllActors->InitTraversal(); - vtkActor* actor = (vtkActor*)theAllActors->GetNextActor(); - Handle(SALOME_InteractiveObject) anIObj; - // don't create new study object if it already exists - bool isDisplayed = false; - while(!(actor==NULL)) { - SALOME_Actor* Gactor = SALOME_Actor::SafeDownCast(actor); - if (Gactor!=NULL) { - if (Gactor->hasIO()) { - if (strcmp(Gactor->getIO()->getEntry(),obj->GetID())==0) { - isDisplayed = true; - anIObj = Gactor->getIO(); - if (!anIObj.IsNull()) myRenderInter->Erase(anIObj); - } - } - } - actor=(vtkActor*)(theAllActors->GetNextActor()); - } - } - if (useSubItems) { - anIter->Next(); - anAttr=SALOMEDS::GenericAttribute::_nil(); - while (anIter->More() && anAttr->_is_nil()) { - SALOMEDS::SObject_var subobject = anIter->Value(); - SALOMEDS::GenericAttribute_var aTmpAttribute; - if (subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) { - anAttr = aTmpAttribute; - obj = subobject; - } else anIter->Next(); - } - } else anAttr = SALOMEDS::GenericAttribute::_nil(); - } - } - } - } -// SALOME_ListIteratorOfListIO It(Sel->StoredIObjects()); -// for(;It.More();It.Next()) { -// Handle(SALOME_InteractiveObject) IOS = It.Value(); -// GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getVTKView()->getRWInteractor()->Erase(IOS);; - } -// SALOME_ListIteratorOfListIO It(Sel->StoredIObjects()); -// for(;It.More();It.Next()) { -// Handle(SALOME_InteractiveObject) IOS = It.Value(); -// GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getVTKView()->getRWInteractor()->Erase(IOS);; -// } - } - else if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) { - // OCC - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() ); - Handle(SALOME_InteractiveObject) anIObject; - for(;It.More();It.Next()) { - anIObject = It.Value(); - if ( v3d->isInViewer( anIObject, true ) ) { - Standard_Boolean found; - Handle(GEOM_AISShape) aSh = GeomGUI->ConvertIOinGEOMAISShape( anIObject, found, true ); - if ( found ) { - ic->Erase(aSh); - ic->AddOrRemoveCurrentObject(aSh, true); - } - } else { - SALOMEDS::SObject_var obj = aStudy->FindObjectID( anIObject->getEntry() ); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeIOR_var anIOR; - if ( !obj->_is_nil() ) { - if ( obj->FindAttribute(anAttr, "AttributeIOR")) { - // this SObject may be GEOM module root SObject - SALOMEDS::ChildIterator_var anIter = GeomGUI->myActiveStudy->getStudyDocument()->NewChildIterator(obj); - bool useSubItems = false; - while (anIter->More() && !useSubItems) { - SALOMEDS::SObject_var subobj = anIter->Value(); - SALOMEDS::GenericAttribute_var aTmpAttr; - if (subobj->FindAttribute(aTmpAttr, "AttributeIOR")) { - anAttr = aTmpAttr; - obj = subobj; - useSubItems = true; - } else anIter->Next(); - } - - while(useSubItems?anIter->More():!anAttr->_is_nil()) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - GEOM::GEOM_Shape_var aShape = GeomGUI->myComponentGeom->GetIORFromString(anIOR->Value()); - TopoDS_Shape Shape = ShapeReader.GetShape(GeomGUI->myComponentGeom,aShape); - if (obj->FindAttribute(anAttr, "AttributeName")) { - // searchin for already displayed objects with the same shape - AIS_ListOfInteractive aDisplayed; - ic->DisplayedObjects(aDisplayed); - AIS_ListIteratorOfListOfInteractive anIObjects(aDisplayed); - Handle(AIS_Shape) anAISShape; - for(;anIObjects.More();anIObjects.Next()) { - anAISShape = Handle(AIS_Shape)::DownCast(anIObjects.Value()); - if (!anAISShape.IsNull()) { - if (anAISShape->Shape().IsSame(Shape)) break; - anAISShape.Nullify(); - } - } - if (!anAISShape.IsNull()) { - if (ic->IsDisplayed(anAISShape)) ic->Erase(anAISShape); - } - } - if (useSubItems) { - anIter->Next(); - anAttr=SALOMEDS::GenericAttribute::_nil(); - while (anIter->More() && anAttr->_is_nil()) { - SALOMEDS::SObject_var subobject = anIter->Value(); - SALOMEDS::GenericAttribute_var aTmpAttribute; - if (subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) { - anAttr = aTmpAttribute; - obj = subobject; - } else anIter->Next(); - } - } else anAttr = SALOMEDS::GenericAttribute::_nil(); - } - } - } - } - } -// QAD_Viewer3d* v3d = GeomGUI->myActiveStudy->getActiveStudyFrame()->getViewerOCC(); -// Handle (AIS_InteractiveContext) myContext = v3d->getAISContext(); -// myContext->EraseSelected(); - } - - Sel->ClearIObjects(); - break; - } - - case 9023 : // DISPLAY ONLY - OBJBROSER POPUP - { - if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) - GeomGUI->OnVTKDisplayOnly(); - else if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) - GeomGUI->OnDisplayOnly(); - break; - } - - case 9024 : // OPEN - OBJBROSER POPUP - { - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() ); - Handle(SALOME_InteractiveObject) anIObject; - for(;It.More();It.Next()) { - anIObject = It.Value(); - SALOMEDS::SObject_var obj = aStudy->FindObjectID( anIObject->getEntry() ); - SALOMEDS::AttributePersistentRef_var aPersist; - SALOMEDS::AttributeIOR_var anIOR; - if ( !obj->_is_nil() ) { - // this SObject may be GEOM module root SObject - SALOMEDS::ChildIterator_var anIter = GeomGUI->myActiveStudy->getStudyDocument()->NewChildIterator(obj); - SALOMEDS::GenericAttribute_var anAttr; - bool useSubItems = false; - while (anIter->More() && !useSubItems) { - SALOMEDS::SObject_var subobj = anIter->Value(); - if (subobj->FindAttribute(anAttr, "AttributePersistentRef")) { - useSubItems = true; - obj = subobj; - } - else anIter->Next(); - } - obj->FindAttribute(anAttr, "AttributePersistentRef"); - - while(useSubItems?anIter->More():!anAttr->_is_nil()) { - if (!obj->FindAttribute(anAttr, "AttributeIOR") && - obj->FindAttribute(anAttr, "AttributePersistentRef")) { - // load - Engines::Component_var comp = GeomGUI->myDesktop->getEngine("FactoryServer","GEOM"); - if (!CORBA::is_nil(comp)) { - SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp); - - - SALOMEDS::StudyBuilder_var aStudyBuilder = GeomGUI->myActiveStudy->getStudyDocument()->NewBuilder(); - aStudyBuilder->LoadWith(GeomGUI->myActiveStudy->getStudyDocument()->FindComponent("GEOM"),driver); - - } else { - MESSAGE("Component is null"); - } - } - if (useSubItems) { - anIter->Next(); - obj = anIter->Value(); - } else anAttr = SALOMEDS::GenericAttribute::_nil(); - } - } - } - break; - } - - case 10000 : // SKETCH Segment - { - if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) - break; - GeomGUI->OnSketchSegment(); - break; - } - case 10001 : // SKETCH Arc - { - if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) - break; - GeomGUI->OnSketchArc(); - break; - } - case 10002 : // SKETCH Set Angle - { - if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) - break; - GeomGUI->OnSketchSetAngle(); - break; - } - case 10003 : // SKETCH Set X - { - if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) - break; - GeomGUI->OnSketchSetx(); - break; - } - case 10004 : // SKETCH Set Y - { - if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) - break; - GeomGUI->OnSketchSety(); - break; - } - case 10006 : // SKETCH Delete - { - if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) - break; - GeomGUI->OnSketchDelete(); - break; - } - case 10007 : // SKETCH End - { - if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) - break; - GeomGUI->OnSketchEnd(); - break; - } - case 10008 : // SKETCH Close - { - if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) - break; - GeomGUI->OnSketchClose(); - break; - } - case 10010 : // SKETCH OptionsOnofflengthdimension - { - GeomGUI->OnSketchOptionsOnofflengthdimension(); - break; - } - case 10011 : // SKETCH OptionsOnoffangledimension - { - GeomGUI->OnSketchOptionsOnoffangledimension(); - break; - } - case 10012 : // SKETCH OptionsOnoffradiusdimension - { - GeomGUI->OnSketchOptionsOnoffradiusdimension(); - break; - } - case 10013 : // SKETCH OptionsOnoffxdimension - { - GeomGUI->OnSketchOptionsOnoffxdimension(); - break; - } - case 10014 : // SKETCH OptionsOnoffydimension - { - GeomGUI->OnSketchOptionsOnoffydimension(); - break; - } - - default: - { - parent->putInfo( tr("GEOM_PRP_COMMAND").arg(theCommandID ) ); - break; - } - } - - return true ; -} - -//======================================================================= -// function : ConvertClickToPoint() -// purpose : Returns the point clicked in 3D view -//======================================================================= -gp_Pnt GeometryGUI::ConvertClickToPoint( Standard_Real x, - Standard_Real y, - Handle(V3d_View) aView ) -{ - V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt; - aView->Eye(XEye, YEye, ZEye); - - aView->At(XAt, YAt, ZAt); - gp_Pnt EyePoint(XEye, YEye, ZEye); - gp_Pnt AtPoint(XAt, YAt, ZAt); - - gp_Vec EyeVector(EyePoint, AtPoint); - gp_Dir EyeDir(EyeVector); - - gp_Pln PlaneOfTheView = gp_Pln(AtPoint,EyeDir); - Standard_Real X, Y, Z; - aView->Convert(x, y, X, Y, Z); - gp_Pnt ConvertedPoint(X, Y, Z); - - gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project(PlaneOfTheView, ConvertedPoint); - gp_Pnt ResultPoint = ElSLib::Value(ConvertedPointOnPlane.X(), - ConvertedPointOnPlane.Y(), - PlaneOfTheView); - return ResultPoint; -} - - - - -//================================================================================== -// function : 0nMousePress() -// purpose : [static] manage mouse events -//================================================================================== -bool GeometryGUI::OnMousePress(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame) -{ - MESSAGE ( "GeometryGUI::OnMousePress") - GeometryGUI::GetOrCreateGeometryGUI(parent); - - if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) - return false; - - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - OCCViewer_ViewPort* vp = ((OCCViewer_ViewFrame*)studyFrame->getRightFrame()->getViewFrame())->getViewPort(); - - /* Get the clicked or selected point */ - gp_Pnt thePoint; - - if ( GeomGUI->myState == CURRENT_SKETCH) { - GeomGUI->mySketcher.ValidateEdge(); - if (GeomGUI->mySketcher.GetmyEdgesNumber() == 1 ) { - QMenuBar* Mb = GeomGUI->myDesktop->getMainMenuBar(); - QMenuData* pp; - QMenuItem* item = Mb->findItem(313,&pp); - pp->setItemEnabled( 313, true); // SKETCH CONTRAINTS - } - } else if( GeomGUI->myState == POINT_METHOD ) { - - GeomGUI->EraseSimulationShape() ; - GeometryGUI_PointDlg *DialogPt = (GeometryGUI_PointDlg*)(GeomGUI->myActiveDialogBox) ; - - if ( DialogPt->UseLocalContext() ) { - ic->InitSelected(); - if ( pe->state() == Qt::ShiftButton ) - v3d->getAISSelector()->shiftSelect(); /* Append selection */ - else - v3d->getAISSelector()->select(); /* New selection */ - - if ( ic->MoreSelected() ) { - thePoint = BRep_Tool::Pnt( TopoDS::Vertex(ic->SelectedShape()) ); - } - else - thePoint = ConvertClickToPoint(pe->x(), pe->y(), ( (OCCViewer_ViewPort3d*)vp)->getView() ); - } - else - thePoint = ConvertClickToPoint(pe->x(), pe->y(), ( (OCCViewer_ViewPort3d*)vp)->getView() ); - - if( DialogPt != 0 ) { - DialogPt->PointIntoCoordinates(thePoint, true) ; /* display point */ - } - else { - // MESSAGE ("On Mouse Press : myActiveDialogBox is null" << endl) ; - GeomGUI->myDesktop->putInfo(tr("GEOM_PRP_ABORT")); - } - } - - return false ; -} - - -//======================================================================= -// function : OnMouseMove() -// purpose : [static] manage mouse events -//======================================================================= -bool GeometryGUI::OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame) -{ - GeometryGUI::GetOrCreateGeometryGUI(parent); - - if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC) - return false; - - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - OCCViewer_ViewPort* vp = ((OCCViewer_ViewFrame*)studyFrame->getRightFrame()->getViewFrame())->getViewPort(); - - if ( GeomGUI->myState == CURRENT_SKETCH) - GeomGUI->mySketcher.MakeCurrentEdge( pe->x(), pe->y(), ((OCCViewer_ViewPort3d*)vp)->getView() ); - - return true; -} - - -//================================================================================ -// function : SetDisplayedObjectList() -// purpose : -//================================================================================ -void GeometryGUI::SetDisplayedObjectList() -{ - if (myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC) - return; - - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - ListDisplayedObject.Clear(); - - Handle (AIS_InteractiveContext) aContext = v3d->getAISContext(); - aContext->DisplayedObjects( ListDisplayedObject ); -} - - - -//===================================================================================== -// function : OnDisplayAll() -// purpose : -//===================================================================================== -void GeometryGUI::OnDisplayAll(bool onlyPreviousDisplayedObject) -{ - if (myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC) - return; - - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) myContext = v3d->getAISContext(); - - myContext->Display(v3d->getTrihedron()); - - if ( !onlyPreviousDisplayedObject ) { - AIS_ListOfInteractive List1; - myContext->ObjectsInCollector(List1); - AIS_ListIteratorOfListOfInteractive ite1(List1); - while (ite1.More()) { - if (ite1.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) { - Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite1.Value()); - if ( aSh->hasIO() ) { - Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(aSh->getIO()); - if ( v3d->isInViewer(GIO, true) ) { - myContext->Display(aSh); - } - } - } - ite1.Next(); - } - } else { - AIS_ListIteratorOfListOfInteractive ite(ListDisplayedObject); - while (ite.More()) { - if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) { - Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value()); - if ( aSh->hasIO() ) { - Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(aSh->getIO()); - if ( v3d->isInViewer(GIO,true) ) { - myContext->Display(aSh); - } - } - } - ite.Next(); - } - } -} - - - - -//===================================================================================== -// function : OnVTKDisplayOnly() -// purpose : -//===================================================================================== -void GeometryGUI::OnVTKDisplayOnly() -{ - - // Erase all not selected actors - - QApplication::setOverrideCursor( Qt::waitCursor ); - - vtkRenderer* aren = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer(); - vtkActorCollection* theActors = aren->GetActors(); - theActors->InitTraversal(); - vtkActor *ac = theActors->GetNextActor(); - while(!(ac==NULL)) { - if ( ac->IsA("SALOME_Actor") ) { - SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ); - if(!anActor->isHighlighted()) anActor->VisibilityOff(); - } - ac = theActors->GetNextActor(); - } - - // Display selection - SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument(); - SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); - SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(GeomGUI->myActiveStudy->getActiveStudyFrame()->entry()); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeName_var aName; - SALOMEDS::AttributeIOR_var anIOR; - - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() ); - - for(;It.More();It.Next()) { - Handle(SALOME_InteractiveObject) IObject = It.Value(); - SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() ); - - VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor(); - - if(myRenderInter->isInViewer(IObject)) { - myRenderInter->Display(IObject); - } - else { - // Create new actor - if ( !obj->_is_nil() ) { - if ( !obj->FindAttribute(anAttr, "AttributeIOR")) - break; - // If selected object contains displayable subobjects, then do nothing - SALOMEDS::ChildIterator_var anIter = GeomGUI->myActiveStudy->getStudyDocument()->NewChildIterator(obj); - SALOMEDS::GenericAttribute_var aTmpAttr; - - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - GEOM::GEOM_Shape_var aShape = GeomGUI->myComponentGeom->GetIORFromString(anIOR->Value()); - if (CORBA::is_nil(aShape)) continue; - TopoDS_Shape Shape = ShapeReader.GetShape(GeomGUI->myComponentGeom,aShape); - - if (obj->FindAttribute(anAttr, "AttributeName")) { - aName = SALOMEDS::AttributeName::_narrow(anAttr); - // open transaction - QAD_Operation* op = new SALOMEGUI_ImportOperation( GeomGUI->myActiveStudy ); - op->start(); - - SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF); - aStudyBuilder->Addreference(newObj1, obj); - // commit transaction - op->finish(); - - vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer(); - int themode = myRenderInter->GetDisplayMode(); - vtkActorCollection* theActors = - GEOM_AssemblyBuilder::BuildActors(Shape,0,themode,Standard_True); - theActors->InitTraversal(); - vtkActor* anActor = (vtkActor*)theActors->GetNextActor(); - while(!(anActor==NULL)) { - GEOM_Actor* GActor = GEOM_Actor::SafeDownCast( anActor ); - GActor->setIO( IObject ); - GActor->setName( IObject->getName() ); - - theRenderer->AddActor(GActor); - vtkRenderWindow *renWin - = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer()->GetRenderWindow(); - renWin->Render(); - anActor = (vtkActor*)theActors->GetNextActor(); - } - } - } - } - } - GeomGUI->myActiveStudy->updateObjBrowser( true ); - QApplication::restoreOverrideCursor(); -} - - - -//===================================================================================== -// function : OnDisplayOnly() -// purpose : -//===================================================================================== -void GeometryGUI::OnDisplayOnly() -{ - if (myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC) - return; - - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - - AIS_ListOfInteractive List; - ic->DisplayedObjects(List); - AIS_ListIteratorOfListOfInteractive ite(List); - while (ite.More()) { - if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) { - Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value()); - if (!ic->IsSelected( aSh )) { - ic->Erase( aSh, Standard_True, Standard_True ); - } - } - ite.Next(); - } - - SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); - SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() ); - - SALOME_ListIteratorOfListIO It1( Sel->StoredIObjects() ); - for(;It1.More();It1.Next()) { - Handle(SALOME_InteractiveObject) IObject = It1.Value(); - - - SALOMEDS::SObject_var fatherSF = - aStudy->FindObjectID(myActiveStudy->getActiveStudyFrame()->entry()); - if ( v3d->isInViewer( IObject, true ) ) { - AIS_ListOfInteractive List1; - ic->ObjectsInCollector(List1); - AIS_ListIteratorOfListOfInteractive ite1(List1); - while (ite1.More()) { - if (ite1.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) { - Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite1.Value()); - if ( aSh->hasIO() ) { - Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(aSh->getIO()); - if ( IObject->isSame( GIO ) ) { - ic->Display(aSh); - ic->AddOrRemoveCurrentObject(aSh, true); - break; - } - } - } - ite1.Next(); - } - } else { - if ( IObject->hasEntry() ) { - SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() ); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeName_var aName; - SALOMEDS::AttributeIOR_var anIOR; - if ( !obj->_is_nil() ) { - if (obj->FindAttribute(anAttr, "AttributeIOR")) { - // this SObject may be GEOM module root SObject - - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - GEOM::GEOM_Shape_var aShape = myComponentGeom->GetIORFromString( anIOR->Value() ); - if (CORBA::is_nil(aShape)) continue; - TopoDS_Shape Shape = ShapeReader.GetShape(myComponentGeom, aShape); - - if (obj->FindAttribute(anAttr, "AttributeName")) { - aName = SALOMEDS::AttributeName::_narrow(anAttr); - // open transaction - QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy ); - op->start(); - - SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF); - aStudyBuilder->Addreference(newObj1, obj); - // commit transaction - op->finish(); - } - - Handle(GEOM_AISShape) aSh = new GEOM_AISShape(Shape, aName->Value()); - Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(), Fatherior,"GEOM"); - - IO->setEntry(obj->GetID()); - aSh->setIO( IO ); - aSh->setName( aName->Value() ); - ic->Display (aSh); - ic->AddOrRemoveCurrentObject(aSh, true); - } - } - } - } - } -} - - -//=============================================================================== -// function : OnEditDelete() -// purpose : -//=============================================================================== -void GeometryGUI::OnEditDelete() -{ - if ( QAD_MessageBox::warn2 - ( QAD_Application::getDesktop(), - tr ("GEOM_WRN_WARNING"), - tr ("GEOM_REALLY_DELETE"), - tr ("GEOM_BUT_YES"), tr ("GEOM_BUT_NO"), 1, 0, 0) != 1 ) - return; - - int nbSf = myActiveStudy->getStudyFramesCount(); - - Standard_Boolean found; - SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument(); - SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeIOR_var anIOR; - - SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() ); - SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() ); - for(;It.More();It.Next()) { - Handle(SALOME_InteractiveObject) IObject = It.Value(); - if ( IObject->hasEntry() ) { - SALOMEDS::Study_var aStudy = GeomGUI->myActiveStudy->getStudyDocument(); - SALOMEDS::SObject_var SO = aStudy->FindObjectID( IObject->getEntry() ); - - /* Erase child graphical objects */ - SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO); - for (; it->More();it->Next()) { - SALOMEDS::SObject_var CSO= it->Value(); - if (CSO->FindAttribute(anAttr, "AttributeIOR") ) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - /* Delete child(s) shape in Client : */ - const TCollection_AsciiString ASCior(anIOR->Value()) ; - ShapeReader.RemoveShapeFromBuffer( ASCior ) ; - - for ( int i = 0; i < nbSf; i++ ) { - QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i); - if ( sf->getTypeView() == VIEW_OCC ) { - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) myContext = v3d->getAISContext(); - Handle(GEOM_AISShape) Result = GeomGUI->ConvertIORinGEOMAISShape( anIOR->Value(), found ); - if ( found ) - myContext->Erase( Result, true, false ); - } else if ( sf->getTypeView() == VIEW_VTK ) { - //vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRenderer(); - VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRWInteractor(); - GEOM_Actor* ac = GeomGUI->ConvertIORinGEOMActor( anIOR->Value(), found ); - if ( found ) { - //Renderer->RemoveActor(ac); - if ( ac->hasIO() ) - myRenderInter->Remove( ac->getIO() ); - } - } - } - } - } - - /* Erase main graphical object */ - for ( int i = 0; i < nbSf; i++ ) { - QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i); - if ( sf->getTypeView() == VIEW_OCC ) { - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) myContext = v3d->getAISContext(); - Handle(GEOM_AISShape) Result = GeomGUI->ConvertIOinGEOMAISShape( IObject, found ); - if ( found ) - myContext->Erase( Result, true, false ); - } else if ( sf->getTypeView() == VIEW_VTK ) { - VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRWInteractor(); - myRenderInter->Remove( IObject ); - } - } - - /* Delete main shape in Client : */ - if (SO->FindAttribute(anAttr, "AttributeIOR") ) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - const TCollection_AsciiString ASCIor(anIOR->Value()) ; - ShapeReader.RemoveShapeFromBuffer( ASCIor ) ; - } - - /* Erase objects in Study */ - SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() ); - if ( !obj->_is_nil() ) { - QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy ); - op->start(); - aStudyBuilder->RemoveObject(obj); - op->finish(); - } - - } /* IObject->hasEntry() */ - } /* more/next */ - - /* Clear any previous selection */ - Sel->ClearIObjects() ; - myActiveStudy->updateObjBrowser(); -} - - -//============================================================================== -// function : OnEditCopy() -// purpose : -//============================================================================== -void GeometryGUI::OnEditCopy() -{ - SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() ); - GEOM::GEOM_Gen::ListOfIOR_var listIOR = new GEOM::GEOM_Gen::ListOfIOR; - - const SALOME_ListIO& List = Sel->StoredIObjects(); - - GeomGUI->ConvertListOfIOInListOfIOR( List, listIOR); - - Sel->ClearIObjects(); - - for (unsigned int ind = 0; ind < listIOR->length();ind++) { - GEOM::GEOM_Shape_var aShapeInit = myComponentGeom->GetIORFromString(listIOR[ind]); - try { - GEOM::GEOM_Shape_var result = myComponentGeom->MakeCopy(aShapeInit) ; - result->NameType( aShapeInit->NameType() ); - this->Display(result); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - } - - myDesktop->putInfo(tr("GEOM_PRP_READY")); -} - - - -//===================================================================================== -// function : OnKeyPress() -// purpose : [static] -//===================================================================================== -bool GeometryGUI::OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame) -{ - GeometryGUI::GetOrCreateGeometryGUI(parent); - - if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC) - return false; - - return true ; -} - - - -//===================================================================================== -// function : DisplaySimulationShape() -// purpose : Displays 'this->mySimulationShape' a pure graphical shape from a TopoDS_Shape -//===================================================================================== -void GeometryGUI::DisplaySimulationShape(const TopoDS_Shape& S) -{ - if( S.IsNull() ) - return ; - - //NRI DEBUG : 14/02/2002 - if ( myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) - return ; - - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - - try { - /* erase any previous */ - ic->Erase( this->mySimulationShape, Standard_True, Standard_False ); - ic->ClearPrs( this->mySimulationShape ); - this->mySimulationShape = new AIS_Shape( TopoDS_Shape() ) ; - this->mySimulationShape->Set( S ) ; - this->mySimulationShape->SetColor(Quantity_NOC_VIOLET) ; - ic->Deactivate( this->mySimulationShape ); - ic->Display( this->mySimulationShape, Standard_False ); - ic->UpdateCurrentViewer(); - } - catch(Standard_Failure) { - MESSAGE( "Exception catched in GeometryGUI::DisplaySimulationShape " ) ; - } - this->mySimulationShape->UnsetColor() ; - return ; -} - - - -//================================================================================== -// function : EraseSimulationShape() -// purpose : Clears the display of 'mySimulationShape' a pure graphical shape -//================================================================================== -void GeometryGUI::EraseSimulationShape() -{ - int count = myActiveStudy->getStudyFramesCount(); - for ( int i = 0; i < count; i++ ) { - if (myActiveStudy->getStudyFrame(i)->getTypeView() == VIEW_OCC ) { - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - ic->Erase( this->mySimulationShape, Standard_True, Standard_False ); - ic->ClearPrs( this->mySimulationShape ); - ic->UpdateCurrentViewer(); - - } else if (myActiveStudy->getStudyFrame(i)->getTypeView() == VIEW_VTK ) { // VTK - } - } - // MESSAGE ( " GeometryGUI::EraseSimulationShape done. " ) -} - - - -//===================================================================================== -// function : Import -// purpose : BRep, Iges, Step -//===================================================================================== -bool GeometryGUI::Import( ) -{ - SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument(); - SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); - - GEOM::GEOM_Shape_var aShape; - QString file; - QStringList filtersList ; - - switch ( GeomGUI->myState ) - { - case 111 : // Import BREP - { - filtersList.append( tr("GEOM_MEN_IMPORT_BREP") ); - filtersList.append( tr("GEOM_MEN_ALL_FILES") ) ; - - file = QAD_FileDlg::getFileName(myDesktop, - "", - filtersList, - tr("GEOM_MEN_IMPORT"), - true); - if ( !file.isEmpty() ) { - QApplication::setOverrideCursor( Qt::waitCursor ); - try { - aShape = myComponentGeom->ImportBREP( file.latin1() ); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - } - break; - } - case 112 : // Import IGES - { - filtersList.append( tr("GEOM_MEN_IMPORT_IGES") ) ; - filtersList.append( tr("GEOM_MEN_ALL_FILES") ) ; - - file = QAD_FileDlg::getFileName(myDesktop, - "", - filtersList, - tr("GEOM_MEN_IMPORT"), - true); - if ( !file.isEmpty() ) { - QApplication::setOverrideCursor( Qt::waitCursor ); - try { - aShape = myComponentGeom->ImportIGES( file.latin1() ); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - } - break; - } - case 113 : // Import STEP - { - filtersList.append( tr("GEOM_MEN_IMPORT_STEP") ) ; - filtersList.append( tr("GEOM_MEN_ALL_FILES") ) ; - - file = QAD_FileDlg::getFileName(myDesktop, - "", - filtersList, - tr("GEOM_MEN_IMPORT"), - true); - if ( !file.isEmpty() ) { - QApplication::setOverrideCursor( Qt::waitCursor ); - try { - aShape = myComponentGeom->ImportSTEP( file.latin1() ); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - } - break; - } - } - - if ( !file.isEmpty() ) { - myDesktop->putInfo( tr("GEOM_PRP_LOADING").arg(QAD_Tools::getFileNameFromPath( file )) ); - - SALOMEDS::SComponent_var father = aStudy->FindComponent("GEOM"); - SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID( myActiveStudy->getActiveStudyFrame()->entry()); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeName_var aName; - SALOMEDS::AttributePixMap_var aPixmap; - int aLocked = false; - if (father->_is_nil()) { - QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy ); - op->start(); - aLocked = aStudy->GetProperties()->IsLocked(); - if (aLocked) aStudy->GetProperties()->SetLocked(false); - father = aStudyBuilder->NewComponent("GEOM"); - anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeName"); - aName = SALOMEDS::AttributeName::_narrow(anAttr); - // aName->SetValue( tr("GEOM_MEN_COMPONENT") ); - aName->SetValue( QAD_Application::getDesktop()->getComponentUserName( "GEOM" ) ); - anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributePixMap"); - aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); - aPixmap->SetPixMap( "ICON_OBJBROWSER_Geometry" ); - if (aLocked) aStudy->GetProperties()->SetLocked(true); - op->finish(); - } -// if (aLocked) return false; - aStudyBuilder->DefineComponentInstance( father, myComponentGeom ); - father->ComponentIOR( Fatherior ); - - QString nameShape = QAD_Tools::getFileNameFromPath(file,false) + QString("_%1").arg(this->myNbGeom++); - - if ( Display ( aShape, strdup(nameShape.latin1())) ) { - myActiveStudy->setMessage( tr("GEOM_INF_LOADED").arg(QAD_Tools::getFileNameFromPath( file )) ); - myDesktop->putInfo( tr("GEOM_PRP_READY")); - } - } - QApplication::restoreOverrideCursor(); - return true ; -} - - -//===================================================================================== -// function : Export -// purpose : BRep, Iges, Step -//===================================================================================== -bool GeometryGUI::Export( ) -{ - SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument(); - SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); - - GEOM::GEOM_Shape_var aShape; - - static QString filters[] = { tr("GEOM_MEN_IMPORT_BREP"), - tr("GEOM_MEN_IMPORT_IGES"), - tr("GEOM_MEN_IMPORT_STEP") }; - - SALOME_Selection* Sel = SALOME_Selection::Selection( this->myActiveStudy->getSelection() ); - SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() ); - - switch ( GeomGUI->myState ) - { - case 121 : - { - for(;It.More();It.Next()) { - QApplication::restoreOverrideCursor(); - Handle(SALOME_InteractiveObject) IObject = It.Value(); - Standard_Boolean found; - GEOM::GEOM_Shape_var aShape = GeomGUI->ConvertIOinGEOMShape(IObject, found); - // Handle(GEOM_AISShape) Shape = ConvertIOinGEOMAISShape(IObject, found, true); - if ( found ) { - QString file = QAD_FileDlg::getFileName(myDesktop, - QString( IObject->getName() ) + ".brep", - tr("GEOM_MEN_IMPORT_BREP"), - tr("GEOM_MEN_EXPORT"), - false); - if ( !file.isEmpty() && !aShape->_is_nil() ) { - QApplication::setOverrideCursor( Qt::waitCursor ); - // Standard_Boolean result = BRepTools::Write(Shape->Shape(), strdup(file.latin1()) ); - try { - GeomGUI->myComponentGeom->ExportBREP(strdup( file.latin1()), aShape); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - } - } - } - break; - } - case 122 : - { - for(;It.More();It.Next()) { - QApplication::restoreOverrideCursor(); - Handle(SALOME_InteractiveObject) IObject = It.Value(); - Standard_Boolean found; - GEOM::GEOM_Shape_var aShape = GeomGUI->ConvertIOinGEOMShape(IObject, found); - // Handle(GEOM_AISShape) Shape = ConvertIOinGEOMAISShape(IObject, found, true); - if ( found ) { - QString file = QAD_FileDlg::getFileName(myDesktop, - QString( IObject->getName() ) + ".igs", - tr("GEOM_MEN_IMPORT_IGES"), - tr("GEOM_MEN_EXPORT"), - false); - if ( !file.isEmpty() && !aShape->_is_nil() ) { - QApplication::setOverrideCursor( Qt::waitCursor ); - try { - GeomGUI->myComponentGeom->ExportIGES(strdup( file.latin1()), aShape); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } -// //VRV: OCC 4.0 migration -// IGESControl_Controller::Init(); -// IGESControl_Writer ICW (Interface_Static::CVal("XSTEP.iges.unit"), -// Interface_Static::IVal("XSTEP.iges.writebrep.mode")); -// //VRV: OCC 4.0 migration - -// ICW.AddShape (Shape->Shape()); -// ICW.ComputeModel(); -// Standard_Boolean result = ICW.Write( strdup(file.latin1()) ); - } - } - } - break; - } - - case 123 : - { -// bool test = false ; -// IFSelect_ReturnStatus status ; -// //VRV: OCC 4.0 migration -// STEPControl_Writer aWriter; -// //VRV: OCC 4.0 migration - QString file; - - for( ; It.More(); It.Next() ) { -// GEOM::GEOM_Shape_var aShape = GeomGUI->ConvertIOinGEOMShape(IObject, found); - QApplication::restoreOverrideCursor(); - Handle(SALOME_InteractiveObject) IObject = It.Value(); - Standard_Boolean found; - GEOM::GEOM_Shape_var aShape = GeomGUI->ConvertIOinGEOMShape(IObject, found); - // Handle(GEOM_AISShape) Shape = ConvertIOinGEOMAISShape(IObject, found, true); - if ( found ) { - file = QAD_FileDlg::getFileName(myDesktop, - QString( IObject->getName() ) + ".stp", - tr("GEOM_MEN_IMPORT_STEP"), - tr("GEOM_MEN_EXPORT"), - false); - if ( !file.isEmpty() && !aShape->_is_nil() ) { - - QApplication::setOverrideCursor( Qt::waitCursor ) ; - try { - GeomGUI->myComponentGeom->ExportSTEP(strdup( file.latin1()), aShape); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } -// //VRV: OCC 4.0 migration -// status = aWriter.Transfer( Shape->Shape(), STEPControl_ManifoldSolidBrep ) ; -// //VRV: OCC 4.0 migration -// test = true ; -// if ( status != IFSelect_RetDone ) { -// QApplication::restoreOverrideCursor() ; -// return false ; -// } - } - } - } -// if(test) { -// status = aWriter.Write( strdup(file.latin1()) ) ; -// QApplication::restoreOverrideCursor() ; -// return status ; -// } - break; - } - - } - QApplication::restoreOverrideCursor() ; -} - - -//===================================================================================== -// function : Display() -// purpose : Displays a CORBA shape -//===================================================================================== -bool GeometryGUI::Display( GEOM::GEOM_Shape_ptr aShape, - Standard_CString name) -{ - // MESSAGE ( "GeometryGUI::Display init ") - Handle(GEOM_InteractiveObject) IO; - SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() ); - Sel->ClearIObjects(); - - if( aShape->_is_nil() ) { - QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), - tr ("GEOM_WRN_WARNING"), - tr ("GEOM_PRP_ABORT"), - tr ("GEOM_BUT_OK") ); - return false ; - } - - TopoDS_Shape shape = ShapeReader.GetShape(myComponentGeom, aShape); - - if ( shape.IsNull() ) - return false; - - SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument(); - SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeName_var aName; - SALOMEDS::AttributePixMap_var aPixmap; - - SALOMEDS::SComponent_var father = aStudy->FindComponent("GEOM"); - int aLocked = false; - if (father->_is_nil()) { - QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy ); - op->start(); - aLocked = aStudy->GetProperties()->IsLocked(); - if (aLocked) aStudy->GetProperties()->SetLocked(false); - father = aStudyBuilder->NewComponent("GEOM"); - anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeName"); - aName = SALOMEDS::AttributeName::_narrow(anAttr); - // aName->SetValue( tr("GEOM_MEN_COMPONENT") ); - aName->SetValue( QAD_Application::getDesktop()->getComponentUserName( "GEOM" ) ); - anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributePixMap"); - aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); - aPixmap->SetPixMap( "ICON_OBJBROWSER_Geometry" ); - myActiveStudy->updateObjBrowser(); - if (aLocked) aStudy->GetProperties()->SetLocked(true); - op->finish(); - } -// if (aLocked) return false; - - aStudyBuilder->DefineComponentInstance( father, myComponentGeom ); - father->ComponentIOR( Fatherior ); - - TCollection_AsciiString nameG(""); - Standard_CString Type; - if ( TCollection_AsciiString(name).IsEqual(Standard_CString("")) ) { - if ( TCollection_AsciiString(aShape->NameType()).IsEqual(Standard_CString("")) ) { - Standard_CString type; - GetShapeTypeString(shape,type); - aShape->NameType( type ); - nameG += TCollection_AsciiString( type ) + TCollection_AsciiString("_") + - TCollection_AsciiString( GeomGUI->myNbGeom++ ) + TCollection_AsciiString("\0"); - } else - nameG += TCollection_AsciiString( aShape->NameType()) + TCollection_AsciiString("_") + - TCollection_AsciiString( GeomGUI->myNbGeom++ ) + TCollection_AsciiString("\0"); - } else - nameG = TCollection_AsciiString(name); - - // VTK - if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { - VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor(); - - vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer(); - int themode = myRenderInter->GetDisplayMode(); - - vtkActorCollection* theActors = - GEOM_AssemblyBuilder::BuildActors(shape,0,themode,Standard_True); - theActors->InitTraversal(); - vtkActor* anActor = (vtkActor*)theActors->GetNextActor(); - - IO = new GEOM_InteractiveObject(aShape->Name(), - Fatherior, - "GEOM"); - while(!(anActor==NULL)) { - GEOM_Actor* GActor = GEOM_Actor::SafeDownCast( anActor ); - GActor->setIO( IO ); - GActor->setName( nameG.ToCString() ); - - theRenderer->AddActor(GActor); - anActor = (vtkActor*)theActors->GetNextActor(); - } - } - // OCC - else if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) { - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - Handle(GEOM_AISShape) theResult = new GEOM_AISShape( shape, nameG.ToCString() ); - theResult->SetShadingColor( myShadingColor ); - IO = new GEOM_InteractiveObject(aShape->Name(), - Fatherior, - "GEOM"); - theResult->setIO( IO ); - theResult->setName( nameG.ToCString() ); - - /* Precaution : close any local context to permit the display */ - if ( ic->HasOpenedContext() ) { - ic->CloseAllContexts(); - } - -// if(isInfinite) -// theResult->SetInfiniteState() ; - - ic->Display(theResult); - } - - Sel->AddIObject( IO, false ); - myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Repaint(); - if ( Settings_AddInStudy ) - GeomGUI->AddInStudy( false, IO ); - - return true; -} - - -//===================================================================================== -// function : AddInStudy() -// purpose : anIOShape or a selected shape -//===================================================================================== -bool GeometryGUI::AddInStudy( bool selection, - const Handle(SALOME_InteractiveObject)& anIO) -{ - SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() ); - if ( !( !Settings_AddInStudy || selection ) ) { - Sel->ClearIObjects(); - } - - SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument(); - SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeName_var aName; - SALOMEDS::AttributePixMap_var aPixmap; - SALOMEDS::AttributeIOR_var anIOR; - SALOMEDS::AttributeSelectable_var aSelAttr; - - SALOMEDS::SComponent_var father = aStudy->FindComponent("GEOM"); - int aLocked = false; - if (father->_is_nil()) { - QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy ); - op->start(); - aLocked = aStudy->GetProperties()->IsLocked(); - if (aLocked) aStudy->GetProperties()->SetLocked(false); - father = aStudyBuilder->NewComponent("GEOM"); - anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeName"); - aName = SALOMEDS::AttributeName::_narrow(anAttr); - // aName->SetValue( tr("GEOM_MEN_COMPONENT") ); - aName->SetValue( QAD_Application::getDesktop()->getComponentUserName( "GEOM" ) ); - anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributePixMap"); - aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); - aPixmap->SetPixMap( "ICON_OBJBROWSER_Geometry" ); - if (aLocked) aStudy->GetProperties()->SetLocked(true); - op->finish(); - } -// if (aLocked) return false; - - aStudyBuilder->DefineComponentInstance( father, myComponentGeom ); - father->ComponentIOR( Fatherior ); - - SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(myActiveStudy->getActiveStudyFrame()->entry()); - - Handle(GEOM_AISShape) GAISShape; - GEOM_Actor* GActor; - Handle(GEOM_InteractiveObject) GIO; - bool found = false; - - // VTK - if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { - vtkRenderer *Renderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer(); - - vtkActorCollection* theActors = Renderer->GetActors(); - theActors->InitTraversal(); - vtkActor *ac = theActors->GetNextActor(); - while(!(ac==NULL)) { - if ( ac->IsA("GEOM_Actor") ) { - GEOM_Actor* anActor = GEOM_Actor::SafeDownCast( ac ); - if ( anActor->hasIO() ) { - Handle(SALOME_InteractiveObject) IO = anActor->getIO(); - if ( IO->IsKind(STANDARD_TYPE(GEOM_InteractiveObject)) ) { - GIO = Handle(GEOM_InteractiveObject)::DownCast( IO ); - if ( anIO->isSame( GIO ) ) { - found = true; - GActor = anActor; - break; - } - } - } - } - ac = theActors->GetNextActor(); - } - - if ( !found ) - return false; - } - // OCC - else if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) { - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - - AIS_ListOfInteractive List; - ic->DisplayedObjects(List); - AIS_ListIteratorOfListOfInteractive ite(List); - while (ite.More()) { - if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) { - Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value()); - if ( aSh->hasIO() ) { - Handle(SALOME_InteractiveObject) IO = aSh->getIO(); - if ( IO->IsKind(STANDARD_TYPE(GEOM_InteractiveObject)) ) { - GIO = Handle(GEOM_InteractiveObject)::DownCast( IO ); - if ( anIO->isSame( GIO ) ) { - found = true; - GAISShape = aSh; - break; - } - } - } - } - ite.Next(); - } - - if ( !found ) - return false; - } - - if ( !Settings_AddInStudy || selection ) { - QString Name = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), anIO->getName() ); - if ( !Name.isEmpty() ) { - // VTK - if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { - GActor->setName( strdup(Name.latin1()) ); - } - // OCC - else if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) { - GAISShape->setName( strdup(Name.latin1()) ); - } - } else { - return false; - } - } - - // open transaction - QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy ); - op->start(); - - SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(father); - - GEOM::GEOM_Shape_var aShape = myComponentGeom->GetIORFromString( GIO->getIOR() ); - - /* For the shape inserted into the study we set its field 'studyshapeid' */ - /* so the shape will contain its corresponding entry in the study Ocaf doc. */ - aShape->StudyShapeId(newObj->GetID()) ; - - GIO->setEntry(newObj->GetID()); - - anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR"); - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - anIOR->SetValue(aShape->Name()); - - anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName"); - aName = SALOMEDS::AttributeName::_narrow(anAttr); - - anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePixMap"); - aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); - if ( aShape->ShapeType() == GEOM::COMPOUND ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" ); - } else if ( aShape->ShapeType() == GEOM::COMPSOLID ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" ); - } else if ( aShape->ShapeType() == GEOM::SOLID ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" ); - } else if ( aShape->ShapeType() == GEOM::SHELL ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" ); - } else if ( aShape->ShapeType() == GEOM::FACE ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" ); - } else if ( aShape->ShapeType() == GEOM::WIRE ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" ); - } else if ( aShape->ShapeType() == GEOM::EDGE ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" ); - } else if ( aShape->ShapeType() == GEOM::VERTEX ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" ); - } - - // VTK - if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { - GActor->setIO( GIO ); - aName->SetValue(GActor->getName()); - } - // OCC - else if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) { - GAISShape->setIO( GIO ); - aName->SetValue(GAISShape->getName()); - } - - SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF); - aStudyBuilder->Addreference(newObj1,newObj); - - GEOM::GEOM_Gen::ListOfIOR_var listIOR = new GEOM::GEOM_Gen::ListOfIOR; - listIOR = myComponentGeom->GetReferencedObjects(aShape); - - if (listIOR->length()>0) { - SALOMEDS::SObject_var Arguments = aStudyBuilder->NewObject(newObj); - anAttr = aStudyBuilder->FindOrCreateAttribute(Arguments, "AttributeName"); - aName = SALOMEDS::AttributeName::_narrow(anAttr); - aName->SetValue(tr("GEOM_ARGUMENTS")); - anAttr = aStudyBuilder->FindOrCreateAttribute(Arguments, "AttributeSelectable"); - aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr); - aSelAttr->SetSelectable(false); - - bool ObjectReferenced = false; - for (unsigned int ind = 0; ind < listIOR->length();ind++) { - SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR(listIOR[ind]); - - if ( !theObj->_is_nil() ) { - SALOMEDS::SObject_var RefObject = aStudyBuilder->NewObject(Arguments); - aStudyBuilder->Addreference(RefObject, theObj); - ObjectReferenced = true; - } - } - - if ( !ObjectReferenced ) - aStudyBuilder->RemoveObject(Arguments); - } - - op->finish(); - - - if ( !Settings_AddInStudy || selection ) { - myActiveStudy->updateObjBrowser(); - } else { - myActiveStudy->updateObjBrowser(false); - Sel->AddIObject( GIO ); - } - - // MESSAGE ( " highlihght done" ) - return true; - -} - - -//===================================================================================== -// function : GetShapeFromIOR() -// purpose : exist also as static method ! -//===================================================================================== -TopoDS_Shape GeometryGUI::GetShapeFromIOR( QString IOR ) -{ - TopoDS_Shape result; - if( IOR.stripWhiteSpace().isEmpty() ) - return result; - ORB_INIT &init = *SINGLETON_::Instance() ; - CORBA::ORB_var& _orb = init.orb() ; - CORBA::Object_var obj = _orb->string_to_object( (char*)(IOR.latin1()) ); - if ( CORBA::is_nil( obj ) ) - return result; - GEOM::GEOM_Shape_var aShape = myComponentGeom->GetIORFromString( IOR ); - if (!aShape->_is_nil()) { - result = ShapeReader.GetShape( myComponentGeom, aShape ); - } - return result; -} - - -//===================================================================================== -// function : SetSettings() -// purpose : [static] -//===================================================================================== -bool GeometryGUI::SetSettings( QAD_Desktop* parent ) -{ - /* Create or retrieve an object GeomGUI */ - GeometryGUI::GetOrCreateGeometryGUI(parent); - - //DCQ parent->menuBar()->setItemEnabled( 504, false); // CORRECTING - //DCQ parent->menuBar()->setItemEnabled( 6062, false); // RADIUS - //VSR parent->menuBar()->setItemEnabled( 701, false); // AUTOMATIC COPY - parent->menuBar()->setItemEnabled( 313, false); // SKETCH CONTRAINTS - parent->menuBar()->setItemEnabled( 3131, false); // SKETCH SET PLAN - - /* Shading Color */ - QString SCr = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorRed"); - QString SCg = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorGreen"); - QString SCb = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorBlue"); - if( !SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty() ) - GeomGUI->myShadingColor = Quantity_Color ( SCr.toInt()/255., SCg.toInt()/255., SCb.toInt()/255., - Quantity_TOC_RGB ); - - /* Wireframe or Shading */ - int DisplayMode = 0; - if ( parent->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) { - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)parent->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle(AIS_InteractiveContext) ic = v3d->getAISContext(); - DisplayMode = ic->DisplayMode(); - } else if ( parent->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { - VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)parent->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor(); - DisplayMode = myRenderInter->GetDisplayMode(); - } - - if ( DisplayMode == 1 ) - parent->menuBar()->changeItem(6021, tr("GEOM_MEN_WIREFRAME") ); - else - parent->menuBar()->changeItem(6021, tr("GEOM_MEN_SHADING") ); - - /* Copy */ -// QString Copy = QAD_CONFIG->getSetting("Geometry:SettingsCopy"); -// if ( !Copy.isEmpty() ) { -// Settings_Copy = Copy.toInt(); -// QMenuData* pp; -// parent->menuBar()->findItem(701,&pp); -// pp->setItemChecked(701, Settings_Copy); -// } - QMenuData* pp; - if ( parent->menuBar()->findItem(701,&pp) ) - pp->removeItem(701); - - /* Add in Study */ + // Add in Study - !!!ALWAYS TRUE!!! /////// VSR : TO BE REMOVED QString AddInStudy = QAD_CONFIG->getSetting("Geometry:SettingsAddInStudy"); - if ( !AddInStudy.isEmpty() ) - Settings_AddInStudy = AddInStudy.toInt(); - else - Settings_AddInStudy = 1; - parent->menuBar()->findItem(702,&pp); - pp->setItemChecked(702, Settings_AddInStudy); - - /* step value */ - QString S = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" ); - if( S.isEmpty() ) - QAD_CONFIG->addSetting( "Geometry:SettingsGeomStep", "100" ); - - /* isos */ - QAD_Study* ActiveStudy = parent->getActiveStudy(); - int count = ActiveStudy->getStudyFramesCount(); - - bool ViewOCC = false; - for ( int i = 0; i < count; i++ ) { - if ( ActiveStudy->getStudyFrame(i)->getTypeView() == VIEW_OCC ) { - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - - QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU"); - QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV"); - if ( !IsoU.isEmpty() ) - ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt()); - if ( !IsoV.isEmpty() ) - ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt()); - - ViewOCC = true; - } - } - - QMenuBar* Mb = GeomGUI->myDesktop->getMainMenuBar(); - - Mb->setItemEnabled( 312, ViewOCC); //Sketch - Mb->setItemEnabled( 309, ViewOCC); //SuppressFace - Mb->setItemEnabled( 314, ViewOCC); //SuppressHole - - Mb->setItemEnabled( 703, ViewOCC);// ShadingColor Settings - Mb->setItemEnabled( 704, ViewOCC);// Isos Settings - - return true; -} - - -//===================================================================================== -// function : DefinePopup() -// purpose : [static] -//===================================================================================== -void GeometryGUI::DefinePopup( QString & theContext, QString & theParent, QString & theObject ) -{ - /* Create or retrieve an object GeomGUI */ - GeometryGUI::GetOrCreateGeometryGUI(QAD_Application::getDesktop()); - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - - theObject = ""; - if ( Sel->IObjectCount() == 1 ) - { - Handle(SALOME_InteractiveObject) IO = Sel->firstIObject(); - if (IO->hasEntry()) - { - SALOMEDS::SObject_var sobj = GeomGUI->myActiveStudy->getStudyDocument()->FindObjectID(IO->getEntry()); - if (!sobj->_is_nil()) - { - SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent(); - if (strcmp(scomp->GetID(), IO->getEntry()) == 0) - { - // component is selected - theObject = "Component"; - } - } - } - } - - if ( ( theParent.compare("Viewer")==0 ) ) - { - if ( GeomGUI->myState == CURRENT_SKETCH ) - theContext = "Sketch"; - else - { - if ( Sel->IObjectCount() > 0 ) - theContext = ""; - else - theContext = "NothingSelected"; - } - } - else - theContext = ""; - -} - -//===================================================================================== -// function : CustomPopup() -// purpose : [static] -//===================================================================================== -bool GeometryGUI::CustomPopup( QAD_Desktop* parent, - QPopupMenu* popup, - const QString& theContext, - const QString& theParent, - const QString& theObject ) -{ - /* Create or retrieve an object GeomGUI */ - GeometryGUI::GetOrCreateGeometryGUI(parent); - - /* Deactivate any non modal dialog box to get the neutral point */ - GeomGUI->EmitSignalDeactivateDialog() ; - - SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() ); - int nbSel = Sel->IObjectCount(); - - if ( (nbSel == 0) && ( theContext.compare("Sketch")!=0 ) ) - return false; - - - if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC) - { - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()-> - getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - if ( theParent.compare("Viewer")==0 ) - { - if ( theContext.compare("Sketch")==0 ) - { - SketchStatus myCS = GeomGUI->mySketcher.GetCurrentStatus(); - popup->setCheckable(TRUE); - if (myCS==SEGMENT) - { - popup->setItemChecked(10000,true); - popup->setItemChecked(10001,false); - } - else if (myCS==ARC_CHORD) - { - popup->setItemChecked(10000,false); - popup->setItemChecked(10001,true); - } - - return true; - } - else - if (theObject.compare("Component") == 0) - { - popup->removeItem(QAD_DisplayOnly_Popup_ID); - return true; - } - else - { - QFont f = QApplication::font(); - f.setBold( TRUE ); - if (nbSel==1) - { - Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject(); - popup->removeItem(QAD_TopLabel_Popup_ID); - popup->insertItem( new CustomItem ( QString(IObject->getName()), f ), QAD_TopLabel_Popup_ID, 0 ); - if ( IObject->hasEntry() ) - popup->setItemEnabled( 801, false ); - else - popup->setItemEnabled( 801, true ); - - if (IObject->IsKind(STANDARD_TYPE(GEOM_InteractiveObject))) - { - Standard_Boolean found; - Handle(GEOM_AISShape) Result = GeomGUI->ConvertIOinGEOMAISShape(IObject, found, true); - - if ( found ) - { - if ( Result->DisplayMode() == 1 ) - popup->changeItem(8021, tr("GEOM_MEN_WIREFRAME") ); - else - popup->changeItem(8021, tr("GEOM_MEN_SHADING") ); - } - } - - if ( !(v3d->isInViewer( IObject ) && v3d->isVisible( IObject )) ) - popup->removeItem(QAD_Erase_Popup_ID); - else - popup->removeItem(QAD_Display_Popup_ID); - - } - else - { - popup->removeItem(QAD_DisplayOnly_Popup_ID); - popup->removeItem(QAD_TopLabel_Popup_ID); - popup->insertItem( new CustomItem ( tr("GEOM_MEN_POPUP_NAME").arg(nbSel), f ), - QAD_TopLabel_Popup_ID, 0 ); - popup->setItemEnabled( 801, false ); - } - } - return true; - } - else - if ( theParent.compare("ObjectBrowser")==0 ) - { - popup->removeItem(QAD_TopLabel_Popup_ID); - int id = popup->idAt(0); // separator - if (id < 0) popup->removeItem(id); - - // checking for GEOM label in the selected list - SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() ); - Handle(SALOME_InteractiveObject) anIObject; - - bool useSubItems = false; - bool needOpen = false; - bool needDisplay = false; - bool needErase = false; - SALOMEDS::GenericAttribute_var aTmpAttr; - for(;It.More();It.Next()) - { - anIObject = It.Value(); - if (!anIObject->hasEntry()) - continue; - - if (v3d->isInViewer(anIObject) && v3d->isVisible(anIObject)) - needErase = true; - else - needDisplay = true; - SALOMEDS::SObject_var obj = - GeomGUI->myActiveStudy->getStudyDocument()->FindObjectID( anIObject->getEntry() ); - if (!obj->_is_nil()) - { - GEOM::GEOM_Shape_var aShape; - if (obj->FindAttribute(aTmpAttr, "AttributeIOR")) { - char *str = SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value(); - if (str && strlen(str)) - aShape = GeomGUI->myComponentGeom-> GetIORFromString(str); - } - else - if (obj->FindAttribute(aTmpAttr, "AttributePersistentRef")) - needOpen = true; - if (aShape->_is_nil()) - { - SALOMEDS::ChildIterator_var anIter = GeomGUI->myActiveStudy-> - getStudyDocument()->NewChildIterator(obj); - while (anIter->More()) - { - SALOMEDS::SObject_var subobj = anIter->Value(); - if (subobj->FindAttribute(aTmpAttr, "AttributeIOR")) - { - useSubItems = true; - needErase = true; - needDisplay = true; - } - else - if (subobj->FindAttribute(aTmpAttr, "AttributePersistentRef")) - { - needOpen = true; - useSubItems = true; - } - anIter->Next(); - } - } - } - } - // remove useless popup items - if (nbSel != 1) popup->removeItem(901); // rename - if (useSubItems) popup->removeItem(QAD_DisplayOnly_Popup_ID); // display only - if (!needOpen) - { - int index = popup->indexOf(9024); - popup->removeItem(9024); // open - popup->removeItemAt(index); // separator under Open - - if (!needDisplay) popup->removeItem(QAD_Display_Popup_ID); - if (!needErase) popup->removeItem(QAD_Erase_Popup_ID); - if (!needDisplay && !needErase) - { - int id = popup->idAt(popup->count()-1); // last item - popup->removeItem(id); // separator - } - } - else - { - popup->removeItem(QAD_DisplayOnly_Popup_ID); // display only - popup->removeItem(QAD_Display_Popup_ID); - popup->removeItem(QAD_Erase_Popup_ID); - if (nbSel!=1) - { - int id = popup->idAt(popup->count()-1); // last item - popup->removeItem(id); // separator - } - } - return true; - } - // MESSAGE ( " CUSTOM POPUP VIEWER OCC done. ") - } - else - if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) - { - // MESSAGE ( " CUSTOM POPUP VIEWER VTK ") - if ( ( theParent.compare("Viewer")==0 ) ) - { - - popup->setItemEnabled( 8033, false ); - if (theObject.compare("Component") == 0) - { - popup->removeItem(QAD_DisplayOnly_Popup_ID); - return true; - } - - //int id = popup->idAt(0); - QFont f = QApplication::font(); - f.setBold( TRUE ); - - if (nbSel==1) - { - Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject(); - popup->removeItem(QAD_TopLabel_Popup_ID); - popup->insertItem( new CustomItem ( QString(IObject->getName()), f ), QAD_TopLabel_Popup_ID, 0 ); - if ( IObject->hasEntry() ) - { - popup->setItemEnabled( 801, false ); - SALOMEDS::Study_var aStudy = GeomGUI->myActiveStudy->getStudyDocument(); - SALOMEDS::SObject_var SO = aStudy->FindObjectID( IObject->getEntry() ); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeIOR_var anIOR; - if ( !SO->_is_nil() ) - { - if (SO->FindAttribute(anAttr, "AttributeIOR") ) - { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - Standard_Boolean found; - GEOM_Actor* Result = GeomGUI->ConvertIORinGEOMActor(anIOR->Value(), found, true); - if ( found ) - { - if ( Result->getDisplayMode() == 1 ) - popup->changeItem(8021, "Wireframe" ); - else - popup->changeItem(8021, "Shading" ); - - if ( !Result->GetVisibility() ) - popup->removeItem(QAD_Erase_Popup_ID); - else - popup->removeItem(QAD_Display_Popup_ID); - } - else - popup->removeItem(QAD_Erase_Popup_ID); - } - } - } - else - popup->setItemEnabled( 801, true ); - } - else - { - popup->removeItem(QAD_DisplayOnly_Popup_ID); - popup->removeItem(QAD_TopLabel_Popup_ID); - popup->insertItem( new CustomItem ( tr("GEOM_MEN_POPUP_NAME").arg(nbSel), f ), QAD_TopLabel_Popup_ID, 0 ); - popup->setItemEnabled( 801, false ); - } - return true; - } - else - if ( theParent.compare("ObjectBrowser")==0 ) - { - popup->removeItem(QAD_TopLabel_Popup_ID); - int id = popup->idAt(0); // separator - if (id < 0) popup->removeItem(id); - - // checking for GEOM label in the selected list - SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() ); - Handle(SALOME_InteractiveObject) anIObject; - - bool useSubItems = false; - bool needOpen = false; - bool needDisplay = false; - bool needErase = false; - SALOMEDS::GenericAttribute_var aTmpAttr; - VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy-> - getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor(); - for(;It.More();It.Next()) - { - anIObject = It.Value(); - if ( !anIObject->hasEntry() ) - continue; - - if (myRenderInter->isInViewer(anIObject) && myRenderInter->isVisible(anIObject)) - needErase = true; - else - needDisplay = true; - - SALOMEDS::SObject_var obj = GeomGUI->myActiveStudy->getStudyDocument() - ->FindObjectID( anIObject->getEntry() ); - if (!obj->_is_nil()) { - GEOM::GEOM_Shape_var aShape; - if (obj->FindAttribute(aTmpAttr, "AttributeIOR")){ - char *str = SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value(); - if (str && strlen(str)) - aShape = GeomGUI->myComponentGeom->GetIORFromString(str); - } - else - if (obj->FindAttribute(aTmpAttr, "AttributePersistentRef")) - needOpen = true; - if (aShape->_is_nil()) - { - SALOMEDS::ChildIterator_var anIter = - GeomGUI->myActiveStudy->getStudyDocument()->NewChildIterator(obj); - while (anIter->More()) - { - SALOMEDS::SObject_var subobj = anIter->Value(); - if (subobj->FindAttribute(aTmpAttr, "AttributeIOR")) - { - useSubItems = true; - needDisplay = true; - needErase = true; - } - else - if (subobj->FindAttribute(aTmpAttr, "AttributePersistentRef")) - { - needOpen = true; - useSubItems = true; - } - anIter->Next(); - } - } - } - } - // remove useless popup items - if (nbSel != 1) popup->removeItem(901); // rename - if (useSubItems) popup->removeItem(QAD_DisplayOnly_Popup_ID); // display only - if (!needOpen) - { - int index = popup->indexOf(9024); - popup->removeItem(9024); // open - popup->removeItemAt(index); // separator under Open - - if (!needDisplay) popup->removeItem(QAD_Display_Popup_ID); - if (!needErase) popup->removeItem(QAD_Erase_Popup_ID); - if (!needDisplay && !needErase) - { - int id = popup->idAt(popup->count()-1); // last item - popup->removeItem(id); // separator - } - } - else - { - popup->removeItem(QAD_DisplayOnly_Popup_ID); // display only - popup->removeItem(QAD_Display_Popup_ID); - popup->removeItem(QAD_Erase_Popup_ID); - if (nbSel!=1) - { - int id = popup->idAt(popup->count()-1); // last item - popup->removeItem(id); // separator - } - } - return true; - // MESSAGE ( " CUSTOM POPUP VIEWER VTK done.") - } - } else - { // other viewer types not supported. - while (1) - { - int id = popup->idAt(0); - if (id <= QAD_TopLabel_Popup_ID && id != -1) - popup->removeItemAt(0); - else - break; - } - popup->removeItem(QAD_DisplayOnly_Popup_ID); - popup->removeItem(QAD_Display_Popup_ID); - popup->removeItem(QAD_Erase_Popup_ID); - int id = popup->idAt(popup->count()-1); // last item - if (id < 0 && id != -1) popup->removeItem(id); // separator - return false; - } - return false; -} + int Settings_AddInStudy; + // if(!AddInStudy.isEmpty()) + // Settings_AddInStudy = AddInStudy.toInt(); + // else -void GeometryGUI::BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO) -{ - /* Create or retrieve an object GeomGUI */ - GeometryGUI::GetOrCreateGeometryGUI(QAD_Application::getDesktop()); - - SALOMEDS::Study_var aStudy = GeomGUI->myActiveStudy->getStudyDocument(); - SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); - - OCCViewer_Viewer3d* v3d; - Handle(AIS_InteractiveContext) ic; - vtkRenderer* Renderer; - - if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) { - v3d = ((OCCViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - ic = v3d->getAISContext(); - } else if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { - Renderer = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer(); - } else - return; + Settings_AddInStudy = 1; + Mb->setItemChecked(411, Settings_AddInStudy); - if (theIO.IsNull()) - MESSAGE("BuildPresentation(): null SALOME_InteractiveObject passed") - - if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { - // VTK - - SALOMEDS::SObject_var fatherSF = - aStudy->FindObjectID(GeomGUI->myActiveStudy->getActiveStudyFrame()->entry()); - - SALOMEDS::SObject_var obj = aStudy->FindObjectID( theIO->getEntry() ); - - VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor(); - - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeName_var aName; - SALOMEDS::AttributeIOR_var anIOR; - - if(myRenderInter->isInViewer(theIO)) { - myRenderInter->Display(theIO, false); - } - else { - // Create new actor - if ( !obj->_is_nil() ) { - if ( obj->FindAttribute(anAttr, "AttributeIOR")) { - // this SObject may be GEOM module root SObject - - bool useSubItems = false; - SALOMEDS::ChildIterator_var anIter = GeomGUI->myActiveStudy->getStudyDocument()->NewChildIterator(obj); - if (GeomGUI->myComponentGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value())->_is_nil()) { - while (anIter->More() && !useSubItems) { - SALOMEDS::SObject_var subobj = anIter->Value(); - SALOMEDS::GenericAttribute_var aTmpAttr; - if (subobj->FindAttribute(aTmpAttr, "AttributeIOR")) { - if (!GeomGUI->myComponentGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value())->_is_nil()) { - anAttr = aTmpAttr; - obj = subobj; - useSubItems = true; - } else anIter->Next(); - } else anIter->Next(); - } - } + // step value + QString S = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep"); + if(S.isEmpty()) + QAD_CONFIG->addSetting("Geometry:SettingsGeomStep", "100"); - while(useSubItems?anIter->More():!anAttr->_is_nil()) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - GEOM::GEOM_Shape_var aShape = GeomGUI->myComponentGeom->GetIORFromString(anIOR->Value()); - TopoDS_Shape Shape = ShapeReader.GetShape(GeomGUI->myComponentGeom,aShape); - - if (obj->FindAttribute(anAttr, "AttributeName")) { - aName = SALOMEDS::AttributeName::_narrow(anAttr); - - vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer(); - vtkActorCollection* theAllActors = theRenderer->GetActors(); - theAllActors->InitTraversal(); - vtkActor* actor = (vtkActor*)theAllActors->GetNextActor(); - Handle(SALOME_InteractiveObject) anIObj; - // don't create new study object if it already exists - bool isDisplayed = false; - while(!(actor==NULL)) { - SALOME_Actor* Gactor = SALOME_Actor::SafeDownCast(actor); - if (Gactor!=NULL) { - if (Gactor->hasIO()) { - if (strcmp(Gactor->getIO()->getEntry(),obj->GetID())==0) { - isDisplayed = true; - anIObj = Gactor->getIO(); - if (!anIObj.IsNull()) myRenderInter->Display(anIObj, false); - } - } - } - actor=(vtkActor*)(theAllActors->GetNextActor()); - } - if (!isDisplayed) { - // open transaction - QAD_Operation* op = new SALOMEGUI_ImportOperation( GeomGUI->myActiveStudy ); - op->start(); - - SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF); - aStudyBuilder->Addreference(newObj1, obj); - // commit transaction - op->finish(); - - vtkRenderWindow *renWin = theRenderer->GetRenderWindow(); - int themode = myRenderInter->GetDisplayMode(); - - vtkActorCollection* theActors = - GEOM_AssemblyBuilder::BuildActors(Shape,0,themode,Standard_True); - theActors->InitTraversal(); - vtkActor* anActor = (vtkActor*)theActors->GetNextActor(); - while(!(anActor==NULL)) { - GEOM_Actor* GActor = GEOM_Actor::SafeDownCast( anActor ); - Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(), Fatherior,"GEOM"); - IO->setEntry(obj->GetID()); - GActor->setIO( IO ); - GActor->setName( theIO->getName() ); - - theRenderer->AddActor(GActor); - // renWin->Render(); - anActor = (vtkActor*)theActors->GetNextActor(); - } - } - } - // next item iteration - if (useSubItems) { - anIter->Next(); - anAttr = SALOMEDS::GenericAttribute::_nil(); - while (anIter->More() && anAttr->_is_nil()) { - SALOMEDS::SObject_var subobject = anIter->Value(); - SALOMEDS::GenericAttribute_var aTmpAttribute; - if (subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) { - anAttr = aTmpAttribute; - obj = subobject; - } else anIter->Next(); - } - } else anAttr = SALOMEDS::GenericAttribute::_nil(); - } - } - } - } - // No viewer update should be done here! - //myRenderInter->Render(); - //GeomGUI->myActiveStudy->updateObjBrowser( true ); - } else if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) { - SALOMEDS::SObject_var fatherSF = - aStudy->FindObjectID( GeomGUI->myActiveStudy->getActiveStudyFrame()->entry()); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeName_var aName; - SALOMEDS::AttributeIOR_var anIOR; - - if ( v3d->isInViewer( theIO, true ) ) { - Standard_Boolean found; - Handle(GEOM_AISShape) aSh = GeomGUI->ConvertIOinGEOMAISShape( theIO, found, true ); - if ( found ) { - ic->Display(aSh, false); - ic->AddOrRemoveCurrentObject(aSh, false); - } - - } else { - SALOMEDS::SObject_var obj = aStudy->FindObjectID( theIO->getEntry() ); - if ( !obj->_is_nil() ) { - MESSAGE("BuildPresentation(): SObject not null") - if ( obj->FindAttribute(anAttr, "AttributeIOR")) { - MESSAGE("BuildPresentation(): SObject has IOR") - // this SObject may be GEOM module root SObject - - bool useSubItems = false; - SALOMEDS::ChildIterator_var anIter = GeomGUI->myActiveStudy->getStudyDocument()->NewChildIterator(obj); - if (GeomGUI->myComponentGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value())->_is_nil()) { - while (anIter->More() && !useSubItems) { - SALOMEDS::SObject_var subobj = anIter->Value(); - SALOMEDS::GenericAttribute_var aTmpAttr; - if (subobj->FindAttribute(aTmpAttr, "AttributeIOR")) { - if (!GeomGUI->myComponentGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value())->_is_nil()) { - anAttr = aTmpAttr; - obj = subobj; - useSubItems = true; - } else anIter->Next(); - } else anIter->Next(); - } - } + // isos + int count = ActiveStudy->getStudyFramesCount(); + for(int i = 0; i < count; i++) { + if(ActiveStudy->getStudyFrame(i)->getTypeView() == VIEW_OCC) { + OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer(); + Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - while(useSubItems?anIter->More():!anAttr->_is_nil()) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - GEOM::GEOM_Shape_var aShape = GeomGUI->myComponentGeom->GetIORFromString(anIOR->Value()); - TopoDS_Shape Shape = ShapeReader.GetShape(GeomGUI->myComponentGeom,aShape); - if (Shape.IsNull()) - MESSAGE("BuildPresentation(): TopoDS_Shape is null!") - if (obj->FindAttribute(anAttr, "AttributeName")) { - MESSAGE("BuildPresentation(): SObject has Name") - aName = SALOMEDS::AttributeName::_narrow(anAttr); - // searchin for already displayed objects with the same shape - AIS_ListOfInteractive aDisplayed; - ic->DisplayedObjects(aDisplayed); - AIS_ListIteratorOfListOfInteractive anIObjects(aDisplayed); - Handle(AIS_Shape) anAISShape; - for(;anIObjects.More();anIObjects.Next()) { - anAISShape = Handle(AIS_Shape)::DownCast(anIObjects.Value()); - if (!anAISShape.IsNull()) { - if (anAISShape->Shape().IsSame(Shape)) break; - anAISShape.Nullify(); - } - } - if (!anAISShape.IsNull()) { - if (!ic->IsDisplayed(anAISShape)) ic->Display(anAISShape, false); - } else { - if (!useSubItems) { - // open transaction - QAD_Operation* op = new SALOMEGUI_ImportOperation( GeomGUI->myActiveStudy ); - op->start(); - if (fatherSF->_is_nil()) - MESSAGE("BuildPresentation(): fatherSF is nil!") - SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF); - aStudyBuilder->Addreference(newObj1, obj); - // commit transaction - op->finish(); - } - Handle(GEOM_AISShape) aSh = new GEOM_AISShape(Shape, aName->Value()); - aSh->SetShadingColor( GeomGUI->myShadingColor ); - Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(), - Fatherior, - "GEOM"); - IO->setEntry(obj->GetID()); - aSh->setIO( IO ); - aSh->setName( aName->Value() ); - ic->Display (aSh, false); - if (!useSubItems) ic->AddOrRemoveCurrentObject(aSh, false); - } - } - // next item iteration - if (useSubItems) { - anIter->Next(); - anAttr=SALOMEDS::GenericAttribute::_nil(); - while (anIter->More() && anAttr->_is_nil()) { - SALOMEDS::SObject_var subobject = anIter->Value(); - SALOMEDS::GenericAttribute_var aTmpAttribute; - if (subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) { - anAttr = aTmpAttribute; - obj = subobject; - } else anIter->Next(); - } - } else - anAttr = SALOMEDS::GenericAttribute::_nil(); - } - } - } + QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU"); + QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV"); + if(!IsoU.isEmpty()) + ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt()); + if(!IsoV.isEmpty()) + ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt()); } - // No viewer update should be done here! - //GeomGUI->myActiveStudy->updateObjBrowser( true ); - //ic->UpdateCurrentViewer(); } + + setActionsEnabled(); + + // PAL5356: update VTK selection + ::UpdateVtkSelection(); + bool bOk = true; + GUIMap::Iterator it; + for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it ) + bOk = bOk && it.data()->SetSettings( parent ); + + // MZN: Enable/disable "Clipping range" menu item(from GEOM_CLIPPING variable) + if (getenv( "GEOM_CLIPPING" ) == NULL) + { + QMenuItem* mi = Mb->findItem(50); + if (mi && mi->popup()) + mi->popup()->removeItem(507); + } + + return bOk; } +*/ //======================================================================= -// function : Parameter() -// purpose : return a parameter (float) from a dialog box -// -// avalue1 : is a float or integer used as a default value displayed -// aTitle1 : is the title for aValue1 -// aTitle : is the main title -// bottom : maximum value to be entered -// top : minimum value to be entered -// decimals : number of decimals +// function : createGeomAction +// purpose : //======================================================================= -double GeometryGUI::Parameter( Standard_Boolean& res, - const char* aValue1, - const char* aTitle1, - const char* aTitle, - const double bottom, - const double top, - const int decimals ) +void GeometryGUI::createGeomAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle ) { - GeometryGUI_aParameterDlg * Dialog = - new GeometryGUI_aParameterDlg(aValue1, - aTitle1, - QAD_Application::getDesktop(), - aTitle, - TRUE, - 0, - bottom, - top, - decimals) ; - int r = Dialog->exec() ; - float X = 0.0 ; - if ( r == QDialog::Accepted ) { - res = Standard_True; - X = Dialog->getValue(); - } else - res = Standard_False; - delete Dialog; - return X; -} + QIconSet icon; + QWidget* parent = application()->desktop(); + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + QPixmap pix; + if ( icon_id.length() ) + pix = resMgr->loadPixmap( "GEOM", tr( icon_id ) ); + else + pix = resMgr->loadPixmap( "GEOM", tr( QString( "ICO_" )+po_id ), false ); + if ( !pix.isNull() ) + icon = QIconSet( pix ); + + QString tooltip = tr( QString( "TOP_" )+po_id ), + menu = tr( QString( "MEN_" )+po_id ), + status_bar = tr( QString( "STB_" )+po_id ); + + createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() ) ); +} + + + +//======================================================================= +// function : GeometryGUI::initialize() +// purpose : Called when GEOM module is created +//======================================================================= +void GeometryGUI::initialize( CAM_Application* app ) +{ + SalomeApp_Module::initialize( app ); + + // ----- create actions -------------- + + createGeomAction( 111, "IMPORT", "", (CTRL + Key_I) ); + createGeomAction( 121, "EXPORT", "", (CTRL + Key_E) ); + + createGeomAction( 33, "DELETE" ); + + createGeomAction( 4011, "POINT" ); + createGeomAction( 4012, "LINE" ); + createGeomAction( 4013, "CIRCLE" ); + createGeomAction( 4014, "ELLIPSE" ); + createGeomAction( 4015, "ARC" ); + createGeomAction( 4019, "CURVE" ); + createGeomAction( 4016, "VECTOR" ); + createGeomAction( 4017, "PLANE" ); + createGeomAction( 4018, "WORK_PLANE" ); + createGeomAction( 4020, "LOCAL_CS" ); + + createGeomAction( 4021, "BOX" ); + createGeomAction( 4022, "CYLINDER" ); + createGeomAction( 4023, "SPHERE" ); + createGeomAction( 4024, "TORUS" ); + createGeomAction( 4025, "CONE" ); + + createGeomAction( 4031, "EXTRUSION" ); + createGeomAction( 4032, "REVOLUTION" ); + createGeomAction( 4033, "FILLING" ); + createGeomAction( 4034, "PIPE" ); + + createGeomAction( 800, "GROUP_CREATE" ); + createGeomAction( 801, "GROUP_EDIT" ); + + createGeomAction( 9997, "Q_FACE" ); + createGeomAction( 9999, "HEX_SOLID" ); + + createGeomAction( 404, "SKETCH" ); + createGeomAction( 407, "EXPLODE" ); + + createGeomAction( 4081, "EDGE" ); + createGeomAction( 4082, "WIRE" ); + createGeomAction( 4083, "FACE" ); + createGeomAction( 4084, "SHELL" ); + createGeomAction( 4085, "SOLID" ); + createGeomAction( 4086, "COMPOUND" ); + + createGeomAction( 5011, "FUSE" ); + createGeomAction( 5012, "COMMON" ); + createGeomAction( 5013, "CUT" ); + createGeomAction( 5014, "SECTION" ); + + createGeomAction( 5021, "TRANSLATION" ); + createGeomAction( 5022, "ROTATION" ); + createGeomAction( 5023, "MODIFY_LOCATION" ); + createGeomAction( 5024, "MIRROR" ); + createGeomAction( 5025, "SCALE" ); + createGeomAction( 5026, "OFFSET" ); + createGeomAction( 5027, "MUL_TRANSLATION" ); + createGeomAction( 5028, "MUL_ROTATION" ); + + createGeomAction( 503, "PARTITION" ); + createGeomAction( 504, "ARCHIMEDE" ); + createGeomAction( 505, "FILLET" ); + createGeomAction( 506, "CHAMFER" ); + //createGeomAction( 507, "CLIPPING" ); + + createGeomAction( 9998, "MUL_TRANSFORM" ); + createGeomAction( 9995, "EXPLODE_BLOCKS" ); + createGeomAction( 99991, "PROPAGATE" ); + + createGeomAction( 601, "SEWING" ); + createGeomAction( 602, "GLUE_FACES" ); + createGeomAction( 603, "SUPPRESS_FACES" ); + createGeomAction( 604, "SUPPERSS_HOLES" ); + createGeomAction( 605, "SHAPE_PROCESS" ); + createGeomAction( 606, "CLOSE_CONTOUR" ); + createGeomAction( 607, "SUPPRESS_INT_WIRES" ); + createGeomAction( 608, "POINT_ON_EDGE" ); + createGeomAction( 609, "CHECK_FREE_BNDS" ); + createGeomAction( 610, "CHECK_FREE_FACES" ); + createGeomAction( 611, "CHANGE_ORIENTATION" ); + + createGeomAction( 708, "POINT_COORDS" ); + createGeomAction( 701, "BASIC_PROPS" ); + createGeomAction( 702, "MASS_CENTER" ); + createGeomAction( 703, "INERTIA" ); + createGeomAction( 7041, "BND_BOX" ); + createGeomAction( 7042, "MIN_DIST" ); + + createGeomAction( 705, "TOLERANCE" ); + createGeomAction( 706, "WHAT_IS" ); + createGeomAction( 707, "CHECK" ); + createGeomAction( 7072, "CHECK_COMPOUND" ); + + createGeomAction( 5103, "CHECK_GEOMETRY" ); + + createGeomAction( 412, "SHADING_COLOR" ); + createGeomAction( 413, "ISOS" ); + createGeomAction( 414, "STEP_VALUE" ); + + createGeomAction( 211, "SHADING" ); + createGeomAction( 212, "DISPLAY_ALL" ); + createGeomAction( 214, "ERASE_ALL" ); + createGeomAction( 216, "DISPLAY" ); + createGeomAction( 2171, "VERTEX_SEL_ONLY" ,"", 0, true ); + createGeomAction( 2172, "EDGE_SEL_ONLY", "", 0, true ); + createGeomAction( 2173, "WIRE_SEL_ONLY", "", 0, true ); + createGeomAction( 2174, "FACE_SEL_ONLY", "", 0, true ); + createGeomAction( 2175, "SHELL_SEL_ONLY", "", 0, true ); + createGeomAction( 2176, "SOLID_SEL_ONLY", "", 0, true ); + createGeomAction( 2177, "COMPOUND_SEL_ONLY", "", 0, true ); + createGeomAction( 2178, "ALL_SEL_ONLY", "", 0, true ); + createGeomAction( 213, "DISPLAY_ONLY" ); + createGeomAction( 215, "ERASE" ); + + createGeomAction( 901, "POP_RENAME" ); + createGeomAction( 80311, "POP_WIREFRAME", "", 0, true ); + createGeomAction( 80312, "POP_SHADING", "", 0, true ); + createGeomAction( 8032, "POP_COLOR" ); + createGeomAction( 8033, "POP_TRANSPARENCY" ); + createGeomAction( 8034, "POP_ISOS" ); + createGeomAction( 8001, "POP_CREATE_GROUP" ); + + // make wireframe-shading items to be exclusive (only one at a time is selected) + //QActionGroup* dispModeGr = new QActionGroup( this, "", true ); + //dispModeGr->add( action( 80311 ) ); + //dispModeGr->add( action( 80312 ) ); + // ---- create menu -------------------------- + + int fileId = createMenu( tr( "MEN_FILE" ), -1, -1 ); + createMenu( separator(), fileId, 10 ); + createMenu( 111, fileId, 10 ); + createMenu( 121, fileId, 10 ); + createMenu( separator(), fileId, -1 ); + + int editId = createMenu( tr( "MEN_EDIT" ), -1, -1 ); + createMenu( 33, editId, -1 ); + + int newEntId = createMenu( tr( "MEN_NEW_ENTITY" ), -1, -1, 10 ); + + int basicId = createMenu( tr( "MEN_BASIC" ), newEntId, -1 ); + createMenu( 4011, basicId, -1 ); + createMenu( 4012, basicId, -1 ); + createMenu( 4013, basicId, -1 ); + createMenu( 4014, basicId, -1 ); + createMenu( 4015, basicId, -1 ); + createMenu( 4019, basicId, -1 ); + createMenu( separator(), basicId, -1 ); + createMenu( 4016, basicId, -1 ); + createMenu( 4017, basicId, -1 ); + createMenu( 4018, basicId, -1 ); + createMenu( 4020, basicId, -1 ); + + int primId = createMenu( tr( "MEN_PRIMITIVES" ), newEntId, -1 ); + createMenu( 4021, primId, -1 ); + createMenu( 4022, primId, -1 ); + createMenu( 4023, primId, -1 ); + createMenu( 4024, primId, -1 ); + createMenu( 4025, primId, -1 ); + + int genId = createMenu( tr( "MEN_GENERATION" ), newEntId, -1 ); + createMenu( 4031, genId, -1 ); + createMenu( 4032, genId, -1 ); + createMenu( 4033, genId, -1 ); + createMenu( 4034, genId, -1 ); + createMenu( separator(), newEntId, -1 ); + + int groupId = createMenu( tr( "MEN_GROUP" ), newEntId, -1 ); + createMenu( 800, groupId, -1 ); + createMenu( 801, groupId, -1 ); + createMenu( separator(), newEntId, -1 ); + + int blocksId = createMenu( tr( "MEN_BLOCKS" ), newEntId, -1 ); + createMenu( 9997, blocksId, -1 ); + createMenu( 9999, blocksId, -1 ); + + createMenu( separator(), newEntId, -1 ); + createMenu( 404, newEntId, -1 ); + createMenu( separator(), newEntId, -1 ); + createMenu( 407, newEntId, -1 ); + + int buildId = createMenu( tr( "MEN_BUILD" ), newEntId, -1 ); + createMenu( 4081, buildId, -1 ); + createMenu( 4082, buildId, -1 ); + createMenu( 4083, buildId, -1 ); + createMenu( 4084, buildId, -1 ); + createMenu( 4085, buildId, -1 ); + createMenu( 4086, buildId, -1 ); + + int operId = createMenu( tr( "MEN_OPERATIONS" ), -1, -1, 10 ); + + int boolId = createMenu( tr( "MEN_BOOLEAN" ), operId, -1 ); + createMenu( 5011, boolId, -1 ); + createMenu( 5012, boolId, -1 ); + createMenu( 5013, boolId, -1 ); + createMenu( 5014, boolId, -1 ); + + int transId = createMenu( tr( "MEN_TRANSFORMATION" ), operId, -1 ); + createMenu( 5021, transId, -1 ); + createMenu( 5022, transId, -1 ); + createMenu( 5023, transId, -1 ); + createMenu( 5024, transId, -1 ); + createMenu( 5025, transId, -1 ); + createMenu( 5026, transId, -1 ); + createMenu( separator(), transId, -1 ); + createMenu( 5027, transId, -1 ); + createMenu( 5028, transId, -1 ); + + createMenu( 503, operId, -1 ); + createMenu( 504, operId, -1 ); + createMenu( separator(), operId, -1 ); + createMenu( 505, transId, -1 ); + createMenu( 506, transId, -1 ); + //createMenu( 507, transId, -1 ); + + int blockId = createMenu( tr( "MEN_BLOCKS" ), operId, -1 ); + createMenu( 9998, blockId, -1 ); + createMenu( 9995, blockId, -1 ); + createMenu( 99991, blockId, -1 ); + + int repairId = createMenu( tr( "MEN_REPAIR" ), -1, -1, 10 ); + createMenu( 605, repairId, -1 ); + createMenu( 603, repairId, -1 ); + createMenu( 606, repairId, -1 ); + createMenu( 607, repairId, -1 ); + createMenu( 604, repairId, -1 ); + createMenu( 601, repairId, -1 ); + createMenu( 602, repairId, -1 ); + createMenu( 608, repairId, -1 ); + createMenu( 609, repairId, -1 ); + createMenu( 610, repairId, -1 ); + createMenu( 611, repairId, -1 ); + + int measurId = createMenu( tr( "MEN_MEASURES" ), -1, -1, 10 ); + createMenu( 708, measurId, -1 ); + createMenu( 701, measurId, -1 ); + createMenu( separator(), measurId, -1 ); + createMenu( 702, measurId, -1 ); + createMenu( 703, measurId, -1 ); + createMenu( separator(), measurId, -1 ); + + int dimId = createMenu( tr( "MEN_DIMENSIONS" ), measurId, -1 ); + createMenu( 7041, dimId, -1 ); + createMenu( 7042, dimId, -1 ); + createMenu( separator(), measurId, -1 ); + + createMenu( 705, measurId, -1 ); + createMenu( separator(), measurId, -1 ); + createMenu( 706, measurId, -1 ); + createMenu( 707, measurId, -1 ); + createMenu( 7072, measurId, -1 ); + + int toolsId = createMenu( tr( "MEN_TOOLS" ), -1, -1, 50 ); + createMenu( separator(), toolsId, -1 ); + createMenu( 5103, toolsId, -1 ); + + //int prefId = createMenu( tr( "MEN_PREFERENCES" ), -1, -1, 50 ); + //createMenu( separator(), prefId, -1 ); + //int geomId = createMenu( tr( "MEN_PREFERENCES_GEOM" ), prefId, -1 ); + //createMenu( 412, geomId, -1 ); + //createMenu( 413, geomId, -1 ); + //createMenu( 414, geomId, -1 ); + //createMenu( separator(), prefId, -1 ); + + int viewId = createMenu( tr( "MEN_VIEW" ), -1, -1 ); + createMenu( separator(), viewId, -1 ); + + int dispmodeId = createMenu( tr( "MEN_DISPLAY_MODE" ), viewId, -1 ); + createMenu( 211, dispmodeId, -1 ); + + createMenu( separator(), viewId, -1 ); + createMenu( 212, viewId, -1 ); + createMenu( 214, viewId, -1 ); + createMenu( separator(), viewId, -1 ); + +/* + PAL9111: + because of these items are accessible through object browser and viewers + we have removed they from main menu + + createMenu( 216, viewId, -1 ); + createMenu( 213, viewId, -1 ); + createMenu( 215, viewId, -1 ); +*/ + + // ---- create toolbars -------------------------- + + int basicTbId = createTool( tr( "TOOL_BASIC" ) ); + createTool( 4011, basicTbId ); + createTool( 4012, basicTbId ); + createTool( 4013, basicTbId ); + createTool( 4014, basicTbId ); + createTool( 4015, basicTbId ); + createTool( 4019, basicTbId ); + createTool( 4016, basicTbId ); + createTool( 4017, basicTbId ); + createTool( 4018, basicTbId ); + createTool( 4020, basicTbId ); + + int primTbId = createTool( tr( "TOOL_PRIMITIVES" ) ); + createTool( 4021, primTbId ); + createTool( 4022, primTbId ); + createTool( 4023, primTbId ); + createTool( 4024, primTbId ); + createTool( 4025, primTbId ); + + int boolTbId = createTool( tr( "TOOL_BOOLEAN" ) ); + createTool( 5011, boolTbId ); + createTool( 5012, boolTbId ); + createTool( 5013, boolTbId ); + createTool( 5014, boolTbId ); + + int genTbId = createTool( tr( "TOOL_GENERATION" ) ); + createTool( 4031, genTbId ); + createTool( 4032, genTbId ); + createTool( 4033, genTbId ); + createTool( 4034, genTbId ); + + int transTbId = createTool( tr( "TOOL_TRANSFORMATION" ) ); + createTool( 5021, transTbId ); + createTool( 5022, transTbId ); + createTool( 5023, transTbId ); + createTool( 5024, transTbId ); + createTool( 5025, transTbId ); + createTool( 5026, transTbId ); + createTool( separator(), transTbId ); + createTool( 5027, transTbId ); + createTool( 5028, transTbId ); + + // ---- create popup menus -------------------------- + + QString clientOCCorVTK = "(client='OCCViewer' or client='VTKViewer')"; + QString clientOCCorVTK_AndSomeVisible = clientOCCorVTK + " and selcount>0 and isVisible"; + + QtxPopupMgr* mgr = popupMgr(); + mgr->insert( action( 901 ), -1, -1 ); // rename + mgr->setRule( action( 901 ), "$type in {'Shape' 'Group'} and selcount=1", true ); + mgr->insert( action( 8001 ), -1, -1 ); // create group + mgr->setRule( action( 8001 ), "client='ObjectBrowser' and type='Shape' and selcount=1 and isOCC=true", true ); + mgr->insert( action( 801 ), -1, -1 ); // edit group + mgr->setRule( action( 801 ), "client='ObjectBrowser' and type='Group' and selcount=1 and isOCC=true", true ); + mgr->insert( separator(), -1, -1 ); // ----------- + dispmodeId = mgr->insert( tr( "MEN_DISPLAY_MODE" ), -1, -1 ); // display mode menu + mgr->insert( action( 80311 ), dispmodeId, -1 ); // wireframe + mgr->setRule( action( 80311 ), clientOCCorVTK_AndSomeVisible, true ); + mgr->setRule( action( 80311 ), clientOCCorVTK + " and displaymode='Wireframe'", false ); + mgr->insert( action( 80312 ), dispmodeId, -1 ); // shading + mgr->setRule( action( 80312 ), clientOCCorVTK_AndSomeVisible, true ); + mgr->setRule( action( 80312 ), clientOCCorVTK + " and displaymode='Shading'", false ); + mgr->insert( separator(), -1, -1 ); // ----------- + mgr->insert( action( 8032 ), -1, -1 ); // color + mgr->setRule( action( 8032 ), clientOCCorVTK_AndSomeVisible + " and ($component={'GEOM'})", true ); + mgr->insert( action( 8033 ), -1, -1 ); // transparency + mgr->setRule( action( 8033 ), clientOCCorVTK_AndSomeVisible, true ); + mgr->insert( action( 8034 ), -1, -1 ); // isos + mgr->setRule( action( 8034 ), "client='OCCViewer' and selcount>0 and isVisible", true ); + mgr->insert( separator(), -1, -1 ); // ----------- + + + QString canDisplay = "($component={'GEOM'}) and (selcount>0) and ({true} in $canBeDisplayed) ", + onlyComponent = "((type='Component') and selcount=1)", + rule = canDisplay + "and ((($type in {%1}) and( %2 )) or " + onlyComponent + ")", + types = "'Shape' 'Group'"; + + mgr->insert( action( 216 ), -1, -1 ); // display + mgr->setRule( action( 216 ), rule.arg( types ).arg( "not isVisible" ), true ); + + mgr->insert( action( 215 ), -1, -1 ); // erase + mgr->setRule( action( 215 ), rule.arg( types ).arg( "isVisible" ), true ); + + mgr->insert( action( 214 ), -1, -1 ); // erase All + mgr->setRule( action( 214 ), clientOCCorVTK, true ); + + QString selectOnly = "(client='OCCViewer' or client='VTKViewer') and (selcount=0)"; + + int selectolnyId = mgr->insert( tr("MEN_SELECT_ONLY"), -1, -1); //select only menu + mgr->insert( action(2171), selectolnyId, -1); //Vertex + mgr->setRule(action(2171), selectOnly, true); + mgr->setRule(action(2171), selectOnly + " and selectionmode='VERTEX'", false); + mgr->insert( action(2172), selectolnyId, -1); //Edge + mgr->setRule(action(2172), selectOnly, true); + mgr->setRule(action(2172), selectOnly + " and selectionmode='EDGE'", false); + mgr->insert( action(2173), selectolnyId, -1); //Wire + mgr->setRule(action(2173), selectOnly, true); + mgr->setRule(action(2173), selectOnly + " and selectionmode='WIRE'", false); + mgr->insert( action(2174), selectolnyId, -1); //Face + mgr->setRule(action(2174), selectOnly, true); + mgr->setRule(action(2174), selectOnly + " and selectionmode='FACE'", false); + mgr->insert( action(2175), selectolnyId, -1); //Shell + mgr->setRule(action(2175), selectOnly, true); + mgr->setRule(action(2175), selectOnly + " and selectionmode='SHELL'", false); + mgr->insert( action(2176), selectolnyId, -1); //Solid + mgr->setRule(action(2176), selectOnly, true); + mgr->setRule(action(2176), selectOnly + " and selectionmode='SOLID'", false); + mgr->insert( action(2177), selectolnyId, -1); //Compound + mgr->setRule(action(2177), selectOnly, true); + mgr->setRule(action(2177), selectOnly + " and selectionmode='COMPOUND'", false); + mgr->insert( separator(), selectolnyId, -1); + mgr->insert( action(2178), selectolnyId, -1); //Clear selection filter + mgr->setRule(action(2178), selectOnly, true); + mgr->setRule(action(2178), selectOnly + " and selectionmode='ALL'", false); + + mgr->insert( action( 213 ), -1, -1 ); // display only + mgr->setRule( action( 213 ), rule.arg( types ).arg( "true" ), true ); + mgr->insert( separator(), -1, -1 ); + + mgr->hide( mgr->actionId( action( myEraseAll ) ) ); +} + +//======================================================================= +// function : GeometryGUI::activateModule() +// purpose : Called when GEOM module is activated +//======================================================================= +bool GeometryGUI::activateModule( SUIT_Study* study ) +{ + if ( CORBA::is_nil( myComponentGeom ) ) + return false; + bool res = SalomeApp_Module::activateModule( study ); -//======================================================================= -// function : OnSketchSegment() -// purpose : -//======================================================================= -void GeometryGUI::OnSketchSegment() -{ - this->mySketcher.ChangeMode(SEGMENT); -} + if ( !res ) + return false; + setMenuShown( true ); + setToolShown( true ); + + connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ), + this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) ); + + // Reset actions accelerator keys + //action(111)->setAccel(QKeySequence(CTRL + Key_I)); // Import + //action(121)->setAccel(QKeySequence(CTRL + Key_E)); // Export + action(111)->setEnabled(true); // Import + action(121)->setEnabled(true); // Export + + GUIMap::Iterator it; + for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it ) + it.data()->activate( application()->desktop() ); + + LightApp_SelectionMgr* sm = getApp()->selectionMgr(); + SUIT_ViewManager* vm; + ViewManagerList OCCViewManagers, VTKViewManagers; + application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers ); + for ( vm = OCCViewManagers.first(); vm; vm = OCCViewManagers.next() ) + myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) ); + application()->viewManagers( SVTK_Viewer::Type(), VTKViewManagers ); + for ( vm = VTKViewManagers.first(); vm; vm = VTKViewManagers.next() ) + myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast( vm->getViewModel() ), sm ) ); + + // disable OCC selectors + getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() ); + for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() ) + sr->setEnabled(true); + + // disable VTK selectors + getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() ); + for ( LightApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() ) + sr->setEnabled(true); -//======================================================================= -// function : OnSketchArc() -// purpose : -//======================================================================= -void GeometryGUI::OnSketchArc() -{ - this->mySketcher.ChangeMode(ARC_CHORD); + return true; } + //======================================================================= -// function : OnSketchSetAngle() -// purpose : +// function : GeometryGUI::deactivateModule() +// purpose : Called when GEOM module is deactivated //======================================================================= -void GeometryGUI::OnSketchSetAngle() +bool GeometryGUI::deactivateModule( SUIT_Study* study ) { - Standard_Real anAngle = this->mySketcher.GetSegmentAngle()/PI180; - Sketch::fitInResol(anAngle); - Standard_Boolean res = false ; - QString Value = QString("%1").arg( anAngle ); - anAngle = Parameter(res, Value, tr("GEOM_MEN_ANGLE"), tr("GEOM_MEN_ENTER_ANGLE"), -180.0, +180.0, 6 )*PI180 ; - - if( res ) { - this->mySketcher.SetSegmentAngle(anAngle); - QMenuBar* Mb = this->myDesktop->getMainMenuBar(); - QMenuData* pp; - QMenuItem* item = Mb->findItem(3133,&pp); - pp->setItemChecked(3133,false); - item = Mb->findItem(3134,&pp); - pp->setItemChecked(3134,false); - } - -} + setMenuShown( false ); + setToolShown( false ); + disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ), + this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) ); -//======================================================================= -// function : OnSketchSetx() -// purpose : -//======================================================================= -void GeometryGUI::OnSketchSetx() -{ - Standard_Boolean res = false; - double X = Parameter( res, - "0.", - tr("GEOM_MEN_X"), - tr("GEOM_MEN_SKETCHER_X"), - 2.0 * Precision::Confusion(), - 1E6, - 6 ) ; - if (res) - this->mySketcher.SetXDimension(X); - QMenuBar* Mb = this->myDesktop->getMainMenuBar(); - QMenuData* pp; - QMenuItem* item = Mb->findItem(3133,&pp); - pp->setItemChecked(3133,false); - item = Mb->findItem(3134,&pp); - pp->setItemChecked(3134,false); + EmitSignalCloseAllDialogs(); + + GUIMap::Iterator it; + for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it ) + it.data()->deactivate(); + + // Unset actions accelerator keys + //action(111)->setAccel(QKeySequence()); // Import + //action(121)->setAccel(QKeySequence()); // Export + action(111)->setEnabled(false); // Import + action(121)->setEnabled(false); // Export + + myOCCSelectors.clear(); + getApp()->selectionMgr()->setEnabled( true, OCCViewer_Viewer::Type() ); + + myVTKSelectors.clear(); + getApp()->selectionMgr()->setEnabled( true, SVTK_Viewer::Type() ); + + return SalomeApp_Module::deactivateModule( study ); } -//======================================================================= -// function : OnSketchSety() -// purpose : -//======================================================================= -void GeometryGUI::OnSketchSety() +//================================================================================= +// function : GeometryGUI::DefinePopup() +// purpose : Called from desktop to define popup menu [static] +//================================================================================= +/* +void GeometryGUI::DefinePopup(QString& theContext, QString& theParent, QString& theObject) { - Standard_Boolean res = false; - double Y = Parameter( res, - "0.", - tr("GEOM_MEN_Y"), - tr("GEOM_MEN_SKETCHER_Y"), - 2.0 * Precision::Confusion(), - 1E6, - 6 ) ; - if (res) - this->mySketcher.SetYDimension(Y); - QMenuBar* Mb = this->myDesktop->getMainMenuBar(); - QMenuData* pp; - QMenuItem* item = Mb->findItem(3133,&pp); - pp->setItemChecked(3133,false); - item = Mb->findItem(3134,&pp); - pp->setItemChecked(3134,false); -} + QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy(); + SALOME_Selection* Sel = SALOME_Selection::Selection(ActiveStudy->getSelection()); + theObject = ""; + theContext = ""; -//======================================================================= -// function : OnSketchDelete() -// purpose : -//======================================================================= -void GeometryGUI::OnSketchDelete() -{ - if (GeomGUI->mySketcher.GetmyEdgesNumber() == 1 ) { - QMenuBar* Mb = GeomGUI->myDesktop->getMainMenuBar(); - QMenuData* pp; - QMenuItem* item = Mb->findItem(313,&pp); - pp->setItemEnabled( 313, false); // SKETCH CONTRAINTS - GeomGUI->mySketcher.SetTransitionStatus(NOCONSTRAINT); + if ( theParent == "Viewer" ) { + if ( Sel->IObjectCount() == 0 ) + theContext = "NothingSelected"; } - if (this->mySketcher.Delete()) - GeomGUI->ResetState(); + if ( Sel->IObjectCount() == 1 ) { + Handle(SALOME_InteractiveObject) IO = Sel->firstIObject(); + if( IO->hasEntry() ) { + SALOMEDS::SObject_var sobj = ActiveStudy->getStudyDocument()->FindObjectID( IO->getEntry() ); + if ( !sobj->_is_nil() ) { + SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent(); + if ( !strcmp(scomp->GetID(), IO->getEntry() ) ) { + // component is selected + theObject = "Component"; + } + else { + GEOM::GEOM_Object_var aGObj = GEOM::GEOM_Object::_narrow( sobj->GetObject() ); + if ( !CORBA::is_nil( aGObj ) ) { + switch( aGObj->GetType() ) { + case GEOM_GROUP: + theObject = "Group"; + break; + default: + theObject = "Shape"; + break; + } + } + } + } + } + } } +//================================================================================= +// function : GeometryGUI::CustomPopup() +// purpose : Called from desktop to create popup menu [static] +//================================================================================= +bool GeometryGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext, + const QString& theParent, const QString& theObject) +{ + GeometryGUI* geomGUI = GetGeomGUI(); + + // Deactivate any non modal dialog box to get the neutral point + geomGUI->EmitSignalDeactivateDialog(); + QAD_Study* anActiveStudy = parent->getActiveStudy(); + QAD_StudyFrame* aStudyFrame = anActiveStudy->getActiveStudyFrame(); + QAD_ViewFrame* aViewFrame = aStudyFrame->getRightFrame()->getViewFrame(); + SALOME_Selection* Sel = SALOME_Selection::Selection(anActiveStudy->getSelection()); + QString parentComponent = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection(); + bool isOCCViewer = aViewFrame->getTypeView() == VIEW_OCC; + bool isVTKViewer = aViewFrame->getTypeView() == VIEW_VTK; + int aDisplayMode = 0; + QString objectName; + + if ( aViewFrame->getTypeView() == VIEW_OCC ) + aDisplayMode = ((OCCViewer_ViewFrame*)aViewFrame)->getViewer()->getAISContext()->DisplayMode(); + else if ( aViewFrame->getTypeView() == VIEW_VTK ) + aDisplayMode = (dynamic_cast( aViewFrame )->getRWInteractor()->GetDisplayMode(); -//======================================================================= -// function : OnSketchClose() -// purpose : -//======================================================================= -void GeometryGUI::OnSketchClose() -{ - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)this->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) myContext = v3d->getAISContext(); - - TopoDS_Wire W = this->mySketcher.Close(); - if ( !W.IsNull() ) { - // - GEOM::GEOM_Gen::ListOfIOR_var listShapes = new GEOM::GEOM_Gen::ListOfIOR; - listShapes->length(0); - unsigned int i = 0; - - BRepTools_WireExplorer Ex(W); - while ( Ex.More() ) { - TopoDS_Edge E = Ex.Current(); - gp_Pnt pt1 , pt2 ; - - pt1 = BRep_Tool::Pnt(TopExp::FirstVertex(E)); - pt2 = BRep_Tool::Pnt(TopExp::LastVertex(E)); - - gp_Pnt CenterPoint; - Handle(Geom_Curve) Curve; - Handle(Geom_Circle) Circle; - gp_Circ Circ; - Standard_Real First,Last; - - Curve = BRep_Tool::Curve(E,First,Last); - if(Curve->IsKind(STANDARD_TYPE(Geom_Circle))) { - Circle = Handle(Geom_Circle)::DownCast(Curve); // pointer on geom_circ - Circ = Circle->Circ(); // gp_Circ - - Curve->D0( (First + Last) / 2. , CenterPoint ); - - GEOM::PointStruct pI = myComponentGeom->MakePointStruct( pt1.X(), pt1.Y(), pt1.Z() ); - GEOM::PointStruct pC = myComponentGeom->MakePointStruct( CenterPoint.X(), CenterPoint.Y(), CenterPoint.Z() ); - GEOM::PointStruct pE = myComponentGeom->MakePointStruct( pt2.X(), pt2.Y(), pt2.Z() ); - - GEOM::GEOM_Shape_var arc; - - try { - arc = myComponentGeom->MakeArc(pI, pC, pE) ; - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); + int nbSel = Sel->IObjectCount(); + + if( nbSel == 0 ) { + ////// NOTHING SELECTED + popup->clear(); + } + else if ( nbSel == 1 ) { + ////// SINGLE OBJECT SELECTION + if ( parentComponent != parent->getActiveComponent() ) { + ////// selected object does not belong to GEOM module: + // remove all commands except Display/Erase... + while ( 1 ) { + int id = popup->idAt( 0 ); + if ( id <= QAD_TopLabel_Popup_ID ) + popup->removeItemAt( 0 ); + else + break; + } + } + else { + ////// selected object belong to the GEOM module + // get interactive object + Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject(); + objectName = IObject->getName(); + // if object has entry get SObject + SALOMEDS::SObject_var SO; + if ( IObject->hasEntry() ) + SO = anActiveStudy->getStudyDocument()->FindObjectID( IObject->getEntry() ); + + if ( theObject == "Component" ) { + ////// menu for component + if ( !isOCCViewer && !isVTKViewer ) { + popup->removeItem( QAD_DisplayOnly_Popup_ID ); + popup->removeItem( QAD_Display_Popup_ID ); + popup->removeItem( QAD_Erase_Popup_ID ); } + } + else { + ////// not component (should be shape) + if ( IObject->hasEntry() ) /////// VSR : TO BE REMOVED + popup->removeItem( 804 ); // "Add in Study" - listShapes->length(i+1); - listShapes[i] = strdup(arc->Name()); - i++; - } else { - GEOM::PointStruct pI = myComponentGeom->MakePointStruct( pt1.X(), pt1.Y(), pt1.Z() ); - GEOM::PointStruct pE = myComponentGeom->MakePointStruct( pt2.X(), pt2.Y(), pt2.Z() ); - GEOM::GEOM_Shape_var segment; - - try { - segment = myComponentGeom->MakeEdge(pI,pE) ; - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); + // Here could be analysis of the geom shape's type + // ... // + + SALOMEDS::GenericAttribute_var aTmpAttr; + if( SO->_is_nil() || SO->GetFatherComponent()->FindAttribute( aTmpAttr, "AttributeIOR") ) + popup->removeItem( 9024 ); // "Open" /////// VSR : TO BE REMOVED + + if ( !isOCCViewer && theParent == "ObjectBrowser" ) { + if ( theObject == "Shape" ) + popup->removeItem( 800 ); // Create Group + else if ( theObject == "Group" ) + popup->removeItem( 801 ); // Edit Group } - listShapes->length(i+1); - listShapes[i] = strdup(segment->Name()); - i++; + if ( isOCCViewer || isVTKViewer ) { + ////// current viewer is OCC or VTK + SALOME_Prs* prs = aViewFrame->CreatePrs( IObject->getEntry() ); + if ( aViewFrame->isVisible( IObject ) ) { + ////// object is already displayed in the viewer + popup->removeItem( QAD_Display_Popup_ID ); + if ( isOCCViewer ) { + ////// OCC viewer only + OCCViewer_Prs* occPrs = dynamic_cast( prs ); + if ( occPrs && !occPrs->IsNull() ) { + AIS_ListOfInteractive ioList; + occPrs->GetObjects( ioList ); + QMenuItem* mi = popup->findItem( 803 ); + if ( mi && mi->popup() ) { + if ( ioList.First()->DisplayMode() == 0 ) + mi->popup()->setItemChecked( 80311, true ); // "Wireframe" + else if ( ioList.First()->DisplayMode() == 1 ) + mi->popup()->setItemChecked( 80312, true ); // "Shading" + else if ( ioList.First()->DisplayMode() < 0 ) + mi->popup()->setItemChecked( aDisplayMode == 0 ? 80311 : 80312 , true ); // "Wireframe" or "Shading" + } + } + } + else { + ////// VTK viewer only + popup->removeItem( 8034 ); // "Isos" + SVTK_Prs* vtkPrs = dynamic_cast( prs ); + if ( vtkPrs && !vtkPrs->IsNull() ) { + vtkActorCollection* actorList = vtkPrs->GetObjects(); + actorList->InitTraversal(); + SALOME_Actor* ac = SALOME_Actor::SafeDownCast( actorList->GetNextActor() ); + QMenuItem* mi = popup->findItem( 803 ); + if ( ac && mi && mi->popup() ) { + if ( ac->getDisplayMode() == 0 ) + mi->popup()->setItemChecked( 80311, true ); // "Wireframe" + else if ( ac->getDisplayMode() == 1 ) + mi->popup()->setItemChecked( 80312, true ); // "Shading" + else + mi->popup()->setItemChecked( aDisplayMode == 0 ? 80311 : 80312 , true ); // "Wireframe" or "Shading" + } + } + } + } + else { + ////// object is not yet displayed in the viewer + popup->removeItem( 803 ); // "Display Mode" + popup->removeItem( 8032 ); // "Color" + popup->removeItem( 8033 ); // "Transparency" + popup->removeItem( 8034 ); // "Isos" + popup->removeItem( QAD_Erase_Popup_ID ); + } + delete prs; + } + else { + ////// other viewer type (neither OCC nor VTK) + popup->removeItem( 803 ); // "Display Mode" + popup->removeItem( 8032 ); // "Color" + popup->removeItem( 8033 ); // "Transparency" + popup->removeItem( 8034 ); // "Isos" + popup->removeItem( QAD_Display_Popup_ID ); + popup->removeItem( QAD_DisplayOnly_Popup_ID ); + popup->removeItem( QAD_Erase_Popup_ID ); + } } - Ex.Next(); } - GEOM::GEOM_Shape_var Wire = myComponentGeom->MakeWire(listShapes) ; - TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, Wire); - Standard_CString type; - GetShapeTypeString(S,type); - Wire->NameType( type ); - - if ( Display(Wire, "" )) { - QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE")); - } } - GeomGUI->ResetState(); - QMenuBar* Mb = this->myDesktop->getMainMenuBar(); - QMenuData* pp; - QMenuItem* item = Mb->findItem(313,&pp); - pp->setItemEnabled( 313, false); // SKETCH CONTRAINTS - GeomGUI->mySketcher.SetTransitionStatus(NOCONSTRAINT); -} + else { + ////// MULTIPLE SELECTION + if ( parentComponent != parent->getActiveComponent() ) { + ////// not GEOM module objects or objects belong to different modules + // remove all commands except Display/Erase... + while ( 1 ) { + int id = popup->idAt( 0 ); + if ( id <= QAD_TopLabel_Popup_ID ) + popup->removeItemAt( 0 ); + else + break; + } + if ( parentComponent.isNull() ) { + ////// objects belong to different modules + popup->removeItem(QAD_Display_Popup_ID); + popup->removeItem(QAD_DisplayOnly_Popup_ID); + popup->removeItem(QAD_Erase_Popup_ID); + } + else { + objectName = tr( "GEOM_MEN_POPUP_NAME" ).arg( nbSel ); + } + } + else { + ////// all selected objects belong to GEOM module + popup->removeItem( 901 ); // "Rename" + SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() ); + bool isComponent = false; + bool needOpen = false; + bool needDisplay = false; + bool needErase = false; + int needToPublish = 0; + for( ;It.More();It.Next() ) { + Handle(SALOME_InteractiveObject) anIObject = It.Value(); -//======================================================================= -// function : OnSketchEnd() -// purpose : -//======================================================================= -void GeometryGUI::OnSketchEnd() -{ - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)this->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) myContext = v3d->getAISContext(); - - TopoDS_Wire W = this->mySketcher.End(); - if (!W.IsNull()) { - // - GEOM::GEOM_Gen::ListOfIOR_var listShapes = new GEOM::GEOM_Gen::ListOfIOR; - listShapes->length(0); - unsigned int i = 0; - - BRepTools_WireExplorer Ex(W); - while ( Ex.More() ) { - TopoDS_Edge E = TopoDS::Edge( Ex.Current() ); - - gp_Pnt pt1 , pt2 ; - pt1 = BRep_Tool::Pnt(TopExp::FirstVertex(E)); - pt2 = BRep_Tool::Pnt(TopExp::LastVertex(E)); - - gp_Pnt CenterPoint; - Handle(Geom_Curve) Curve; - Handle(Geom_Circle) Circle; - gp_Circ Circ; - Standard_Real First,Last; - - Curve = BRep_Tool::Curve(E,First,Last); - if(Curve->IsKind(STANDARD_TYPE(Geom_Circle))) { - Circle = Handle(Geom_Circle)::DownCast(Curve); // pointer on geom_circ - Circ = Circle->Circ(); // gp_Circ - - Curve->D0( (First + Last) / 2. , CenterPoint ); - - GEOM::PointStruct pI = myComponentGeom->MakePointStruct( pt1.X(), pt1.Y(), pt1.Z() ); - GEOM::PointStruct pC = myComponentGeom->MakePointStruct( CenterPoint.X(), CenterPoint.Y(), CenterPoint.Z() ); - GEOM::PointStruct pE = myComponentGeom->MakePointStruct( pt2.X(), pt2.Y(), pt2.Z() ); - - GEOM::GEOM_Shape_var arc; - - try { - arc = myComponentGeom->MakeArc(pI, pC, pE) ; - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); + if ( aViewFrame->isVisible( anIObject ) ) + needErase = true; + else + needDisplay = true; + + if( anIObject->hasEntry() ) { + needToPublish = -1; /////// VSR : TO BE REMOVED + SALOMEDS::SObject_var obj = anActiveStudy->getStudyDocument()->FindObjectID( anIObject->getEntry() ); + SALOMEDS::GenericAttribute_var aTmpAttr; + if ( !obj->_is_nil() && !obj->GetFatherComponent()->FindAttribute( aTmpAttr, "AttributeIOR" ) ) + needOpen = true; /////// VSR : TO BE REMOVED + if ( !obj->_is_nil() && QString( obj->GetID() ) == QString( obj->GetFatherComponent()->GetID() ) ) + isComponent = true; } - - listShapes->length(i+1); - listShapes[i] = strdup(arc->Name()); - i++; - } else { - GEOM::PointStruct pI = myComponentGeom->MakePointStruct( pt1.X(), pt1.Y(), pt1.Z() ); - GEOM::PointStruct pE = myComponentGeom->MakePointStruct( pt2.X(), pt2.Y(), pt2.Z() ); - GEOM::GEOM_Shape_var segment; - - try { - segment = myComponentGeom->MakeEdge(pI,pE) ; + else { + if ( needToPublish != -1 ) needToPublish = 1; } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); + } + if( needOpen || ( !isOCCViewer && !isVTKViewer ) ) { + ////// Data is not loaded yet or current viewer is neither OCC nor VTK + popup->removeItem( 803 ); // "Display Mode" + popup->removeItem( 8032 ); // "Color" + popup->removeItem( 8033 ); // "Transparency" + popup->removeItem( 8034 ); // "Isos" + popup->removeItem( 804 ); // "Add in Study" + popup->removeItem( QAD_DisplayOnly_Popup_ID ); + popup->removeItem( QAD_Display_Popup_ID ); + popup->removeItem( QAD_Erase_Popup_ID ); + } + else { + popup->removeItem( 9024 ); // "Open" + if ( needToPublish <= 0 ) + popup->removeItem( 804 ); // "Add in Study" + + if( isComponent ) { + popup->removeItem( 803 ); // "Display Mode" + popup->removeItem( 8032 ); // "Color" + popup->removeItem( 8033 ); // "Transparency" + popup->removeItem( 8034 ); // "Isos" + popup->removeItem( QAD_DisplayOnly_Popup_ID ); } - - listShapes->length(i+1); - listShapes[i] = strdup(segment->Name()); - i++; + + if ( !needDisplay ) + popup->removeItem( QAD_Display_Popup_ID ); + if ( !needErase ) + popup->removeItem( QAD_Erase_Popup_ID ); + if ( !isOCCViewer ) + popup->removeItem( 8034 ); // "Isos" } - Ex.Next(); } + } - GEOM::GEOM_Shape_var Wire = myComponentGeom->MakeWire(listShapes) ; - TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, Wire); - Standard_CString type; - GetShapeTypeString(S,type); - Wire->NameType( type ); - - if ( Display(Wire, "") ) { - QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE")); + // check popup for unnecessary separators + QAD_Tools::checkPopup( popup ); + // find popup menu's TopLabel item (with title) + int topItem = popup->indexOf( QAD_TopLabel_Popup_ID ); + if ( topItem >= 0 ) { + // remove popup menu's title item + popup->removeItem( QAD_TopLabel_Popup_ID ); + if ( theParent == "Viewer" && !objectName.isEmpty() && popup->count() > 0 ) { + // set bold font for popup menu's title + QFont f = popup->font(); f.setBold( TRUE ); + popup->removeItem( QAD_TopLabel_Popup_ID ); + popup->insertItem( new CustomItem( objectName, f ), QAD_TopLabel_Popup_ID, topItem ); } } - GeomGUI->ResetState(); - QMenuBar* Mb = this->myDesktop->getMainMenuBar(); - QMenuData* pp; - QMenuItem* item = Mb->findItem(313,&pp); - pp->setItemEnabled( 313, false); // SKETCH CONTRAINTS - GeomGUI->mySketcher.SetTransitionStatus(NOCONSTRAINT); -} -//======================================================================= -// function : OnSettingsNoconstraint() -// purpose : -//======================================================================= -void GeometryGUI::OnSettingsNoconstraint() -{ - this->mySketcher.SetTransitionStatus(NOCONSTRAINT); + return false; } -//======================================================================= -// function : OnSettingsPerpendicular() -// purpose : -//======================================================================= -void GeometryGUI::OnSettingsPerpendicular() -{ - this->mySketcher.SetTransitionStatus(PERPENDICULAR); -} +*/ //======================================================================= -// function : OnSettingsTangent() -// purpose : +// function : GeometryGUI::BuildPresentation() +// purpose : //======================================================================= -void GeometryGUI::OnSettingsTangent() +void GeometryGUI::BuildPresentation( const Handle(SALOME_InteractiveObject)& io, SUIT_ViewWindow* win ) { - this->mySketcher.SetTransitionStatus(TANGENT); + //GEOM_Displayer().Display( io, false, win ); } //======================================================================= -// function : OnSketchOptionsOnoffangledimension() -// purpose : +// function : onWindowActivated() +// purpose : update menu items' status - disable non-OCC-viewer-compatible actions //======================================================================= -void GeometryGUI::OnSketchOptionsOnoffangledimension() +void GeometryGUI::onWindowActivated( SUIT_ViewWindow* win ) { - QMenuBar* Mb = this->myDesktop->getMainMenuBar(); - QMenuData* pp; - QMenuItem* item = Mb->findItem(10011,&pp); - pp->setItemChecked(10011,!pp->isItemChecked(10011)); - this->mySketcher.SetParameterVisibility(ANGLE_PARAMETER,pp->isItemChecked(10011)); -} + if ( !win ) + return; -//======================================================================= -// function : OnSketchOptionsOnofflengthdimension() -// purpose : -//======================================================================= -void GeometryGUI::OnSketchOptionsOnofflengthdimension() -{ - QMenuBar* Mb = this->myDesktop->getMainMenuBar(); - QMenuData* pp; - QMenuItem* item = Mb->findItem(10010,&pp); - pp->setItemChecked(10010,!pp->isItemChecked(10010)); - this->mySketcher.SetParameterVisibility(LENGTH_PARAMETER,pp->isItemChecked(10010)); -} + const bool ViewOCC = ( win->getViewManager()->getType() == OCCViewer_Viewer::Type() ); +// const bool ViewVTK = ( win->getViewManager()->getType() == SVTK_Viewer::Type() ); -//======================================================================= -// function : OnSketchOptionsOnoffradiusdimension() -// purpose : -//======================================================================= -void GeometryGUI::OnSketchOptionsOnoffradiusdimension() -{ - QMenuBar* Mb = this->myDesktop->getMainMenuBar(); - QMenuData* pp; - QMenuItem* item = Mb->findItem(10012,&pp); - pp->setItemChecked(10012,!pp->isItemChecked(10012)); - this->mySketcher.SetParameterVisibility(RADIUS_PARAMETER,pp->isItemChecked(10012)); -} + // disable non-OCC viewframe menu commands +// action( 404 )->setEnabled( ViewOCC ); // SKETCHER + action( 603 )->setEnabled( ViewOCC ); // SuppressFace + action( 604 )->setEnabled( ViewOCC ); // SuppressHole + action( 606 )->setEnabled( ViewOCC ); // CloseContour + action( 607 )->setEnabled( ViewOCC ); // RemoveInternalWires + action( 608 )->setEnabled( ViewOCC ); // AddPointOnEdge +// action( 609 )->setEnabled( ViewOCC ); // Free boundaries + action( 413 )->setEnabled( ViewOCC ); // Isos Settings + action( 800 )->setEnabled( ViewOCC ); // Create Group + action( 801 )->setEnabled( ViewOCC ); // Edit Group -//======================================================================= -// function : OnSketchOptionsOnoffxdimension() -// purpose : -//======================================================================= -void GeometryGUI::OnSketchOptionsOnoffxdimension() -{ - QMenuBar* Mb = this->myDesktop->getMainMenuBar(); - QMenuData* pp; - QMenuItem* item = Mb->findItem(10013,&pp); - pp->setItemChecked(10013,!pp->isItemChecked(10013)); - this->mySketcher.SetParameterVisibility(XVALUE_PARAMETER,pp->isItemChecked(10013)); + action( 9998 )->setEnabled( ViewOCC ); // MENU BLOCKS - MULTI-TRANSFORMATION } -//======================================================================= -// function : OnSketchOptionsOnoffydimension() -// purpose : -//======================================================================= -void GeometryGUI::OnSketchOptionsOnoffydimension() +void GeometryGUI::windows( QMap& mappa ) const { - QMenuBar* Mb = this->myDesktop->getMainMenuBar(); - QMenuData* pp; - QMenuItem* item = Mb->findItem(10014,&pp); - pp->setItemChecked(10014,!pp->isItemChecked(10014)); - this->mySketcher.SetParameterVisibility(YVALUE_PARAMETER,pp->isItemChecked(10014)); + mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft ); + mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom ); } - -//======================================================================= -// function : Archimede() -// purpose : -//======================================================================= -void GeometryGUI::Archimede( const Handle(SALOME_InteractiveObject)& IO, - const double aWeight, - const double aWaterDensity, - const double aMeshingDeflection ) +void GeometryGUI::viewManagers( QStringList& lst ) const { - try { - if ( IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject)) ) { - Handle(GEOM_InteractiveObject) GIO = - Handle(GEOM_InteractiveObject)::DownCast( IO ); - GEOM::GEOM_Shape_var Shape = GeomGUI->myComponentGeom->GetIORFromString( GIO->getIOR() ); - - GEOM::GEOM_Shape_var Result = GeomGUI->myComponentGeom->Archimede( Shape, aWeight, aWaterDensity, aMeshingDeflection); - Result->NameType(tr("GEOM_PLANE")); - if ( Display(Result, "") ) { - QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE")); - } - return; - } - if ( IO->hasEntry() ) { - SALOMEDS::Study_var aStudy = GeomGUI->myActiveStudy->getStudyDocument(); - SALOMEDS::SObject_var obj = aStudy->FindObjectID( IO->getEntry() ); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeIOR_var anIOR; - if ( !obj->_is_nil() ) { - if (obj->FindAttribute(anAttr, "AttributeIOR")) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - GEOM::GEOM_Shape_var Shape = GeomGUI->myComponentGeom->GetIORFromString( anIOR->Value() ); - GEOM::GEOM_Shape_var Result = GeomGUI->myComponentGeom->Archimede( Shape, aWeight, aWaterDensity, aMeshingDeflection); - Result->NameType(tr("GEOM_PLANE")); - if ( Display(Result, "") ) { - QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE")); - } - } - } - } - - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } + lst.append( OCCViewer_Viewer::Type() ); } - -//===================================================================================== -// EXPORTED METHODS -//===================================================================================== -extern "C" +void GeometryGUI::onViewManagerAdded( SUIT_ViewManager* vm ) { - bool OnGUIEvent(int theCommandID, QAD_Desktop* parent) + if ( vm->getType() == OCCViewer_Viewer::Type() ) { - return GeometryGUI::OnGUIEvent(theCommandID, parent); - } + qDebug( "connect" ); + connect( vm, SIGNAL( keyPress ( SUIT_ViewWindow*, QKeyEvent* ) ), + this, SLOT( OnKeyPress( SUIT_ViewWindow*, QKeyEvent* ) ) ); + connect( vm, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ), + this, SLOT( OnMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) ); + connect( vm, SIGNAL( mouseMove ( SUIT_ViewWindow*, QMouseEvent* ) ), + this, SLOT( OnMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) ); - bool OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame) - { - return GeometryGUI::OnKeyPress (pe, parent, studyFrame); - } - bool OnMousePress (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame) - { - return GeometryGUI::OnMousePress (pe, parent, studyFrame); - } + LightApp_SelectionMgr* sm = getApp()->selectionMgr(); + myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) ); - bool OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame) - { - return GeometryGUI::OnMouseMove (pe, parent, studyFrame); + // disable OCC selectors + getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() ); + for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() ) + sr->setEnabled(true); } - - bool SetSettings ( QAD_Desktop* parent ) + else if ( vm->getType() == SVTK_Viewer::Type() ) { - return GeometryGUI::SetSettings( parent ); - } + LightApp_SelectionMgr* sm = getApp()->selectionMgr(); + myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast( vm->getViewModel() ), sm ) ); - bool customPopup ( QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext, - const QString & theParent, const QString & theObject ) - { - return GeometryGUI::CustomPopup( parent, popup, theContext, theParent, theObject ); + // disable VTK selectors + getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() ); + for ( LightApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() ) + sr->setEnabled(true); } +} - void definePopup ( QString & theContext, QString & theParent, QString & theObject ) - { - GeometryGUI::DefinePopup( theContext, theParent, theObject ); - } - - bool activeStudyChanged ( QAD_Desktop* parent ) +void GeometryGUI::onViewManagerRemoved( SUIT_ViewManager* vm ) +{ + SUIT_ViewModel* viewer = vm->getViewModel(); + if ( vm->getType() == OCCViewer_Viewer::Type() ) { - GeometryGUI::activeStudyChanged( parent ); + for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() ) + if ( sr->viewer() == viewer ) + { + myOCCSelectors.remove( sr ); + break; + } } - - void buildPresentation ( const Handle(SALOME_InteractiveObject)& theIO ) + if ( vm->getType() == SVTK_Viewer::Type() ) { - GeometryGUI::BuildPresentation(theIO); + for ( LightApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() ) + if ( sr->viewer() == viewer ) + { + myVTKSelectors.remove( sr ); + break; + } } +} - void supportedViewType(int* buffer, int bufferSize) - { - if (!buffer || !bufferSize) return; - buffer[0] = (int)VIEW_OCC; - if (--bufferSize) buffer[1] = (int)VIEW_VTK; - } +QString GeometryGUI::engineIOR() const +{ + if ( !CORBA::is_nil( GetGeomGen() ) ) + return QString( getApp()->orb()->object_to_string( GetGeomGen() ) ); + return QString( "" ); } -//===================================================================================== -// function : OnFilletGetAll() -// purpose : -//===================================================================================== -bool GeometryGUI::OnFilletGetAll(const TopoDS_Shape& ShapeTopo, const double Radius, const int SubShapeType, const char* ShapeTopoIOR) +LightApp_Selection* GeometryGUI::createSelection() const { - GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID; - ListOfID->length(0); - - SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument(); - SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR( ShapeTopoIOR ); - if ( theObj->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY")); - return false ; - } - - try { - if( Radius <= Precision::Confusion() ) - return false; - - GEOM::GEOM_Shape_var aShape = myComponentGeom->GetIORFromString( ShapeTopoIOR ); - GEOM::GEOM_Shape_var result = myComponentGeom->MakeFillet(aShape, Radius, SubShapeType, ListOfID) ; - if ( result->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_ABORT")); - return false; - } - TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, result); - Standard_CString type; - GetShapeTypeString(S,type); - result->NameType( type ); + return new GEOMGUI_Selection(); +} - if ( Display( result, "" )) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); +void GeometryGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& title ) +{ + SalomeApp_Module::contextMenuPopup( client, menu, title ); + SALOME_ListIO lst; + getApp()->selectionMgr()->selectedObjects( lst ); + if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) { + Handle(SALOME_InteractiveObject) io = lst.First(); + SalomeApp_Study* appStudy = dynamic_cast( application()->activeStudy() ); + _PTR(Study) study = appStudy->studyDS(); + _PTR(SObject) obj = study->FindObjectID( io->getEntry() ); + if ( obj ) + title = QString( obj->GetName().c_str() ); } - return true; } -//===================================================================================== -// function : OnFilletGetSelected() -// purpose : -//===================================================================================== -bool GeometryGUI::OnFilletGetSelected(const TopoDS_Shape& ShapeTopo, - const char* ShapeTopoIOR, - const double Radius, - const int SubShapeType, - Standard_Integer& aLocalContextId, - bool& myUseLocalContext ) +void GeometryGUI::createPreferences() { - if ( this->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) { - return false; - } + int tabId = addPreference( tr( "PREF_TAB_SETTINGS" ) ); - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - - if( myUseLocalContext == false ) { - /* No local context opened for fillet method */ - myDesktop->putInfo(tr("GEOM_PRP_ABORT")); - return false ; - } - - GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID; - ic->InitSelected(); - int nbSelected = ic->NbSelected(); - int i = 0; - ic->InitSelected(); - - while(ic->MoreSelected()) { - TopoDS_Shape s = ic->SelectedShape(); - if ( s.ShapeType() == TopAbs_FACE ) { - TopExp_Explorer Exp( s, TopAbs_EDGE ); - TopTools_MapOfShape M ; - while ( Exp.More() ) { - if( M.Add(Exp.Current() )) { /* if a new edge : do not add doublons indices */ - ListOfID->length( i + 1 ); - ListOfID[i] = GetIndex( Exp.Current(), ShapeTopo, (int)TopAbs_EDGE ) ; - i++ ; - } - Exp.Next(); - } - } - else { - ListOfID->length( i + 1 ); - ListOfID[i] = GetIndex( ic->SelectedShape(), ShapeTopo, SubShapeType ); - i++; - } - ic->NextSelected(); - } + int genGroup = addPreference( tr( "PREF_GROUP_GENERAL" ), tabId ); + setPreferenceProperty( genGroup, "columns", 1 ); - GEOM::GEOM_Shape_var aShape = myComponentGeom->GetIORFromString( ShapeTopoIOR ); - GEOM::GEOM_Shape_var aResult ; - try { - aResult = myComponentGeom->MakeFillet( aShape, Radius, 6, ListOfID ); + int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), genGroup, + LightApp_Preferences::Selector, "Geometry", "display_mode" ); - /* local context from DialogBox */ - ic->CloseLocalContext(aLocalContextId) ; - myUseLocalContext = false ; + addPreference( tr( "PREF_SHADING_COLOR" ), genGroup, + LightApp_Preferences::Color, "Geometry", "shading_color" ); - TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, aResult); - Standard_CString type; - GetShapeTypeString(S,type); - aResult->NameType( type ); + addPreference( tr( "PREF_WIREFRAME_COLOR" ), genGroup, + LightApp_Preferences::Color, "Geometry", "wireframe_color" ); - if ( Display( aResult, "") ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } + addPreference( tr( "PREF_FREE_BOUND_COLOR" ), genGroup, + LightApp_Preferences::Color, "Geometry", "free_bound_color" ); - if ( myUseLocalContext ) { - /* local context from DialogBox */ - ic->CloseLocalContext(aLocalContextId) ; - myUseLocalContext = false ; - } + addPreference( tr( "PREF_LINE_COLOR"), genGroup, + LightApp_Preferences::Color, "Geometry", "line_color" ); - this->OnDisplayAll(true); - myActiveStudy->updateObjBrowser(); - myDesktop->putInfo (tr("GEOM_PRP_READY")); + addPreference( tr( "PREF_POINT_COLOR"), genGroup, + LightApp_Preferences::Color, "Geometry", "point_color" ); - return true ; -} + addPreference( tr( "PREF_ISOS_COLOR" ), genGroup, + LightApp_Preferences::Color, "Geometry", "isos_color" ); -//===================================================================================== -// function : OnChamferGetAll() -// purpose : -//===================================================================================== -bool GeometryGUI::OnChamferGetAll(const TopoDS_Shape& ShapeTopo, const double D1, const double D2, const int SubShapeType, const char* ShapeTopoIOR) -{ - GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID; - ListOfID->length(0); - - SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument(); - SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR( ShapeTopoIOR ); - if ( theObj->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY")); - return false ; - } - - try { - if( D1 <= Precision::Confusion() ) - return false; - if( D2 <= Precision::Confusion() ) - return false; - - GEOM::GEOM_Shape_var aShape = myComponentGeom->GetIORFromString( ShapeTopoIOR ); - GEOM::GEOM_Shape_var result = myComponentGeom->MakeChamfer(aShape, D1, D2, SubShapeType, ListOfID) ; - if ( result->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_ABORT")); - return false; - } + int step = addPreference( tr( "PREF_STEP_VALUE" ), genGroup, + LightApp_Preferences::IntSpin, "Geometry", "SettingsGeomStep" ); - TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, result); - Standard_CString type; - GetShapeTypeString(S,type); - result->NameType( type ); + int VertexGroup = addPreference( tr( "PREF_GROUP_VERTEX" ), tabId ); - if ( Display( result, "") ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } - return true; -} + int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), VertexGroup, + LightApp_Preferences::Selector, "Geometry", "type_of_marker" ); -//===================================================================================== -// function : OnChamferGetSelected() -// purpose : -//===================================================================================== -bool GeometryGUI::OnChamferGetSelected(const TopoDS_Shape& ShapeTopo, - const char* ShapeTopoIOR, - const double D1, const double D2, const int SubShapeType, - Standard_Integer& aLocalContextId, - bool& myUseLocalContext) -{ - if ( this->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) { - return false; - } - - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - - if( myUseLocalContext == false ) { - /* No local context opened for chamfer method */ - myDesktop->putInfo(tr("GEOM_PRP_ABORT")); - return false ; - } - - GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID; - ic->InitSelected(); - int nbSelected = ic->NbSelected(); - int i = 0; - ic->InitSelected(); - - while(ic->MoreSelected()) { - TopoDS_Shape s = ic->SelectedShape(); - if ( s.ShapeType() == TopAbs_FACE ) { - TopExp_Explorer Exp( s, TopAbs_EDGE ); - TopTools_MapOfShape M ; - while ( Exp.More() ) { - if( M.Add(Exp.Current() )) { /* if a new edge : do not add doublons indices */ - ListOfID->length( i + 1 ); - ListOfID[i] = GetIndex( Exp.Current(), ShapeTopo, (int)TopAbs_EDGE ) ; - i++ ; - } - Exp.Next(); - } - } - else { - ListOfID->length( i + 1 ); - ListOfID[i] = GetIndex( ic->SelectedShape(), ShapeTopo, SubShapeType ) ; - i++; - } - ic->NextSelected(); - } - - GEOM::GEOM_Shape_var aShape = myComponentGeom->GetIORFromString( ShapeTopoIOR ); - GEOM::GEOM_Shape_var aResult ; - try { - aResult = myComponentGeom->MakeChamfer( aShape, D1, D2, 6, ListOfID ); + int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), VertexGroup, + LightApp_Preferences::DblSpin, "Geometry", "marker_scale" ); - /* local context from DialogBox */ - ic->CloseLocalContext(aLocalContextId) ; - myUseLocalContext = false ; + // Set property for default display mode + QStringList aModesList; + aModesList.append( tr("MEN_WIREFRAME") ); + aModesList.append( tr("MEN_SHADING") ); - TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, aResult); - Standard_CString type; - GetShapeTypeString(S,type); - aResult->NameType( type ); + QValueList anIndexesList; + anIndexesList.append(0); + anIndexesList.append(1); - if ( Display( aResult, "") ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); - } + setPreferenceProperty( dispmode, "strings", aModesList ); + setPreferenceProperty( dispmode, "indexes", anIndexesList ); - if ( myUseLocalContext ) { - /* local context from DialogBox */ - ic->CloseLocalContext(aLocalContextId) ; - myUseLocalContext = false ; - } + // Set property for step value for spinboxes + setPreferenceProperty( step, "min", 0.001 ); + setPreferenceProperty( step, "max", 10000 ); + setPreferenceProperty( step, "precision", 3 ); + + // Set property for type of vertex marker + QStringList aTypeOfMarkerList; + QValueList anTypeOfMarkerIndexesList; + + aTypeOfMarkerList.append( tr("TOM_PLUS") ); + anTypeOfMarkerIndexesList.append(Aspect_TOM_PLUS); + + aTypeOfMarkerList.append( tr("TOM_POINT") ); + anTypeOfMarkerIndexesList.append(Aspect_TOM_POINT); + + aTypeOfMarkerList.append( tr("TOM_STAR") ); + anTypeOfMarkerIndexesList.append(Aspect_TOM_STAR); + + aTypeOfMarkerList.append( tr("TOM_O") ); + anTypeOfMarkerIndexesList.append(Aspect_TOM_O); + + aTypeOfMarkerList.append( tr("TOM_X") ); + anTypeOfMarkerIndexesList.append(Aspect_TOM_X); + + aTypeOfMarkerList.append( tr("TOM_O_POINT") ); + anTypeOfMarkerIndexesList.append(Aspect_TOM_O_POINT); + + aTypeOfMarkerList.append( tr("TOM_O_PLUS") ); + anTypeOfMarkerIndexesList.append(Aspect_TOM_O_PLUS); + + aTypeOfMarkerList.append( tr("TOM_O_STAR") ); + anTypeOfMarkerIndexesList.append(Aspect_TOM_O_STAR); - this->OnDisplayAll(true); - myActiveStudy->updateObjBrowser(); - myDesktop->putInfo (tr("GEOM_PRP_READY")); + aTypeOfMarkerList.append( tr("TOM_O_X") ); + anTypeOfMarkerIndexesList.append(Aspect_TOM_O_X); + + + setPreferenceProperty( typeOfMarker, "strings", aTypeOfMarkerList ); + setPreferenceProperty( typeOfMarker, "indexes", anTypeOfMarkerIndexesList ); + + // Set property for Vertex Marker scale + setPreferenceProperty( markerScale, "min", 1. ); + setPreferenceProperty( markerScale, "max", 7. ); + setPreferenceProperty( markerScale, "precision", 0.01 ); + setPreferenceProperty( markerScale, "step", 0.5 ); - return true ; } -//===================================================================================== -// function : MakeCDGAndDisplay() -// purpose : -//===================================================================================== -void GeometryGUI::MakeCDGAndDisplay(GEOM::GEOM_Shape_ptr Shape) +void GeometryGUI::preferencesChanged( const QString& section, const QString& param ) { - try { - GEOM::GEOM_Shape_var result = myComponentGeom->MakeCDG( Shape ); - if ( result->_is_nil() ) { - myDesktop->putInfo(tr("GEOM_PRP_ABORT") ); - return ; + if (section == "Geometry") { + SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr(); + if (param == QString("SettingsGeomStep")) { + double spin_step = aResourceMgr->doubleValue(section, param, 100.); + EmitSignalDefaultStepValueChanged(spin_step); } - result->NameType( tr("GEOM_POINT") ); - if ( Display( result ) ) - myDesktop->putInfo(tr("GEOM_PRP_DONE")); - } - catch (const SALOME::SALOME_Exception& S_ex) { - QtCatchCorbaException(S_ex); } - return ; } -bool GeometryGUI::SObjectExist(SALOMEDS::SObject_ptr theFatherObject, const char* IOR) { - SALOMEDS::Study_var aStudy = GeomGUI->myActiveStudy->getStudyDocument(); - SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(theFatherObject); - SALOMEDS::SObject_var RefSO; - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeIOR_var anIOR; - for (; it->More();it->Next()) { - SALOMEDS::SObject_var SO= it->Value(); - if (SO->FindAttribute(anAttr, "AttributeIOR") ) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - if ( strcmp( anIOR->Value(), IOR ) == 0 ) - return true; - } - if ( SO->ReferencedObject( RefSO ) ) { - if (RefSO->FindAttribute(anAttr, "AttributeIOR") ) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - if ( strcmp( anIOR->Value(), IOR ) == 0 ) - return true; - } - } - } - return false; +LightApp_Displayer* GeometryGUI::displayer() +{ + if( !myDisplayer ) + myDisplayer = new GEOM_Displayer( dynamic_cast( getApp()->activeStudy() ) ); + return myDisplayer; +} + +void GeometryGUI::setLocalSelectionMode(const int mode) +{ + myLocalSelectionMode = mode; +} +int GeometryGUI::getLocalSelectionMode() const +{ + return myLocalSelectionMode; }