geom/src/EntityGUI/EntityGUI.cxx

479 lines
17 KiB
C++
Raw Normal View History

2015-02-10 14:25:19 +05:00
// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
2004-01-07 20:46:21 +05:00
//
2012-08-09 13:58:02 +06:00
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
2004-01-07 20:46:21 +05:00
//
2012-08-09 13:58:02 +06:00
// 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
2014-02-18 12:44:41 +06:00
// version 2.1 of the License, or (at your option) any later version.
2004-01-07 20:46:21 +05:00
//
2012-08-09 13:58:02 +06:00
// 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.
2009-02-13 17:16:39 +05:00
//
2012-08-09 13:58:02 +06:00
// 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
2009-02-13 17:16:39 +05:00
//
2012-08-09 13:58:02 +06:00
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2009-02-13 17:16:39 +05:00
//
2012-08-09 13:58:02 +06:00
2009-02-13 17:16:39 +05:00
// GEOM GEOMGUI : GUI for Geometry component
// File : EntityGUI.cxx
// Author : Damien COQUERET, Open CASCADE S.A.S.
2004-01-07 20:46:21 +05:00
//
#include "EntityGUI.h"
#include "GeometryGUI.h"
2012-08-09 13:58:02 +06:00
#include "GeometryGUI_Operations.h"
2013-10-30 22:50:50 +06:00
#include "GEOMUtils.hxx"
2009-02-13 17:16:39 +05:00
#include <LightApp_SelectionMgr.h>
2009-02-13 17:16:39 +05:00
#include <OCCViewer_ViewManager.h>
#include <OCCViewer_ViewModel.h>
2012-08-09 13:58:02 +06:00
#include <OCCViewer_ViewPort3d.h>
#include <OCCViewer_ViewWindow.h>
#include <SALOME_ListIO.hxx>
#include <SUIT_Desktop.h>
#include <SUIT_MessageBox.h>
#include <SUIT_Session.h>
#include <SUIT_ViewWindow.h>
2009-02-13 17:16:39 +05:00
#include <SalomeApp_Application.h>
#include <SalomeApp_Study.h>
2014-11-19 20:45:44 +05:00
#include "utilities.h"
2004-06-16 21:24:55 +06:00
2009-02-13 17:16:39 +05:00
#include <TopoDS_Shape.hxx>
2012-08-09 13:58:02 +06:00
#include <TopoDS.hxx>
#include <BRep_Tool.hxx>
#include <ProjLib.hxx>
#include <ElSLib.hxx>
#include <QMouseEvent>
#include <QApplication>
2004-06-16 21:24:55 +06:00
2012-08-09 13:58:02 +06:00
#include "EntityGUI_SketcherDlg.h" // Sketcher
#include "EntityGUI_3DSketcherDlg.h" // Sketcher
#include "EntityGUI_IsolineDlg.h" // Isoline
2014-10-28 15:19:15 +05:00
#include "EntityGUI_SurfFromFaceDlg.h" // Surface From Face
2012-08-09 13:58:02 +06:00
#include "EntityGUI_SubShapeDlg.h" // Method SUBSHAPE
#include "EntityGUI_FeatureDetectorDlg.h" // Feature Detection
#include "EntityGUI_PictureImportDlg.h" // Import Picture in viewer
#include "EntityGUI_FieldDlg.h" // Create/Edit Field
#include "EntityGUI_PolylineDlg.h" // Create/Edit 2d polyline
#include "GEOMImpl_Types.hxx"
2004-01-07 20:46:21 +05:00
//=======================================================================
// function : EntityGUI()
// purpose : Constructor
//=======================================================================
EntityGUI::EntityGUI( GeometryGUI* parent ) : GEOMGUI( parent )
2004-01-07 20:46:21 +05:00
{
2009-02-13 17:16:39 +05:00
mySimulationShape1 = new AIS_Shape( TopoDS_Shape() );
mySimulationShape2 = new AIS_Shape( TopoDS_Shape() );
2004-01-07 20:46:21 +05:00
}
//=======================================================================
// function : ~EntityGUI()
// purpose : Destructor
//=======================================================================
EntityGUI::~EntityGUI()
{
}
//=======================================================================
// function : OnGUIEvent()
// purpose :
//=======================================================================
2009-02-13 17:16:39 +05:00
bool EntityGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
2004-01-07 20:46:21 +05:00
{
SalomeApp_Application* app = getGeometryGUI()->getApp();
if ( !app ) return false;
getGeometryGUI()->EmitSignalDeactivateDialog();
2004-12-01 15:39:14 +05:00
QDialog* aDlg = NULL;
2004-01-07 20:46:21 +05:00
2009-02-13 17:16:39 +05:00
switch ( theCommandID ) {
2012-08-09 13:58:02 +06:00
case GEOMOp::Op2dSketcher: // 2D SKETCHER
2009-02-13 17:16:39 +05:00
getGeometryGUI()->ActiveWorkingPlane();
aDlg = new EntityGUI_SketcherDlg( getGeometryGUI(), parent );
break;
2012-08-09 13:58:02 +06:00
case GEOMOp::Op3dSketcher: // 3D SKETCHER
2009-02-13 17:16:39 +05:00
aDlg = new EntityGUI_3DSketcherDlg( getGeometryGUI(), parent );
break;
case GEOMOp::OpIsoline: // ISOLINE
aDlg = new EntityGUI_IsolineDlg( getGeometryGUI(), parent );
break;
2014-10-28 15:19:15 +05:00
case GEOMOp::OpSurfaceFromFace: // SURFACE FROM FACE
aDlg = new EntityGUI_SurfFromFaceDlg( getGeometryGUI(), parent );
break;
2012-08-09 13:58:02 +06:00
case GEOMOp::OpExplode: // EXPLODE
2009-02-13 17:16:39 +05:00
aDlg = new EntityGUI_SubShapeDlg( getGeometryGUI(), parent );
break;
2012-08-09 13:58:02 +06:00
#ifdef WITH_OPENCV
case GEOMOp::OpFeatureDetect: // FEATURE DETECTION
aDlg = new EntityGUI_FeatureDetectorDlg( getGeometryGUI(), parent );
break;
#endif
case GEOMOp::OpPictureImport: // IMPORT PICTURE IN VIEWER
aDlg = new EntityGUI_PictureImportDlg( getGeometryGUI(), parent );
break;
case GEOMOp::OpCreateField: // CREATE FIELD
aDlg = new EntityGUI_FieldDlg (getGeometryGUI(), GEOM::GEOM_Field::_nil(), 0,
parent);
break;
case GEOMOp::OpEditField: // EDIT FIELD
case GEOMOp::OpEditFieldPopup:
{
SALOME_ListIO aList;
aList.Clear();
LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
if (aSelMgr)
aSelMgr->selectedObjects(aList);
SALOME_ListIteratorOfListIO anIter (aList);
GEOM::GEOM_Field_var field;
GEOM::GEOM_FieldStep_var step;
SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
if ( aList.Extent() > 0 && study ) {
for ( ; anIter.More(); anIter.Next() )
{
Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
if ( !anIObj.IsNull() && anIObj->hasEntry() )
if ( _PTR(SObject) obj = study->studyDS()->FindObjectID( anIObj->getEntry() ))
{
CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( obj );
GEOM::GEOM_BaseObject_var bo = GEOM::GEOM_BaseObject::_narrow( corbaObj );
GEOM::GEOM_Field_var f;
GEOM::GEOM_FieldStep_var s;
switch ( bo->GetType() ) {
case GEOM_FIELD:
f = GEOM::GEOM_Field::_narrow( corbaObj ); break;
case GEOM_FIELD_STEP:
step = GEOM::GEOM_FieldStep::_narrow( corbaObj );
if ( !step->_is_nil() )
f = step->GetField();
break;
default:
continue;
}
if ( !f->_is_nil() )
{
if ( !field->_is_nil() && !f->_is_equivalent( field ))
{
field = GEOM::GEOM_Field::_nil(); // several field selected
break;
}
field = f;
}
}
}
}
if ( !field->_is_nil()) {
int stepID;
if ( !step->_is_nil() ) {
stepID = step->GetID();
}
else {
GEOM::ListOfLong_var stepIDs = field->GetSteps();
if ( stepIDs->length() > 0 )
stepID = stepIDs[0];
else
stepID = 0;
}
aDlg = new EntityGUI_FieldDlg (getGeometryGUI(), field, stepID, parent);
break;
}
SUIT_MessageBox::warning(parent, tr("WRN_WARNING"), tr("NO_FIELD"));
break;
}
case GEOMOp::Op2dPolylineEditor: // POLYLINE EDITOR
getGeometryGUI()->ActiveWorkingPlane();
aDlg = new EntityGUI_PolylineDlg( getGeometryGUI(), parent );
break;
2009-02-13 17:16:39 +05:00
default:
app->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) );
break;
2004-12-01 15:39:14 +05:00
}
if ( aDlg )
aDlg->show();
return true;
2004-01-07 20:46:21 +05:00
}
2012-08-09 13:58:02 +06:00
//=================================================================================
// function : 0nMousePress()
// purpose : [static] manage mouse events
//=================================================================================
bool EntityGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
{
QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
// Create Point dialog, OCC viewer
if ( aDlg &&
theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() &&
pe->modifiers() != Qt::ControlModifier ) {
gp_Pnt aPnt;
if ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_SketcherDlg" ) == 0 )
{
EntityGUI_SketcherDlg* aSketcherDlg = (EntityGUI_SketcherDlg*) aDlg;
((OCCViewer_ViewWindow*)theViewWindow)->setSketcherStyle(true);
if ( aSketcherDlg->acceptMouseEvent() ) {
OCCViewer_Viewer* anOCCViewer =
( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer();
Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
ic->InitSelected();
if ( pe->modifiers() == Qt::ShiftModifier )
ic->ShiftSelect(); // Append selection
else
ic->Select(); // New selection
ic->InitSelected();
if ( ic->MoreSelected() ) {
TopoDS_Shape aShape = ic->SelectedShape();
if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
}
else {
OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
2013-10-30 22:50:50 +06:00
aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
2012-08-09 13:58:02 +06:00
}
Qt::KeyboardModifiers modifiers = pe->modifiers();
aSketcherDlg->OnPointSelected( modifiers, aPnt ); // "feed" the point to point construction dialog
} // acceptMouseEvent()
}
#ifdef WITH_OPENCV
if ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_FeatureDetectorDlg" ) == 0 )
{
EntityGUI_FeatureDetectorDlg* aCornerDlg = (EntityGUI_FeatureDetectorDlg*) aDlg;
if ( aCornerDlg->acceptMouseEvent() ) {
OCCViewer_Viewer* anOCCViewer =
( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer();
Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
ic->InitSelected();
ic->Select(); // New selection
ic->InitSelected();
TopoDS_Shape aShape;
if ( ic->MoreSelected() )
aShape = ic->SelectedShape();
if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
else
{
OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
2013-10-30 22:50:50 +06:00
aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
2012-08-09 13:58:02 +06:00
}
// aCornerDlg->OnPointSelected( aPnt ); // "feed" the point to corner detection dialog
// QPoint start = QPoint(pe->x(),pe->y());
aCornerDlg->setStartPnt( aPnt );
} // acceptMouseEvent()
}
#endif
}
return false;
}
//=================================================================================
// function : 0nMouseRelease()
// purpose : [static] manage mouse events
//=================================================================================
bool EntityGUI::OnMouseRelease( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
{
((OCCViewer_ViewWindow*)theViewWindow)->setSketcherStyle(false);
QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
#ifdef WITH_OPENCV
if ( aDlg && ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_FeatureDetectorDlg" ) == 0 ) &&
theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() &&
pe->modifiers() != Qt::ControlModifier )
{
EntityGUI_FeatureDetectorDlg* aCornerDlg = (EntityGUI_FeatureDetectorDlg*) aDlg;
gp_Pnt aPnt;
if ( aCornerDlg->acceptMouseEvent() )
{
// QPoint end = QPoint(pe->x(),pe->y());
OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
2013-10-30 22:50:50 +06:00
aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
2012-08-09 13:58:02 +06:00
aCornerDlg->setEndPnt( aPnt );
}
}
#endif
return false;
}
//=================================================================================
// function : 0nMouseMove()
// purpose : [static] manage mouse events
//=================================================================================
bool EntityGUI::OnMouseMove( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
{
QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
if ( aDlg && QString( aDlg->metaObject()->className() ).compare( "EntityGUI_SketcherDlg" ) == 0 &&
theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() )
{
EntityGUI_SketcherDlg* aSketcherDlg = (EntityGUI_SketcherDlg*) aDlg;
if ( aSketcherDlg->acceptMouseEvent() )
{
OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
2013-10-30 22:50:50 +06:00
gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
2012-08-09 13:58:02 +06:00
Qt::KeyboardModifiers modifiers = pe->modifiers();
if (QApplication::mouseButtons() == Qt::LeftButton )
aSketcherDlg->OnPointSelected( modifiers, aPnt, false ); // "feed" the point to point construction dialog
}
}
return false;
}
2004-06-16 21:24:55 +06:00
//=====================================================================================
// function : DisplaySimulationShape()
// purpose : Displays 'this->mySimulationShape' a pure graphical shape from a TopoDS_Shape
//=====================================================================================
2009-02-13 17:16:39 +05:00
void EntityGUI::DisplaySimulationShape( const TopoDS_Shape& S1, const TopoDS_Shape& S2 )
2004-01-07 20:46:21 +05:00
{
2012-08-09 13:58:02 +06:00
MESSAGE("EntityGUI::DisplaySimulationShape")
SalomeApp_Application* app = getGeometryGUI()->getApp();
if ( !app ) return;
SUIT_ViewManager* aVM = app->desktop()->activeWindow()->getViewManager();
2009-02-13 17:16:39 +05:00
if ( aVM->getType() != OCCViewer_Viewer::Type() )
2004-06-16 21:24:55 +06:00
return;
2009-02-13 17:16:39 +05:00
OCCViewer_Viewer* v3d = ( (OCCViewer_ViewManager*)aVM )->getOCCViewer();
2004-06-16 21:24:55 +06:00
Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
try {
2009-02-13 17:16:39 +05:00
if ( !S1.IsNull() ) {
2004-06-16 21:24:55 +06:00
/* erase any previous */
ic->Erase( mySimulationShape1, Standard_True );
2009-02-13 17:16:39 +05:00
ic->ClearPrs( mySimulationShape1 );
2009-02-13 17:16:39 +05:00
mySimulationShape1 = new AIS_Shape( TopoDS_Shape() );
mySimulationShape1->Set( S1 );
mySimulationShape1->SetColor( Quantity_NOC_RED );
2009-02-13 17:16:39 +05:00
ic->Deactivate( mySimulationShape1 );
ic->Display( mySimulationShape1, Standard_False );
2004-06-16 21:24:55 +06:00
mySimulationShape1->UnsetColor();
}
2009-02-13 17:16:39 +05:00
if ( !S2.IsNull() ) {
ic->Erase( mySimulationShape2, Standard_True );
2009-02-13 17:16:39 +05:00
ic->ClearPrs( mySimulationShape2 );
2004-01-07 20:46:21 +05:00
2009-02-13 17:16:39 +05:00
mySimulationShape2 = new AIS_Shape( TopoDS_Shape() );
mySimulationShape2->Set( S2 );
mySimulationShape2->SetColor( Quantity_NOC_VIOLET );
2004-01-07 20:46:21 +05:00
2009-02-13 17:16:39 +05:00
ic->Deactivate( mySimulationShape2 );
ic->Display( mySimulationShape2, Standard_False );
2004-06-16 21:24:55 +06:00
mySimulationShape2->UnsetColor();
2004-01-07 20:46:21 +05:00
}
2004-06-16 21:24:55 +06:00
ic->UpdateCurrentViewer();
2004-01-07 20:46:21 +05:00
}
2009-02-13 17:16:39 +05:00
catch( Standard_Failure ) {
MESSAGE( "Exception catched in EntityGUI::DisplaySimulationShape" );
2004-06-16 21:24:55 +06:00
}
2004-01-07 20:46:21 +05:00
}
2004-06-16 21:24:55 +06:00
//==================================================================================
// function : EraseSimulationShape()
// purpose : Clears the display of 'mySimulationShape' a pure graphical shape
//==================================================================================
2004-12-01 15:39:14 +05:00
void EntityGUI::EraseSimulationShape()
2004-01-07 20:46:21 +05:00
{
2012-08-09 13:58:02 +06:00
MESSAGE("EntityGUI::EraseSimulationShape")
SalomeApp_Application* app = getGeometryGUI()->getApp();
if ( !app ) return;
// get all view windows at the desktop
2009-02-13 17:16:39 +05:00
QList<SUIT_ViewWindow*> aWndLst = app->desktop()->windows();
//get all view windows, which belong to the active study
2009-02-13 17:16:39 +05:00
QList<SUIT_ViewWindow*> aWndLstAS;
SUIT_ViewWindow* vw;
2009-02-13 17:16:39 +05:00
QListIterator<SUIT_ViewWindow*> itWL( aWndLst );
while ( itWL.hasNext() && ( vw = itWL.next() ) )
if ( vw->getViewManager()->study() == app->activeStudy() )
aWndLstAS.append( vw );
2009-02-13 17:16:39 +05:00
QListIterator<SUIT_ViewWindow*> itWLAS( aWndLstAS );
while ( itWLAS.hasNext() && ( vw = itWLAS.next() ) ) {
if ( vw->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
2009-02-13 17:16:39 +05:00
OCCViewer_Viewer* v3d = ( (OCCViewer_ViewManager*)( vw->getViewManager() ) )->getOCCViewer();
2004-06-16 21:24:55 +06:00
Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
ic->Erase( mySimulationShape1, Standard_True );
ic->Erase( mySimulationShape2, Standard_True );
ic->ClearPrs( mySimulationShape1 );
2009-02-13 17:16:39 +05:00
ic->ClearPrs( mySimulationShape2 );
2004-06-16 21:24:55 +06:00
ic->UpdateCurrentViewer();
}
2004-01-07 20:46:21 +05:00
}
}
//=====================================================================================
// function : SObjectExist()
// purpose :
//=====================================================================================
2009-02-13 17:16:39 +05:00
bool EntityGUI::SObjectExist( const _PTR(SObject)& theFatherObject, const char* IOR )
2004-01-07 20:46:21 +05:00
{
SalomeApp_Application* app = getGeometryGUI()->getApp();
if ( !app ) return false;
SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
if ( !appStudy ) return false;
_PTR(Study) aStudy = appStudy->studyDS();
2009-02-13 17:16:39 +05:00
_PTR(ChildIterator) it ( aStudy->NewChildIterator( theFatherObject ) );
_PTR(SObject) RefSO;
_PTR(GenericAttribute) anAttr;
2009-02-13 17:16:39 +05:00
for ( ; it->More();it->Next() ) {
_PTR(SObject) SO ( it->Value() );
2009-02-13 17:16:39 +05:00
if ( SO->FindAttribute( anAttr, "AttributeIOR" ) ) {
_PTR(AttributeIOR) anIOR ( anAttr );
2009-02-13 17:16:39 +05:00
if ( strcmp( anIOR->Value().c_str(), IOR ) == 0 )
2012-08-09 13:58:02 +06:00
return true;
2004-01-07 20:46:21 +05:00
}
2009-02-13 17:16:39 +05:00
if ( SO->ReferencedObject( RefSO ) ) {
if ( RefSO->FindAttribute( anAttr, "AttributeIOR" ) ) {
_PTR(AttributeIOR) anIOR ( anAttr );
2012-08-09 13:58:02 +06:00
if ( strcmp( anIOR->Value().c_str(), IOR ) == 0 )
return true;
2004-01-07 20:46:21 +05:00
}
}
}
return false;
}
//=====================================================================================
// EXPORTED METHODS
//=====================================================================================
extern "C"
{
2009-02-13 17:16:39 +05:00
#ifdef WIN32
__declspec( dllexport )
#endif
GEOMGUI* GetLibGUI( GeometryGUI* parent )
2004-12-01 15:39:14 +05:00
{
return new EntityGUI( parent );
2004-12-01 15:39:14 +05:00
}
2004-01-07 20:46:21 +05:00
}