// Module : SALOME
// $Header$
-using namespace std;
#include "OCCViewer_ViewFrame.h"
#include "OCCViewer_Viewer3d.h"
#include "OCCViewer_ViewPort.h"
#include "QAD_Settings.h"
#include "SALOME_Selection.h"
#include "SALOME_AISShape.hxx"
+#include "SALOMEGUI.h"
+#include "SALOMEDS_Tool.hxx"
+#include "ToolsGUI.h"
// QT Include
#include <qapplication.h>
#include <AIS_ListIteratorOfListOfInteractive.hxx>
#include <Visual3d_View.hxx>
-/*!
- Constructor
+// IDL headers
+#include <SALOMEconfig.h>
+#include CORBA_SERVER_HEADER(SALOMEDS)
+#include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
+
+using namespace std;
+
+//=======================================================================
+// name : getMapOfEntry
+// Purpose : Convert list of interactive objects in map <entry <--> interactive object>
+//=======================================================================
+static void getMapOfEntry( const AIS_ListOfInteractive& theList,
+ QMap< QString, Handle(AIS_InteractiveObject) >& theMap )
+{
+ AIS_ListIteratorOfListOfInteractive anIter( theList );
+ for ( ; anIter.More(); anIter.Next() )
+ {
+ Handle(SALOME_InteractiveObject) anIO =
+ Handle(SALOME_InteractiveObject)::DownCast( anIter.Value() );
+ if ( !anIO.IsNull() )
+ theMap[ anIO->getEntry() ] = anIter.Value();
+ }
+}
+
+
+/*
+ Class : OCCViewer_ViewFrame
+ Description : View frame for Open CASCADE view
*/
-OCCViewer_ViewFrame::OCCViewer_ViewFrame(QWidget* parent, const QString& title)
- : QAD_ViewFrame (parent, "")
+
+
+//=======================================================================
+// name : OCCViewer_ViewFrame
+// Purpose : Constructor
+//=======================================================================
+OCCViewer_ViewFrame::OCCViewer_ViewFrame( QWidget* parent, const QString& title )
+ : QAD_ViewFrame ( parent, "" )
{
initialize();
}
-/*!
- Constructor
-*/
+//=======================================================================
+// name : OCCViewer_ViewFrame
+// Purpose : Constructor
+//=======================================================================
OCCViewer_ViewFrame::OCCViewer_ViewFrame( QWidget* parent )
: QAD_ViewFrame (parent, "")
{
initialize();
}
-/*!
- Destructor
-*/
+//=======================================================================
+// name : ~OCCViewer_ViewFrame
+// Purpose : Destructor
+//=======================================================================
OCCViewer_ViewFrame::~OCCViewer_ViewFrame()
{
cleanup();
}
-/*!
- Init viewframe
-*/
+//=======================================================================
+// name : initialize
+// Purpose : Initialize view frame (called from constructors )
+//=======================================================================
void OCCViewer_ViewFrame::initialize()
{
myViewPort = NULL;
myViewer->enableMultipleSelection( true );
}
-/*!
- Cleanup viewframe
-*/
+//=======================================================================
+// name : cleanup
+// Purpose : Cleanup viewframe
+//=======================================================================
void OCCViewer_ViewFrame::cleanup()
{
-
}
-/*!
- Sets the viewport for this frame
-*/
+//=======================================================================
+// name : setViewPort
+// Purpose : Sets the viewport for this frame
+//=======================================================================
void OCCViewer_ViewFrame::setViewPort( OCCViewer_ViewPort* view )
{
myViewPort = view;
setCentralWidget ( myViewPort );
}
-/*!
- Inits the viewport for this frame
-*/
+//=======================================================================
+// name : initViewPort
+// Purpose : Inits the viewport for this frame
+//=======================================================================
void OCCViewer_ViewFrame::initViewPort()
{
/* Active Key Event */
+
setFocus();
/* Initial attributes */
+
myViewPort->setCursor( cursor() );
myViewPort->setBackgroundColor( backgroundColor() );
- QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpKeyPress (QKeyEvent*)),
- this, SIGNAL(vfKeyPress(QKeyEvent*))) );
-
- /* Listen to my viewport */
- QAD_ASSERT ( QObject::connect(myViewPort,
- SIGNAL(vpTransformationStarted (OCCViewer_ViewPort::OperationType)),
- this,
- SIGNAL(vfTransformationStarted(OCCViewer_ViewPort::OperationType))) );
- QAD_ASSERT ( QObject::connect( myViewPort,
- SIGNAL(vpTransformationFinished (OCCViewer_ViewPort::OperationType)),
- this,
- SIGNAL(vfTransformationFinished(OCCViewer_ViewPort::OperationType))) );
-
- QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpDrawExternal (QPainter*)),
- this, SIGNAL(vfDrawExternal(QPainter*))) );
- QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpMousePress (QMouseEvent*)),
- this, SIGNAL(vfMousePress(QMouseEvent*))) );
- QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpMouseRelease (QMouseEvent*)),
- this, SIGNAL(vfMouseRelease(QMouseEvent*))) );
- QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpMouseMove (QMouseEvent*)),
- this, SIGNAL(vfMouseMove(QMouseEvent*))) );
- QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpMouseDoubleClick (QMouseEvent*)),
- this, SIGNAL(vfMouseDoubleClick(QMouseEvent*))) );
-
- QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpKeyPress (QKeyEvent*)),
- this, SIGNAL(vfKeyPress(QKeyEvent*))) );
- QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpKeyRelease (QKeyEvent*)),
- this, SIGNAL(vfKeyRelease(QKeyEvent*))) );
-}
-
-/*!
- Returns widget containing 3D-Viewer
-*/
+ QAD_ASSERT( QObject::connect(myViewPort, SIGNAL( vpKeyPress ( QKeyEvent* ) ),
+ this, SIGNAL(vfKeyPress(QKeyEvent*))) );
+
+ /* Listen to my viewport */
+
+ QAD_ASSERT( connect( myViewPort, SIGNAL( vpTransformationStarted( OCCViewer_ViewPort::OperationType ) ),
+ this, SIGNAL( vfTransformationStarted( OCCViewer_ViewPort::OperationType ) ) ) );
+ QAD_ASSERT( connect( myViewPort, SIGNAL( vpTransformationFinished ( OCCViewer_ViewPort::OperationType ) ),
+ this, SIGNAL( vfTransformationFinished( OCCViewer_ViewPort::OperationType ) ) ) );
+
+ QAD_ASSERT( connect( myViewPort, SIGNAL( vpDrawExternal( QPainter* ) ),
+ this, SIGNAL( vfDrawExternal( QPainter* ) ) ) );
+ QAD_ASSERT( connect( myViewPort, SIGNAL( vpMousePress( QMouseEvent* ) ),
+ this, SIGNAL( vfMousePress( QMouseEvent* ) ) ) );
+ QAD_ASSERT( connect( myViewPort, SIGNAL( vpMouseRelease( QMouseEvent* ) ),
+ this, SIGNAL( vfMouseRelease( QMouseEvent* ) ) ) );
+ QAD_ASSERT( connect( myViewPort, SIGNAL( vpMouseMove( QMouseEvent* ) ),
+ this, SIGNAL( vfMouseMove( QMouseEvent* ) ) ) );
+ QAD_ASSERT( connect( myViewPort, SIGNAL( vpMouseDoubleClick( QMouseEvent* ) ),
+ this, SIGNAL( vfMouseDoubleClick( QMouseEvent* ) ) ) );
+
+ QAD_ASSERT( connect( myViewPort, SIGNAL( vpKeyPress( QKeyEvent* ) ),
+ this, SIGNAL( vfKeyPress( QKeyEvent* ) ) ) );
+ QAD_ASSERT( connect( myViewPort, SIGNAL( vpKeyRelease( QKeyEvent* ) ),
+ this, SIGNAL( vfKeyRelease( QKeyEvent* ) ) ) );
+}
+
+//=======================================================================
+// name : getViewWidget
+// Purpose : Returns widget containing 3D-Viewer
+//=======================================================================
QWidget* OCCViewer_ViewFrame::getViewWidget()
{
return (QWidget*)getViewPort();
}
-/*!
- Returns the viewport of this frame
-*/
+//=======================================================================
+// name : getViewPort
+// Purpose : Returns the viewport of this frame
+//=======================================================================
OCCViewer_ViewPort* OCCViewer_ViewFrame::getViewPort() const
{
return myViewPort;
}
-/*!
- Sets the cursor for the viewframe's viewport
-*/
+//=======================================================================
+// name : Sets the cursor for the viewframe's viewport
+// Purpose : setCursor
+//=======================================================================
void OCCViewer_ViewFrame::setCursor( const QCursor& cursor)
{
if ( myViewPort )
- myViewPort->QWidget::setCursor(cursor);
+ myViewPort->QWidget::setCursor( cursor );
}
-/*!
- Returns the current cursor
-*/
+
+//=======================================================================
+// name : cursor
+// Purpose : Returns the current cursor
+//=======================================================================
QCursor OCCViewer_ViewFrame::cursor() const
{
if ( myViewPort )
return QMainWindow::cursor();
}
-/*!
- Set background of the viewport
-*/
+//=======================================================================
+// name : setBackgroundColor
+// Purpose : Set background of the viewport
+//=======================================================================
void OCCViewer_ViewFrame::setBackgroundColor( const QColor& color)
{
if ( myViewPort )
- myViewPort->setBackgroundColor(color);
+ myViewPort->setBackgroundColor( color );
}
-/*!
- Returns background of the viewport
-*/
+//=======================================================================
+// name : backgroundColor
+// Purpose : Returns background of the viewport
+//=======================================================================
QColor OCCViewer_ViewFrame::backgroundColor() const
{
if ( myViewPort )
return QMainWindow::backgroundColor();
}
-/*!
- Sets the parent viewer for the window
-*/
-void OCCViewer_ViewFrame::setViewer(OCCViewer_Viewer3d* viewer)
+//=======================================================================
+// name : setViewer
+// Purpose : Sets the parent viewer for the window
+//=======================================================================
+void OCCViewer_ViewFrame::setViewer( OCCViewer_Viewer3d* viewer )
{
myViewer = viewer;
}
-/*!
- Returns the parent viewer for the window
-*/
+//=======================================================================
+// name : getViewer
+// Purpose : Returns the parent viewer for the window
+//=======================================================================
OCCViewer_Viewer3d* OCCViewer_ViewFrame::getViewer() const
{
return myViewer;
}
-/*!
- Returns 'true' if viewframe is visible
-*/
-void OCCViewer_ViewFrame::setVisible( bool visible )
+//=======================================================================
+// name : setVisible
+// Purpose : Show/hide view
+//=======================================================================
+void OCCViewer_ViewFrame::setVisible( const bool visible )
{
if ( visible == QWidget::isVisible() )
return;
- if ( visible ) show();
- else hide();
+ if ( visible )
+ show();
+ else
+ hide();
}
-/*!
- Called when viewframe is about to close
-*/
-void OCCViewer_ViewFrame::closeEvent(QCloseEvent* e)
+//=======================================================================
+// name : closeEvent
+// Purpose : Called when viewframe is about to close
+//=======================================================================
+void OCCViewer_ViewFrame::closeEvent( QCloseEvent* e )
{
- emit vfViewClosing(e); /* notify our viewer */
+ emit vfViewClosing( e ); /* notify our viewer */
}
-/*!
- Called when viewframe is resized
-*/
-void OCCViewer_ViewFrame::resizeEvent(QResizeEvent* e)
+//=======================================================================
+// name : resizeEvent
+// Purpose : Called when viewframe is resized
+//=======================================================================
+void OCCViewer_ViewFrame::resizeEvent( QResizeEvent* e )
{
- emit vfResize(e);
+ emit vfResize( e );
}
+//=======================================================================
+// name : keyPressEvent
+// Purpose : Called when key is pressed
+//=======================================================================
void OCCViewer_ViewFrame::keyPressEvent( QKeyEvent *k )
{
emit vfKeyPress(k);
}
-/*!
- Fits all objects in the active view
-*/
+//=======================================================================
+// name : onViewFitAll
+// Purpose : Fits all objects in the active view
+//=======================================================================
void OCCViewer_ViewFrame::onViewFitAll()
{
myViewPort->fitAll();
}
-/*!
- Fits all obejcts within a rectangular area of the active view
-*/
+//=======================================================================
+// name : onViewFitArea
+// Purpose : Fits all obejcts within a rectangular area of the active view
+//=======================================================================
void OCCViewer_ViewFrame::onViewFitArea()
{
myViewPort->activateWindowFit();
- QAD_Application::getDesktop()->putInfo( tr("PRP_VW3D_SKETCHAREA") );
+ QAD_Application::getDesktop()->putInfo( tr( "PRP_VW3D_SKETCHAREA" ) );
}
-/*!
- Moves the active view
-*/
+//=======================================================================
+// name : onViewPan
+// Purpose : Moves the active view
+//=======================================================================
void OCCViewer_ViewFrame::onViewPan()
{
myViewPort->activatePanning();
}
-/*!
- Zooms the active view
-*/
+//=======================================================================
+// name : onViewZoom
+// Purpose : Zooms the active view
+//=======================================================================
void OCCViewer_ViewFrame::onViewZoom()
{
myViewPort->activateZoom();
}
-/*!
- Sets a new center of the active view
-*/
+//=======================================================================
+// name : onViewGlobalPan
+// Purpose : Sets a new center of the active view
+//=======================================================================
void OCCViewer_ViewFrame::onViewGlobalPan()
{
myViewPort->activateGlobalPanning();
QAD_Application::getDesktop()->putInfo( tr("PRP_VW3D_POINTCENTER") );
}
-/*!
- Rotates the active view
-*/
+//=======================================================================
+// name : onViewRotate
+// Purpose : Rotates the active view
+//=======================================================================
void OCCViewer_ViewFrame::onViewRotate()
{
myViewPort->activateRotation();
}
-/*!
- Reset the active view
-*/
+//=======================================================================
+// name : onViewReset
+// Purpose : Reset the active view
+//=======================================================================
void OCCViewer_ViewFrame::onViewReset()
{
myViewPort->reset();
}
-/*!
- Provides front projection of the active view
-*/
+//=======================================================================
+// name : onViewFront
+// Purpose : Provides front projection of the active view
+//=======================================================================
void OCCViewer_ViewFrame::onViewFront()
{
Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
onViewFitAll();
}
-/*!
- Provides back projection of the active view
-*/
+//=======================================================================
+// name : onViewBack
+// Purpose : Provides back projection of the active view
+//=======================================================================
void OCCViewer_ViewFrame::onViewBack()
{
Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
onViewFitAll();
}
-/*!
- Provides right projection of the active view
-*/
+//=======================================================================
+// name : onViewRight
+// Purpose : Provides right projection of the active view
+//=======================================================================
void OCCViewer_ViewFrame::onViewRight()
{
Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
onViewFitAll();
}
-/*!
- Provides left projection of the active view
-*/
+//=======================================================================
+// name : onViewLeft
+// Purpose : Provides left projection of the active view
+//=======================================================================
void OCCViewer_ViewFrame::onViewLeft()
{
Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
onViewFitAll();
}
-/*!
- Provides bottom projection of the active view
-*/
+//=======================================================================
+// name : onViewBottom
+// Purpose : Provides bottom projection of the active view
+//=======================================================================
void OCCViewer_ViewFrame::onViewBottom()
{
Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
onViewFitAll();
}
-/*!
- Provides top projection of the active view
-*/
+//=======================================================================
+// name : onViewTop
+// Purpose : Provides top projection of the active view
+//=======================================================================
void OCCViewer_ViewFrame::onViewTop()
{
Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
onViewFitAll();
}
-/*!
- Display/hide Trihedron
-*/
+//=======================================================================
+// name : onViewTrihedron
+// Purpose : Display/hide Trihedron
+//=======================================================================
void OCCViewer_ViewFrame::onViewTrihedron()
{
if (!myViewer->getAISContext()->IsDisplayed( myViewer->getTrihedron() ))
onAdjustTrihedron();
}
-void OCCViewer_ViewFrame::rename( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
+//=======================================================================
+// name : rename
+// Purpose : Rename entry object
+//=======================================================================
+void OCCViewer_ViewFrame::rename( const Handle(SALOME_InteractiveObject)& IObject,
+ const QString newName )
{
myViewer->rename(IObject, newName);
}
+//=======================================================================
+// name : unHighlightAll
+// Purpose : Unhighlight all objects
+//=======================================================================
void OCCViewer_ViewFrame::unHighlightAll()
{
myViewer->unHighlightAll();
}
-void OCCViewer_ViewFrame::highlight( const Handle(SALOME_InteractiveObject)& IObject, bool highlight, bool update )
+//=======================================================================
+// name : highlight
+// Purpose : Highlight object
+//=======================================================================
+void OCCViewer_ViewFrame::highlight( const Handle(SALOME_InteractiveObject)& IObject,
+ const bool highlight,
+ const bool update )
{
- myViewer->highlight(IObject, highlight, update);
+ myViewer->highlight( IObject, highlight, update );
}
+//=======================================================================
+// name : isInViewer
+// Purpose : Magic function
+//=======================================================================
bool OCCViewer_ViewFrame::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
{
return myViewer->isInViewer( IObject );
}
+//=======================================================================
+// name : isVisible
+// Purpose : Verify whether object is visible
+//=======================================================================
bool OCCViewer_ViewFrame::isVisible( const Handle(SALOME_InteractiveObject)& IObject )
{
return myViewer->isVisible( IObject );
}
+//=======================================================================
+// name : setPopupServer
+// Purpose : Set popup server
+//=======================================================================
void OCCViewer_ViewFrame::setPopupServer( QAD_Application* App )
{
myViewer->setPopupServer( App );
}
-void OCCViewer_ViewFrame::undo(QAD_Study* theStudy, const char* StudyFrameEntry)
+//=======================================================================
+// name : redisplayAll
+// Purpose : Redisplay all objects of active component in accordance with
+// their display flags
+//=======================================================================
+void OCCViewer_ViewFrame::redisplayAll( QAD_Study* theQADStudy, const bool theToUpdate )
{
- SALOMEDS::Study_var aStudy = theStudy->getStudyDocument();
- AIS_ListOfInteractive List1;
- myViewer->getAISContext()->ObjectsInCollector(List1);
- AIS_ListIteratorOfListOfInteractive ite1(List1);
- for( ; ite1.More(); ite1.Next() )
- {
- Handle(SALOME_InteractiveObject) anObj =
- Handle(SALOME_InteractiveObject)::DownCast( ite1.Value()->GetOwner() );
-
- if ( !anObj.IsNull() &&
- anObj->hasEntry() &&
- theStudy->isInViewer( anObj->getEntry(), StudyFrameEntry) )
- {
- myViewer->getAISContext()->Display( ite1.Value() );
- }
- }
+ SALOMEDS::Study_var aStudy = theQADStudy->getStudyDocument();
+ QAD_Desktop* aDesktop = QAD_Application::getDesktop();
+ SALOMEGUI* aGUI = aDesktop->getActiveGUI();
+ const QString& aCompName = aDesktop->getComponentDataType();
+ SALOMEDS::SObject_var aComponent =
+ SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
+
+ if ( aComponent->_is_nil() )
+ return;
+
+ Handle(AIS_InteractiveContext) anIC = myViewer->getAISContext();
+ bool isTrhDisplayed = anIC->IsDisplayed( myViewer->getTrihedron() );
- AIS_ListOfInteractive List;
- myViewer->getAISContext()->DisplayedObjects(List);
- AIS_ListIteratorOfListOfInteractive ite(List);
- for ( ; ite.More(); ite.Next() )
- {
- Handle(SALOME_InteractiveObject) anObj =
- Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
+ anIC->DisplayAll( true, false );
+ anIC->EraseAll( false, false );
- if ( !anObj.IsNull() &&
- anObj->hasEntry() &&
- theStudy->isInViewer( anObj->getEntry(), StudyFrameEntry) )
+ if ( isTrhDisplayed )
+ anIC->Display( myViewer->getTrihedron(), false );
+
+ std::list<SALOMEDS::SObject_var> aList;
+ SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
+
+ std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
+ for ( ; anIter != aList.end(); ++anIter )
+ {
+ SALOMEDS::SObject_var anObj = (*anIter);
+ if ( ToolsGUI::GetVisibility( aStudy, anObj, this ) )
{
- myViewer->getAISContext()->Erase( ite.Value(), true, true );
+ Handle(SALOME_InteractiveObject) anIObj = new SALOME_InteractiveObject();
+ anIObj->setEntry( anObj->GetID() );
+ aGUI->BuildPresentation( anIObj, this );
}
}
+
+ if ( theToUpdate )
+ Repaint();
}
-void OCCViewer_ViewFrame::redo(QAD_Study* theStudy, const char* StudyFrameEntry)
+//=======================================================================
+// name : undo
+// Purpose : Redisplay all objects of active component in accordance with
+// their display flags. Called when undo operation is complited
+//=======================================================================
+void OCCViewer_ViewFrame::undo( QAD_Study* theQADStudy, const char* )
{
- SALOMEDS::Study_var aStudy = theStudy->getStudyDocument();
- SALOMEDS::SObject_var RefSO;
- SALOMEDS::SObject_var SO = aStudy->FindObjectID( StudyFrameEntry );
- SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
- for (; it->More();it->Next()){
- SALOMEDS::SObject_var CSO= it->Value();
- if (CSO->ReferencedObject(RefSO))
- {
- AIS_ListOfInteractive List;
- myViewer->getAISContext()->ObjectsInCollector(List);
-
- AIS_ListIteratorOfListOfInteractive ite(List);
- for ( ; ite.More(); ite.Next() )
- {
- Handle(SALOME_InteractiveObject) anObj =
- Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
-
- if ( !anObj.IsNull() && anObj->hasEntry() && strcmp( anObj->getEntry(), RefSO->GetID() ) == 0 )
- myViewer->getAISContext()->Display( ite.Value(), false );
- }
- }
- }
-
- AIS_ListOfInteractive List1;
- myViewer->getAISContext()->DisplayedObjects(List1);
- AIS_ListIteratorOfListOfInteractive ite1(List1);
- for ( ; ite1.More(); ite1.Next() )
- {
- Handle(SALOME_InteractiveObject) anObj =
- Handle(SALOME_InteractiveObject)::DownCast( ite1.Value()->GetOwner() );
+ redisplayAll( theQADStudy );
+}
- if ( !anObj.IsNull() && anObj->hasEntry() && !theStudy->isInViewer( anObj->getEntry(), StudyFrameEntry ) )
- myViewer->getAISContext()->Erase( ite1.Value(), false, true );
- }
-
- Repaint();
+//=======================================================================
+// name : redo
+// Purpose : Redisplay all objects of active component in accordance with
+// their display flags. Called when undo operation is complited
+//=======================================================================
+void OCCViewer_ViewFrame::redo( QAD_Study* theQADStudy, const char* )
+{
+ redisplayAll( theQADStudy );
}
-/* selection */
-Handle(SALOME_InteractiveObject) OCCViewer_ViewFrame::FindIObject(const char* Entry)
+//=======================================================================
+// name : FindIObject
+// Purpose : Find in context SALOME_InteractiveObject by entry
+//=======================================================================
+Handle(SALOME_InteractiveObject) OCCViewer_ViewFrame::FindIObject( const char* Entry )
{
Handle (AIS_InteractiveContext) ic = myViewer->getAISContext();
AIS_ListOfInteractive List;
- ic->DisplayedObjects(List);
+ ic->DisplayedObjects( List );
AIS_ListOfInteractive List1;
- ic->ObjectsInCollector(List1);
- List.Append(List1);
+ ic->ObjectsInCollector( List1 );
+ List.Append( List1 );
- AIS_ListIteratorOfListOfInteractive ite(List);
+ AIS_ListIteratorOfListOfInteractive ite( List );
for ( ; ite.More(); ite.Next() )
{
Handle(SALOME_InteractiveObject) anObj =
return Handle(SALOME_InteractiveObject)();
}
-/* display */
-void OCCViewer_ViewFrame::Display(const Handle(SALOME_InteractiveObject)& IObject, bool update)
+//=======================================================================
+// name : Display
+// Purpose : Display object
+//=======================================================================
+void OCCViewer_ViewFrame::Display( const Handle(SALOME_InteractiveObject)& theIObject,
+ bool toUpdate )
{
- QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
- SALOME_Selection* Sel
- = SALOME_Selection::Selection( myStudy->getSelection() );
+ if ( theIObject.IsNull() )
+ return;
- Handle (AIS_InteractiveContext) ic = myViewer->getAISContext();
+ QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
+ SALOME_Selection* aSel = SALOME_Selection::Selection( aQADStudy->getSelection() );
+ SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
- AIS_ListOfInteractive List;
- ic->DisplayedObjects(List);
- AIS_ListOfInteractive List1;
- ic->ObjectsInCollector(List1);
- List.Append(List1);
-
- AIS_ListIteratorOfListOfInteractive ite( List );
- for ( ; ite.More(); ite.Next() )
+ Handle(AIS_InteractiveContext) anIC = myViewer->getAISContext();
+
+ AIS_ListOfInteractive aList;
+ anIC->ObjectsInCollector( aList );
+ AIS_ListIteratorOfListOfInteractive anIter( aList );
+ for ( ; anIter.More(); anIter.Next() )
{
Handle(SALOME_InteractiveObject) anObj =
- Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
+ Handle(SALOME_InteractiveObject)::DownCast( anIter.Value()->GetOwner() );
- if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( IObject ) )
+ if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( theIObject ) )
{
- ic->Display( ite.Value(), false );
- Sel->AddIObject( anObj, false );
+ anIC->Display( anIter.Value(), false );
+ aSel->AddIObject( anObj, false );
+ ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
break;
}
}
- if ( update )
+ if ( toUpdate )
Repaint();
}
-void OCCViewer_ViewFrame::DisplayOnly(const Handle(SALOME_InteractiveObject)& IObject)
+//=======================================================================
+// name : DisplayOnly
+// Purpose : Display object and erase all other ones
+//=======================================================================
+void OCCViewer_ViewFrame::DisplayOnly( const Handle(SALOME_InteractiveObject)& theIO )
{
- QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
- SALOME_Selection* Sel
- = SALOME_Selection::Selection( myStudy->getSelection() );
+ EraseAll();
+ Display( theIO );
+}
- Handle (AIS_InteractiveContext) ic = myViewer->getAISContext();
+//=======================================================================
+// name : Erase
+// Purpose : Erase object
+//=======================================================================
+void OCCViewer_ViewFrame::Erase( const Handle(SALOME_InteractiveObject)& theIObject,
+ bool toUpdate )
+{
+ QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
+ SALOME_Selection* aSel = SALOME_Selection::Selection( aStudy->getSelection() );
+
+ Handle(AIS_InteractiveContext) anIC = myViewer->getAISContext();
- AIS_ListOfInteractive List;
- ic->DisplayedObjects(List);
- AIS_ListOfInteractive List1;
- ic->ObjectsInCollector(List1);
- List.Append(List1);
+ AIS_ListOfInteractive aList;
+ anIC->DisplayedObjects( aList );
- AIS_ListIteratorOfListOfInteractive ite( List );
+ AIS_ListIteratorOfListOfInteractive ite( aList );
for ( ; ite.More(); ite.Next() )
{
Handle(SALOME_InteractiveObject) anObj =
if ( !anObj.IsNull() && anObj->hasEntry() )
{
- if ( !anObj->isSame( IObject ) )
+ if ( anObj->isSame( theIObject ) )
{
- ic->Erase( ite.Value(), false );
- Sel->RemoveIObject( anObj, false );
- }
- else
- {
- ic->Display( ite.Value(), false );
- Sel->AddIObject( anObj, false );
+ anIC->Erase( ite.Value(), false );
+ aSel->RemoveIObject( anObj, false );
+ ToolsGUI::SetVisibility( aStudy->getStudyDocument(), anObj->getEntry(), false, this );
+ break;
}
}
}
-
- Repaint();
+
+ if ( toUpdate )
+ Repaint();
}
-void OCCViewer_ViewFrame::Erase(const Handle(SALOME_InteractiveObject)& IObject, bool update)
+
+//=======================================================================
+// name : DisplayAll
+// Purpose : Display all objects of active component
+//=======================================================================
+void OCCViewer_ViewFrame::DisplayAll()
{
- QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
- SALOME_Selection* Sel
- = SALOME_Selection::Selection( myStudy->getSelection() );
+ SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
+ QAD_Desktop* aDesktop = QAD_Application::getDesktop();
+ SALOMEGUI* aGUI = aDesktop->getActiveGUI();
+ const QString& aCompName = aDesktop->getComponentDataType();
+ SALOMEDS::SObject_var aComponent =
+ SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
+
+ if ( aComponent->_is_nil() )
+ return;
- Handle (AIS_InteractiveContext) ic = myViewer->getAISContext();
-
- AIS_ListOfInteractive List;
- ic->DisplayedObjects(List);
-
- AIS_ListIteratorOfListOfInteractive ite( List );
- for ( ; ite.More(); ite.Next() )
+ Handle(AIS_InteractiveContext) anIC = myViewer->getAISContext();
+
+ AIS_ListOfInteractive aDispList;
+ AIS_ListOfInteractive aCollList;
+ anIC->DisplayedObjects( aDispList );
+ anIC->ObjectsInCollector( aCollList );
+
+ QMap< QString, Handle(AIS_InteractiveObject) > aDispMap;
+ QMap< QString, Handle(AIS_InteractiveObject) > aCollMap;
+ getMapOfEntry( aDispList, aDispMap );
+ getMapOfEntry( aCollList, aCollMap );
+
+ std::list<SALOMEDS::SObject_var> aList;
+ SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
+
+ std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
+ for ( ; anIter != aList.end(); ++anIter )
{
- Handle(SALOME_InteractiveObject) anObj =
- Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
+ SALOMEDS::SObject_var anObj = (*anIter);
+ if ( anObj->_is_nil() )
+ continue;
- if ( !anObj.IsNull() && anObj->hasEntry() )
+ const char* aEntry = anObj->GetID();
+ if ( aCollMap.contains( aEntry ) )
{
- if ( anObj->isSame( IObject ) )
- {
- ic->Erase( ite.Value(), false );
- Sel->RemoveIObject( anObj, false );
- break;
- }
+ anIC->DisplayFromCollector( aCollMap[ aEntry ], false );
+ ToolsGUI::SetVisibility( aStudy, aEntry, true, this );
+ }
+ else if ( !aDispMap.contains( aEntry ) )
+ {
+ Handle(SALOME_InteractiveObject) anIObj = new SALOME_InteractiveObject();
+ anIObj->setEntry( anObj->GetID() );
+ aGUI->BuildPresentation( anIObj, this );
}
}
-
- if ( update )
- Repaint();
-}
-void OCCViewer_ViewFrame::DisplayAll()
-{
- myViewer->getAISContext()->DisplayAll(Standard_False,Standard_True);
+ Repaint();
}
+
+//=======================================================================
+// name : EraseAll
+// Purpose : Erase all objects
+//=======================================================================
void OCCViewer_ViewFrame::EraseAll()
{
- Standard_Boolean isTrihedronDisplayed =
+ SALOMEDS::Study_var aStudy =
+ QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
+
+ Standard_Boolean isTrihedronDisplayed =
myViewer->getAISContext()->IsDisplayed( myViewer->getTrihedron() );
- myViewer->getAISContext()->EraseAll();
- if (isTrihedronDisplayed)
+
+ Handle(AIS_InteractiveContext) anIC = myViewer->getAISContext();
+
+ AIS_ListOfInteractive aList;
+ anIC->DisplayedObjects( aList );
+ AIS_ListIteratorOfListOfInteractive anIter( aList );
+ for ( ; anIter.More(); anIter.Next() )
+ {
+ if ( anIC->IsDisplayed( myViewer->getTrihedron() ) &&
+ anIter.Value()->DynamicType() == STANDARD_TYPE( AIS_Trihedron ) )
+ continue;
+
+ Handle(AIS_InteractiveObject) anIO = anIter.Value();
+ anIC->Erase( anIO, false, true );
+
+ Handle(SALOME_InteractiveObject) anObj =
+ Handle(SALOME_InteractiveObject)::DownCast( anIO->GetOwner() );
+
+ if ( !anObj.IsNull() && anObj->hasEntry() )
+ ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), false, this );
+ }
+
+ if ( isTrihedronDisplayed )
myViewer->getAISContext()->Display( myViewer->getTrihedron() );
else
Repaint();
}
-
-
+//=======================================================================
+// name : Repaint
+// Purpose : Uodate view
+//=======================================================================
void OCCViewer_ViewFrame::Repaint()
{
onAdjustTrihedron();
myViewer->getViewer3d()->Update();
}
-//==========================================================
-/*!
- * OCCViewer_ViewFrame::getTrihedronSize
- * Get new an current trihedron size
- */
-//==========================================================
+//=======================================================================
+// name : getTrihedronSize
+// Purpose : Get new and current trihedron size corresponding to the
+// current model size
+//=======================================================================
bool OCCViewer_ViewFrame::getTrihedronSize( double& theNewSize, double& theSize )
{
theNewSize = 100;
if ( view3d.IsNull() )
return false;
-
+
double Xmin = 0, Ymin = 0, Zmin = 0, Xmax = 0, Ymax = 0, Zmax = 0;
double aMaxSide;
- double aPercents;
view3d->View()->MinMaxValues( Xmin, Ymin, Zmin, Xmax, Ymax, Zmax );
fabs( theNewSize - theSize) > theNewSize * EPS;
}
+//=======================================================================
+// name : AdjustTrihedrons
+// Purpose : Adjust trihedron size in accordance with size of model
+//=======================================================================
void OCCViewer_ViewFrame::AdjustTrihedrons( const bool forced )
{
Handle (AIS_InteractiveContext) ic = myViewer->getAISContext();
myViewer->setTrihedronSize( aNewSize );
}
+//=======================================================================
+// name : onAdjustTrihedron
+// Purpose : Slot. Called when trihedrons must be resized
+//=======================================================================
void OCCViewer_ViewFrame::onAdjustTrihedron()
{
AdjustTrihedrons( false );
}
-//==========================================================
-/*!
- * OCCViewer_ViewFrame::Display
- * Display presentation
- */
-//==========================================================
+//=======================================================================
+// name : Display
+// Purpose : Display presentation
+//=======================================================================
void OCCViewer_ViewFrame::Display( const SALOME_OCCPrs* prs )
{
// try do downcast object
// get all displayed objects
AIS_ListOfInteractive List;
ic->DisplayedObjects( List );
- // get objects in he collector
+ // get objects in the collector
AIS_ListOfInteractive ListCollector;
ic->ObjectsInCollector( ListCollector );
anOCCPrs->GetObjects( anAISObjects );
AIS_ListIteratorOfListOfInteractive aIter( anAISObjects );
- for ( ; aIter.More(); aIter.Next() ) {
+ for ( ; aIter.More(); aIter.Next() )
+ {
Handle(AIS_InteractiveObject) anAIS = aIter.Value();
- if ( !anAIS.IsNull() ) {
+ if ( !anAIS.IsNull() )
+ {
// try to find presentation in the viewer
bool bDisplayed = false;
AIS_ListIteratorOfListOfInteractive ite( List );
- while ( ite.More() ) {
- // compare presentations by handles
- // if the object is already displayed - nothing to do more
- if ( ite.Value() == anAIS ) {
-
- // Deactivate object if necessary
- if ( !anOCCPrs->ToActivate() )
- ic->Deactivate( anAIS );
- bDisplayed = true;
- break;
- }
- ite.Next();
+ for ( ; ite.More(); ite.Next() )
+ {
+ // compare presentations by handles
+ // if the object is already displayed - nothing to do more
+ if ( ite.Value() == anAIS )
+ {
+ // Deactivate object if necessary
+ if ( !anOCCPrs->ToActivate() )
+ ic->Deactivate( anAIS );
+ bDisplayed = true;
+ break;
+ }
}
+
if ( bDisplayed )
- continue;
+ continue;
+
// then try to find presentation in the collector
bDisplayed = false;
ite.Initialize( ListCollector );
- while ( ite.More() ) {
- // compare presentations by handles
- // if the object is in collector - display it
- if ( ite.Value() == anAIS ) {
- ic->DisplayFromCollector( anAIS, false );
-
- // Deactivate object if necessary
- if ( !anOCCPrs->ToActivate() )
- ic->Deactivate( anAIS );
- bDisplayed = true;
- break;
- }
- ite.Next();
+ for ( ; ite.More(); ite.Next() )
+ {
+ // compare presentations by handles
+ // if the object is in collector - display it
+ if ( ite.Value() == anAIS )
+ {
+ ic->DisplayFromCollector( anAIS, false );
+
+ // Deactivate object if necessary
+ if ( !anOCCPrs->ToActivate() )
+ ic->Deactivate( anAIS );
+ bDisplayed = true;
+
+ // Set visibility flag
+ Handle(SALOME_InteractiveObject) anObj =
+ Handle(SALOME_InteractiveObject)::DownCast( anAIS->GetOwner() );
+ if ( !anObj.IsNull() && anObj->hasEntry() )
+ {
+ SALOMEDS::Study_var aStudy =
+ QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
+ ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
+ }
+
+ break;
+ }
}
if ( bDisplayed )
- continue;
+ continue;
+
// if object is not displayed and not found in the collector - display it
if ( anAIS->IsKind( STANDARD_TYPE(AIS_Trihedron) ) )
{
getTrihedronSize( aNewSize, aSize );
aTrh->SetSize( aTrh == myViewer->getTrihedron() ? aNewSize : 0.5 * aNewSize );
}
-
+
ic->Display( anAIS, false );
+ // Set visibility flag
+ Handle(SALOME_InteractiveObject) anObj =
+ Handle(SALOME_InteractiveObject)::DownCast( anAIS->GetOwner() );
+ if ( !anObj.IsNull() && anObj->hasEntry() )
+ {
+ SALOMEDS::Study_var aStudy =
+ QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
+ ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
+ }
+
// Deactivate object if necessary
if ( !anOCCPrs->ToActivate() )
ic->Deactivate( anAIS );
}
}
-//==========================================================
-/*!
- * OCCViewer_ViewFrame::Erase
- * Erase presentation
- */
-//==========================================================
+//=======================================================================
+// name : Erase
+// Purpose : Erase presentation
+//=======================================================================
void OCCViewer_ViewFrame::Erase( const SALOME_OCCPrs* prs, const bool forced )
{
// try do downcast object
if ( !anAIS.IsNull() ) {
// erase the object from context : move it to collector
ic->Erase( anAIS, false, forced ? false : true );
+
+ // Set visibility flag if necessary
+ if ( !forced )
+ {
+ Handle(SALOME_InteractiveObject) anObj =
+ Handle(SALOME_InteractiveObject)::DownCast( anAIS->GetOwner() );
+ if ( !anObj.IsNull() && anObj->hasEntry() )
+ {
+ SALOMEDS::Study_var aStudy =
+ QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
+ ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
+ }
+ }
}
}
}
-//==========================================================
-/*!
- * OCCViewer_ViewFrame::CreatePrs
- * Create presentation by entry
- */
-//==========================================================
+//=======================================================================
+// name : CreatePrs
+// Purpose : Create presentation corresponding to the entry
+//=======================================================================
SALOME_Prs* OCCViewer_ViewFrame::CreatePrs( const char* entry )
{
OCCViewer_Prs* prs = new OCCViewer_Prs();
return prs;
}
-//==========================================================
-/*!
- * OCCViewer_ViewFrame::LocalSelection
- * Activates selection of sub shapes
- */
-//==========================================================
+//=======================================================================
+// name : LocalSelection
+// Purpose : Activates selection of sub shapes
+//=======================================================================
void OCCViewer_ViewFrame::LocalSelection( const SALOME_OCCPrs* thePrs, const int theMode )
{
Handle(AIS_InteractiveContext) anIC = myViewer->getAISContext();
}
}
-//==========================================================
-/*!
- * OCCViewer_ViewFrame::GlobalSelection
- * Deactivates selection of sub shapes
- */
-//==========================================================
+//=======================================================================
+// name : GlobalSelection
+// Purpose : Deactivates selection of sub shapes
+//=======================================================================
void OCCViewer_ViewFrame::GlobalSelection( const bool update ) const
{
Handle(AIS_InteractiveContext) anIC = myViewer->getAISContext();
anIC->CurrentViewer()->Redraw();
}
-//==========================================================
-/*!
- * OCCViewer_ViewFrame::BeforeDisplay
- * Axiluary method called before displaying of objects
- */
-//==========================================================
+//=======================================================================
+// name : BeforeDisplay
+// Purpose : Axiluary method called before displaying of objects
+//=======================================================================
void OCCViewer_ViewFrame::BeforeDisplay( SALOME_Displayer* d )
{
d->BeforeDisplay( this, SALOME_OCCViewType() );
}
-//==========================================================
-/*!
- * OCCViewer_ViewFrame::AfterDisplay
- * Axiluary method called after displaying of objects
- */
-//==========================================================
-void OCCViewer_ViewFrame::AfterDisplay( SALOME_Displayer* d )
+//=======================================================================
+// name : AfterDisplay
+// Purpose : Axiluary method called after displaying of objects
+//=======================================================================
+void OCCViewer_ViewFrame::AfterDisplay( SALOME_Displayer* d )
{
d->AfterDisplay( this, SALOME_OCCViewType() );
}
+#define INCREMENT_FOR_OP 10
+
+//=======================================================================
+// name : onPanLeft
+// Purpose : Performs incremental panning to the left
+//=======================================================================
+void OCCViewer_ViewFrame::onPanLeft()
+{
+ myViewPort->incrementalPan( -INCREMENT_FOR_OP, 0 );
+}
+
+//=======================================================================
+// name : onPanRight
+// Purpose : Performs incremental panning to the right
+//=======================================================================
+void OCCViewer_ViewFrame::onPanRight()
+{
+ myViewPort->incrementalPan( INCREMENT_FOR_OP, 0 );
+}
+
+//=======================================================================
+// name : onPanUp
+// Purpose : Performs incremental panning to the top
+//=======================================================================
+void OCCViewer_ViewFrame::onPanUp()
+{
+ myViewPort->incrementalPan( 0, INCREMENT_FOR_OP );
+}
+
+//=======================================================================
+// name : onPanDown
+// Purpose : Performs incremental panning to the bottom
+//=======================================================================
+void OCCViewer_ViewFrame::onPanDown()
+{
+ myViewPort->incrementalPan( 0, -INCREMENT_FOR_OP );
+}
+
+//=======================================================================
+// name : onZoomIn
+// Purpose : Performs incremental zooming in
+//=======================================================================
+void OCCViewer_ViewFrame::onZoomIn()
+{
+ myViewPort->incrementalZoom( INCREMENT_FOR_OP );
+}
+
+//=======================================================================
+// name : onZoomOut
+// Purpose : Performs incremental zooming out
+//=======================================================================
+void OCCViewer_ViewFrame::onZoomOut()
+{
+ myViewPort->incrementalZoom( -INCREMENT_FOR_OP );
+}
+
+//=======================================================================
+// name : onRotateLeft
+// Purpose : Performs incremental rotating to the left
+//=======================================================================
+void OCCViewer_ViewFrame::onRotateLeft()
+{
+ myViewPort->incrementalRotate( -INCREMENT_FOR_OP, 0 );
+}
+
+//=======================================================================
+// name : onRotateRight
+// Purpose : Performs incremental rotating to the right
+//=======================================================================
+void OCCViewer_ViewFrame::onRotateRight()
+{
+ myViewPort->incrementalRotate( INCREMENT_FOR_OP, 0 );
+}
+
+//=======================================================================
+// name : onRotateUp
+// Purpose : Performs incremental rotating to the top
+//=======================================================================
+void OCCViewer_ViewFrame::onRotateUp()
+{
+ myViewPort->incrementalRotate( 0, -INCREMENT_FOR_OP );
+}
+
+//=======================================================================
+// name : onRotateDown
+// Purpose : Performs incremental rotating to the bottom
+//=======================================================================
+void OCCViewer_ViewFrame::onRotateDown()
+{
+ myViewPort->incrementalRotate( 0, INCREMENT_FOR_OP );
+}