1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

Integration of OCCT 6.5.0 from SVN

This commit is contained in:
bugmaster
2011-03-16 07:30:28 +00:00
committed by bugmaster
parent 4903637061
commit 7fd59977df
16375 changed files with 3882564 additions and 0 deletions

View File

@@ -0,0 +1,566 @@
#include "ApplicationCommon.h"
#include "DocumentCommon.h"
#include "View.h"
#include <QFrame>
#include <QVBoxLayout>
#include <QMenuBar>
#include <QStatusBar>
#include <QWorkspace>
#include <QMessageBox>
#include <QApplication>
#include <QSignalMapper>
#include <stdlib.h>
static ApplicationCommonWindow* stApp;
static QWorkspace* stWs;
ApplicationCommonWindow::ApplicationCommonWindow()
: QMainWindow( 0 ),
myWindowPopup( 0 ),
myFilePopup( 0 ),
myCasCadeBar( 0 ),
myStdToolBar( 0 )
{
myNbDocuments = 0;
stApp = this;
myIsDocuments = false;
// create and define the central widget
QFrame* vb = new QFrame( this );
QVBoxLayout *layout = new QVBoxLayout( vb );
layout->setMargin( 0 );
vb->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
stWs = new QWorkspace( vb );
layout->addWidget( stWs );
setCentralWidget( vb );
createStandardOperations();
createCasCadeOperations();
statusBar()->showMessage( QObject::tr("INF_READY"), 5000 );
resize( 1000, 700 );
}
ApplicationCommonWindow::~ApplicationCommonWindow()
{
}
void ApplicationCommonWindow::createStandardOperations()
{
QPixmap newIcon, helpIcon, closeIcon;
QString dir = getResourceDir() + QString( "/" );
newIcon = QPixmap( dir+QObject::tr("ICON_NEW") );
helpIcon = QPixmap( dir+QObject::tr("ICON_HELP") );
closeIcon = QPixmap( dir+QObject::tr("ICON_CLOSE") );
QAction * fileNewAction, * fileCloseAction, * fileQuitAction,
* viewToolAction, * viewStatusAction,
* helpAboutAction;
fileNewAction = new QAction( newIcon, QObject::tr("MNU_NEW"), this );
fileNewAction->setToolTip( QObject::tr("TBR_NEW") );
fileNewAction->setStatusTip( QObject::tr("TBR_NEW") );
fileNewAction->setShortcut( QObject::tr("CTRL+N") );
connect( fileNewAction, SIGNAL( activated() ) , this, SLOT( onNewDoc() ) );
myStdActions.insert( FileNewId, fileNewAction );
fileCloseAction = new QAction( closeIcon, QObject::tr("MNU_CLOSE"), this );
fileCloseAction->setToolTip( QObject::tr("TBR_CLOSE") );
fileCloseAction->setStatusTip( QObject::tr("TBR_CLOSE") );
fileCloseAction->setShortcut( QObject::tr("CTRL+W") );
connect( fileCloseAction, SIGNAL( activated() ) , this, SLOT( onCloseWindow() ) );
myStdActions.insert( FileCloseId, fileCloseAction );
fileQuitAction = new QAction( QObject::tr("MNU_QUIT"), this );
fileQuitAction->setToolTip( QObject::tr("TBR_QUIT") );
fileQuitAction->setStatusTip( QObject::tr("TBR_QUIT") );
fileQuitAction->setShortcut( QObject::tr("CTRL+Q") );
connect( fileQuitAction, SIGNAL( activated() ) , qApp, SLOT( closeAllWindows() ) );
myStdActions.insert( FileQuitId, fileQuitAction );
viewToolAction = new QAction( QObject::tr("MNU_TOOL_BAR"), this );
viewToolAction->setToolTip( QObject::tr("TBR_TOOL_BAR") );
viewToolAction->setStatusTip( QObject::tr("TBR_TOOL_BAR") );
connect( viewToolAction, SIGNAL( activated() ) , this, SLOT( onViewToolBar() ));
viewToolAction->setCheckable( true );
viewToolAction->setChecked( true );
myStdActions.insert( ViewToolId, viewToolAction );
viewStatusAction = new QAction( QObject::tr("MNU_STATUS_BAR"), this );
viewStatusAction->setToolTip( QObject::tr("TBR_STATUS_BAR") );
viewStatusAction->setStatusTip( QObject::tr("TBR_STATUS_BAR") );
connect( viewStatusAction, SIGNAL( activated() ), this, SLOT( onViewStatusBar() ));
viewStatusAction->setCheckable( true );
viewStatusAction->setChecked( true );
myStdActions.insert( ViewStatusId, viewStatusAction );
helpAboutAction = new QAction( helpIcon, QObject::tr("MNU_ABOUT"), this );
helpAboutAction->setToolTip( QObject::tr( "TBR_ABOUT" ) );
helpAboutAction->setStatusTip( QObject::tr( "TBR_ABOUT" ) );
helpAboutAction->setShortcut( QObject::tr( "F1" ) );
connect( helpAboutAction, SIGNAL( activated() ) , this, SLOT( onAbout() ) );
myStdActions.insert( HelpAboutId, helpAboutAction );
// popuplate a menu with all actions
myFilePopup = new QMenu( this );
myFilePopup = menuBar()->addMenu( QObject::tr("MNU_FILE") );
myFilePopup->addAction( fileNewAction );
myFilePopup->addAction( fileCloseAction );
myFileSeparator = myFilePopup->addSeparator();
myFilePopup->addAction( fileQuitAction );
// add a view menu
QMenu * view = new QMenu( this );
view = menuBar()->addMenu( QObject::tr("MNU_VIEW") );
view->addAction( viewToolAction );
view->addAction( viewStatusAction );
// add a help menu
QMenu * help = new QMenu( this );
menuBar()->addSeparator();
help = menuBar()->addMenu( QObject::tr("MNU_HELP") );
help->addAction( helpAboutAction );
// populate a tool bar with some actions
myStdToolBar = addToolBar( tr( "File Operations" ) );
myStdToolBar->addAction( fileNewAction );
myStdToolBar->addAction( helpAboutAction );
myStdActions.at(FileCloseId)->setEnabled(myDocuments.count() > 0);
}
void ApplicationCommonWindow::createCasCadeOperations()
{
createWindowPopup();
// populate a tool bar with some actions
myCasCadeBar = addToolBar( tr( "Shape Operations" ) );
QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" );
QAction* a;
a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_WIRE") ), QObject::tr("MNU_TOOL_WIRE"), this );
a->setToolTip( QObject::tr("TBR_TOOL_WIRE") );
a->setStatusTip( QObject::tr("TBR_TOOL_WIRE") );
connect( a, SIGNAL( activated() ) , this, SLOT( onToolAction() ) );
myToolActions.insert( ToolWireframeId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_SHAD") ), QObject::tr("MNU_TOOL_SHAD"), this );
a->setToolTip( QObject::tr("TBR_TOOL_SHAD") );
a->setStatusTip( QObject::tr("TBR_TOOL_SHAD") );
connect( a, SIGNAL( activated() ) , this, SLOT( onToolAction() ) );
myToolActions.insert( ToolShadingId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_COLOR") ), QObject::tr("MNU_TOOL_COLOR"), this );
a->setToolTip( QObject::tr("TBR_TOOL_COLOR") );
a->setStatusTip( QObject::tr("TBR_TOOL_COLOR") );
connect( a, SIGNAL( activated() ) , this, SLOT( onToolAction() ) );
myToolActions.insert( ToolColorId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_MATER") ), QObject::tr("MNU_TOOL_MATER"), this );
a->setToolTip( QObject::tr("TBR_TOOL_MATER") );
a->setStatusTip( QObject::tr("TBR_TOOL_MATER") );
connect( a, SIGNAL( activated() ) , this, SLOT( onToolAction() ) );
myToolActions.insert( ToolMaterialId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_TRANS") ), QObject::tr("MNU_TOOL_TRANS"), this );
a->setToolTip( QObject::tr("TBR_TOOL_TRANS") );
a->setStatusTip( QObject::tr("TBR_TOOL_TRANS") );
connect( a, SIGNAL( activated() ) , this, SLOT( onToolAction() ) );
myToolActions.insert( ToolTransparencyId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_DEL") ), QObject::tr("MNU_TOOL_DEL"), this );
a->setToolTip( QObject::tr("TBR_TOOL_DEL") );
a->setStatusTip( QObject::tr("TBR_TOOL_DEL") );
connect( a, SIGNAL( activated() ) , this, SLOT( onToolAction() ) );
myToolActions.insert( ToolDeleteId, a );
QSignalMapper* sm = new QSignalMapper( this );
connect( sm, SIGNAL( mapped( int ) ), this, SLOT( onSetMaterial( int ) ) );
a = new QAction( QObject::tr("MNU_BRASS"), this );
a->setToolTip( QObject::tr("TBR_BRASS") );
a->setStatusTip( QObject::tr("TBR_BRASS") );
sm->setMapping( a,(int)Graphic3d_NOM_BRASS );
connect( a, SIGNAL( activated() ), sm, SLOT( map() ) );
myMaterialActions.insert( Graphic3d_NOM_BRASS, a );
a = new QAction( QObject::tr("MNU_BRONZE"), this );
a->setToolTip( QObject::tr("TBR_BRONZE") );
a->setStatusTip( QObject::tr("TBR_BRONZE") );
sm->setMapping( a, ( int )Graphic3d_NOM_BRONZE );
connect( a, SIGNAL( activated() ), sm, SLOT( map() ) );
myMaterialActions.insert( Graphic3d_NOM_BRONZE, a );
a = new QAction( QObject::tr("MNU_COPPER"), this );
a->setToolTip( QObject::tr("TBR_COPPER") );
a->setStatusTip( QObject::tr("TBR_COPER") );
sm->setMapping( a, ( int )Graphic3d_NOM_COPPER );
connect( a, SIGNAL( activated() ), sm, SLOT( map() ) );
myMaterialActions.insert( Graphic3d_NOM_COPPER, a );
a = new QAction( QObject::tr("MNU_GOLD"), this );
a->setToolTip( QObject::tr("TBR_GOLD") );
a->setStatusTip( QObject::tr("TBR_GOLD") );
sm->setMapping( a, ( int )Graphic3d_NOM_GOLD );
connect( a, SIGNAL( activated() ), sm, SLOT( map() ) );
myMaterialActions.insert( Graphic3d_NOM_GOLD, a );
a = new QAction( QObject::tr("MNU_PEWTER"), this );
a->setToolTip( QObject::tr("TBR_PEWTER") );
a->setStatusTip( QObject::tr("TBR_PEWTER") );
sm->setMapping( a, ( int )Graphic3d_NOM_PEWTER );
connect( a, SIGNAL( activated() ), sm, SLOT( map() ) );
myMaterialActions.insert( Graphic3d_NOM_PEWTER, a );
a = new QAction( QObject::tr("MNU_PLASTER"), this );
a->setToolTip( QObject::tr("TBR_PLASTER") );
a->setStatusTip( QObject::tr("TBR_PLASTER") );
sm->setMapping( a, ( int )Graphic3d_NOM_PLASTER );
connect( a, SIGNAL( activated() ), sm, SLOT( map() ) );
myMaterialActions.insert( Graphic3d_NOM_PLASTER, a );
a = new QAction( QObject::tr("MNU_PLASTIC"), this );
a->setToolTip( QObject::tr("TBR_PLASTIC") );
a->setStatusTip( QObject::tr("TBR_PLASTIC") );
sm->setMapping( a, ( int )Graphic3d_NOM_PLASTIC );
connect( a, SIGNAL( activated() ), sm, SLOT( map() ) );
myMaterialActions.insert( Graphic3d_NOM_PLASTIC, a );
a = new QAction( QObject::tr("MNU_SILVER"), this );
a->setToolTip( QObject::tr("TBR_SILVER") );
a->setStatusTip( QObject::tr("TBR_SILVER") );
sm->setMapping( a, ( int )Graphic3d_NOM_SILVER );
connect( a, SIGNAL( activated() ), sm, SLOT( map() ) );
myMaterialActions.insert( Graphic3d_NOM_SILVER, a );
for ( int i = 0; i < myToolActions.size(); i++ )
myCasCadeBar->addAction( myToolActions.at( i ) );
myCasCadeBar->hide();
}
QList<QAction*>* ApplicationCommonWindow::getToolActions()
{
return &myToolActions;
}
QList<QAction*>* ApplicationCommonWindow::getMaterialActions()
{
return &myMaterialActions;
}
void ApplicationCommonWindow::createWindowPopup()
{
if ( !myWindowPopup )
{
myWindowPopup = new QMenu( QObject::tr( "MNU_WINDOW" ), this );
connect( myWindowPopup, SIGNAL( aboutToShow() ),
this, SLOT( windowsMenuAboutToShow() ) );
}
}
void ApplicationCommonWindow::windowsMenuAboutToShow()
{
myWindowPopup->clear();
QAction* a;
QString dir = getResourceDir() + QString( "/" );
a = new QAction( QPixmap( dir + QObject::tr( "ICON_WINDOW_NEW3D" ) ), QObject::tr( "MNU_WINDOW_NEW3D" ), this );
a->setToolTip( QObject::tr( "TBR_WINDOW_NEW3D" ) );
a->setStatusTip( QObject::tr( "TBR_WINDOW_NEW3D" ) );
connect( a, SIGNAL( activated() ), this, SLOT( onCreateNewView() ) );
myWindowPopup->addAction( a );
a = new QAction( QPixmap( dir + QObject::tr( "ICON_WINDOW_CASCADE" ) ), QObject::tr( "MNU_WINDOW_CASCADE" ), this );
a->setToolTip( QObject::tr( "TBR_WINDOW_CASCADE" ) );
a->setStatusTip( QObject::tr( "TBR_WINDOW_CASCADE" ) );
connect( a, SIGNAL( activated() ), stWs, SLOT( cascade() ) );
myWindowPopup->addAction( a );
a = new QAction( QPixmap( dir + QObject::tr( "ICON_WINDOW_TILE" ) ), QObject::tr( "MNU_WINDOW_TILE" ), this );
a->setToolTip( QObject::tr( "TBR_WINDOW_TILE" ) );
a->setStatusTip( QObject::tr( "TBR_WINDOW_TILE" ) );
connect( a, SIGNAL( activated() ), stWs, SLOT( tile() ) );
myWindowPopup->addAction( a );
myWindowPopup->addSeparator();
QWidgetList windows = stWs->windowList();
for ( uint i = 0; i < windows.count(); ++i )
{
QAction* aAction = new QAction( windows.at(i)->windowTitle(), this );
aAction->setCheckable( true );
aAction->setData( i );
myWindowPopup->addAction( aAction );
connect( aAction, SIGNAL( toggled( bool ) ), this, SLOT( windowsMenuActivated( bool ) ) );
aAction->setChecked( stWs->activeWindow() == windows.at(i) );
}
}
void ApplicationCommonWindow::windowsMenuActivated( bool checked )
{
QAction* aSender = qobject_cast<QAction*>( sender() );
if ( !aSender )
return;
QWidget* w = stWs->windowList().at( aSender->data().toInt() );
if ( w && checked )
w->setFocus();
}
QWorkspace * ApplicationCommonWindow::getWorkspace()
{
return stWs;
}
ApplicationCommonWindow* ApplicationCommonWindow::getApplication()
{
return stApp;
}
void ApplicationCommonWindow::updateFileActions()
{
if ( stWs->windowList().isEmpty() )
{
if ( !myIsDocuments )
{
QAction *fileQuitAction, *windowAction;
QList<QAction *> aListActions = myFilePopup->actions();
for ( int i = 0; i < aListActions.size(); i++ )
{
if( aListActions.at( i )->text() == QObject::tr("MNU_QUIT") )
{
fileQuitAction = aListActions.at( i );
break;
}
}
if( !fileQuitAction )
return;
myIsDocuments = true;
myCasCadeBar->show();
QList<QAction *> aListMenuActions = menuBar()->actions();
for ( int i = 0; i < aListMenuActions.size(); i++ )
{
if( aListMenuActions.at( i )->text() == QObject::tr("MNU_HELP") )
{
windowAction= aListMenuActions.at( i );
break;
}
}
if( !windowAction )
return;
menuBar()->insertMenu( windowAction, myWindowPopup );
}
else
{
myIsDocuments = false;
myCasCadeBar->hide();
menuBar()->removeAction( myWindowPopup->menuAction() );
}
}
}
DocumentCommon* ApplicationCommonWindow::createNewDocument()
{
return new DocumentCommon( ++myNbDocuments, this );
}
int& ApplicationCommonWindow::getNbDocument()
{
return myNbDocuments;
}
DocumentCommon* ApplicationCommonWindow::onNewDoc()
{
updateFileActions();
DocumentCommon* aDoc = createNewDocument();
aDoc->onCreateNewView();
onSelectionChanged();
connect( aDoc, SIGNAL( sendCloseDocument( DocumentCommon* ) ),
this, SLOT( onCloseDocument( DocumentCommon* ) ) );
connect( stWs, SIGNAL( windowActivated( QWidget* ) ),
this, SLOT( onWindowActivated( QWidget* ) ) );
connect( aDoc, SIGNAL( selectionChanged() ),
this, SLOT( onSelectionChanged() ) );
myDocuments.append( aDoc );
myStdActions.at( FileCloseId )->setEnabled( myDocuments.count() > 0 );
return aDoc;
}
void ApplicationCommonWindow::onCloseWindow(){
MDIWindow* m = (MDIWindow*)stWs->activeWindow();
if ( m )
{
DocumentCommon* doc = m->getDocument();
onCloseDocument( doc );
}
}
void ApplicationCommonWindow::onCloseDocument(DocumentCommon* theDoc)
{
myDocuments.removeAll( theDoc );
theDoc->removeViews();
delete theDoc;
updateFileActions();
myStdActions.at(FileCloseId)->setEnabled(myDocuments.count() > 0);
}
void ApplicationCommonWindow::onViewToolBar()
{
bool show = myStdActions.at( ViewToolId )->isChecked();
if ( show == myStdToolBar->isVisible() )
return;
if ( show )
myStdToolBar->show();
else
myStdToolBar->hide();
}
void ApplicationCommonWindow::onViewStatusBar()
{
bool show = myStdActions.at( ViewStatusId )->isChecked();
if ( show == statusBar()->isVisible() )
return;
if ( show )
statusBar()->show();
else
statusBar()->hide();
}
void ApplicationCommonWindow::onAbout()
{
QMessageBox::information( this, QObject::tr( "TIT_ABOUT" ), QObject::tr( "INF_ABOUT" ), QObject::tr("BTN_OK" ),
QString::null, QString::null, 0, 0 );
}
void ApplicationCommonWindow::onCreateNewView()
{
DocumentCommon* doc = ((MDIWindow*) stWs->activeWindow())->getDocument();
doc->onCreateNewView();
}
void ApplicationCommonWindow::onWindowActivated ( QWidget * w )
{
if ( w )
((MDIWindow*) w)->onWindowActivated();
}
void ApplicationCommonWindow::onToolAction()
{
QAction* sentBy = (QAction*) sender();
QWorkspace* ws = ApplicationCommonWindow::getWorkspace();
DocumentCommon* doc = ((MDIWindow*)ws->activeWindow())->getDocument();
if( sentBy == myToolActions.at( ToolWireframeId ) )
doc->onWireframe();
if( sentBy == myToolActions.at( ToolShadingId ) )
doc->onShading();
if( sentBy == myToolActions.at( ToolColorId ) )
doc->onColor();
if( sentBy == myToolActions.at( ToolMaterialId ) )
doc->onMaterial();
if( sentBy == myToolActions.at( ToolTransparencyId ) )
doc->onTransparency();
if( sentBy == myToolActions.at( ToolDeleteId ) )
doc->onDelete();
}
void ApplicationCommonWindow::onSelectionChanged()
{
QWorkspace* ws = ApplicationCommonWindow::getWorkspace();
DocumentCommon* doc;
if( !qobject_cast<MDIWindow*>( ws->activeWindow() ) )
return;
doc = ((MDIWindow*)ws->activeWindow())->getDocument();
Handle(AIS_InteractiveContext) context = doc->getContext();
bool OneOrMoreInShading = false;
bool OneOrMoreInWireframe = false;
int numSel = context->NbSelected();
if ( numSel )
{
for ( context->InitCurrent(); context->MoreCurrent(); context->NextCurrent() )
{
if ( context->IsDisplayed( context->Current(), 1 ) )
OneOrMoreInShading = true;
if ( context->IsDisplayed( context->Current(), 0 ) )
OneOrMoreInWireframe = true;
}
myToolActions.at( ToolWireframeId )->setEnabled( OneOrMoreInShading );
myToolActions.at( ToolShadingId )->setEnabled( OneOrMoreInWireframe );
myToolActions.at( ToolColorId )->setEnabled( true );
myToolActions.at( ToolMaterialId )->setEnabled( true );
myToolActions.at( ToolTransparencyId )->setEnabled( OneOrMoreInShading );
myToolActions.at( ToolDeleteId )->setEnabled( true );
}
else
{
myToolActions.at( ToolWireframeId )->setEnabled( false );
myToolActions.at( ToolShadingId )->setEnabled( false );
myToolActions.at( ToolColorId )->setEnabled( false );
myToolActions.at( ToolMaterialId )->setEnabled( false );
myToolActions.at( ToolTransparencyId )->setEnabled( false );
myToolActions.at( ToolDeleteId )->setEnabled( false );
}
}
void ApplicationCommonWindow::onSetMaterial( int theMaterial )
{
QWorkspace* ws = getWorkspace();
DocumentCommon* doc = ((MDIWindow*)ws->activeWindow())->getDocument();
doc->onMaterial( theMaterial );
}
QString ApplicationCommonWindow::getResourceDir()
{
static QString resDir( ::getenv( "CSF_ResourcesDefaults" ) );
return resDir;
}
void ApplicationCommonWindow::resizeEvent( QResizeEvent* e )
{
QMainWindow::resizeEvent( e );
statusBar()->setSizeGripEnabled( !isMaximized() );
}
bool ApplicationCommonWindow::isDocument()
{
return myIsDocuments;
}
QMenu* ApplicationCommonWindow::getFilePopup()
{
return myFilePopup;
}
QAction* ApplicationCommonWindow::getFileSeparator()
{
return myFileSeparator;
}
QToolBar* ApplicationCommonWindow::getCasCadeBar()
{
return myCasCadeBar;
}

View File

@@ -0,0 +1,82 @@
#ifndef APPLICATIONCOMMON_H
#define APPLICATIONCOMMON_H
#include "DocumentCommon.h"
#include <QMainWindow>
#include <QAction>
#include <QToolBar>
#include <QMenu>
#include <QWorkspace>
#include <QList>
class COMMONSAMPLE_EXPORT ApplicationCommonWindow: public QMainWindow
{
Q_OBJECT
public:
enum { FileNewId, FileCloseId, FileQuitId, ViewToolId, ViewStatusId, HelpAboutId };
enum { ToolWireframeId, ToolShadingId, ToolColorId, ToolMaterialId, ToolTransparencyId, ToolDeleteId };
ApplicationCommonWindow();
~ApplicationCommonWindow();
static QWorkspace* getWorkspace();
static ApplicationCommonWindow* getApplication();
static QString getResourceDir();
virtual void updateFileActions();
QList<QAction*>* getToolActions();
QList<QAction*>* getMaterialActions();
protected:
virtual DocumentCommon* createNewDocument();
int& getNbDocument();
public slots:
DocumentCommon* onNewDoc();
void onCloseWindow();
virtual void onCloseDocument( DocumentCommon* theDoc );
virtual void onSelectionChanged();
virtual void onAbout();
void onViewToolBar();
void onViewStatusBar();
void onToolAction();
void onCreateNewView();
void onWindowActivated ( QWidget * w );
void windowsMenuAboutToShow();
void windowsMenuActivated( bool checked/*int id*/ );
void onSetMaterial( int theMaterial );
protected:
virtual void resizeEvent( QResizeEvent* );
bool isDocument();
QMenu* getFilePopup();
QAction* getFileSeparator();
QToolBar* getCasCadeBar();
private:
void createStandardOperations();
void createCasCadeOperations();
void createWindowPopup();
private:
int myNbDocuments;
bool myIsDocuments;
QList<QAction*> myStdActions;
QList<QAction*> myToolActions;
QList<QAction*> myMaterialActions;
QList<DocumentCommon*> myDocuments;
QToolBar* myStdToolBar;
QToolBar* myCasCadeBar;
QMenu* myFilePopup;
QMenu* myWindowPopup;
QAction* myFileSeparator;
};
#endif

View File

@@ -0,0 +1,130 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS><TS version="1.1">
<context>
<name>QObject</name>
<message>
<source>ICON_VIEW_PAN</source>
<translation>view_pan.png</translation>
</message>
<message>
<source>ICON_VIEW_TOP</source>
<translation>view_top.png</translation>
</message>
<message>
<source>ICON_VIEW_AXO</source>
<translation>view_axo.png</translation>
</message>
<message>
<source>ICON_CURSOR_ZOOM</source>
<translation>cursor_zoom.png</translation>
</message>
<message>
<source>ICON_WINDOW_TILE</source>
<translation>tile.png</translation>
</message>
<message>
<source>ICON_VIEW_ZOOM</source>
<translation>view_zoom.png</translation>
</message>
<message>
<source>ICON_VIEW_BACK</source>
<translation>view_back.png</translation>
</message>
<message>
<source>ICON_VIEW_LEFT</source>
<translation>view_left.png</translation>
</message>
<message>
<source>ICON_VIEW_GLOBALPAN</source>
<translation>view_glpan.png</translation>
</message>
<message>
<source>ICON_CLOSE</source>
<translation>close.png</translation>
</message>
<message>
<source>ICON_HELP</source>
<translation>help.png</translation>
</message>
<message>
<source>ICON_TOOL_TRANS</source>
<translation>tool_transparency.png</translation>
</message>
<message>
<source>ICON_TOOL_COLOR</source>
<translation>tool_color.png</translation>
</message>
<message>
<source>ICON_TOOL_MATER</source>
<translation>tool_material.png</translation>
</message>
<message>
<source>ICON_WINDOW_CASCADE</source>
<translation>cascade.png</translation>
</message>
<message>
<source>ICON_VIEW_BOTTOM</source>
<translation>view_bottom.png</translation>
</message>
<message>
<source>ICON_VIEW_HLROFF</source>
<translation>view_comp_off.png</translation>
</message>
<message>
<source>ICON_VIEW_FITALL</source>
<translation>view_fitall.png</translation>
</message>
<message>
<source>ICON_CURSOR_ROTATE</source>
<translation>cursor_rotate.png</translation>
</message>
<message>
<source>ICON_DOC</source>
<translation>document.png</translation>
</message>
<message>
<source>ICON_NEW</source>
<translation>new.png</translation>
</message>
<message>
<source>ICON_VIEW_RIGHT</source>
<translation>view_right.png</translation>
</message>
<message>
<source>ICON_VIEW_RESET</source>
<translation>view_reset.png</translation>
</message>
<message>
<source>ICON_VIEW_HLRON</source>
<translation>view_comp_on.png</translation>
</message>
<message>
<source>ICON_VIEW_FRONT</source>
<translation>view_front.png</translation>
</message>
<message>
<source>ICON_VIEW_ROTATION</source>
<translation>view_rotate.png</translation>
</message>
<message>
<source>ICON_TOOL_SHAD</source>
<translation>tool_shading.png</translation>
</message>
<message>
<source>ICON_TOOL_WIRE</source>
<translation>tool_wireframe.png</translation>
</message>
<message>
<source>ICON_VIEW_FITAREA</source>
<translation>view_fitarea.png</translation>
</message>
<message>
<source>ICON_TOOL_DEL</source>
<translation>tool_delete.png</translation>
</message>
<message>
<source>ICON_SAMPLE</source>
<translation>lamp.png</translation>
</message>
</context>
</TS>

View File

@@ -0,0 +1,414 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS><TS version="1.1">
<context>
<name>QObject</name>
<message>
<source>TBR_ROTATION</source>
<translation>Dynamic Rotation</translation>
</message>
<message>
<source>MNU_GLOBALPAN</source>
<translation>&amp;Global Panning</translation>
</message>
<message>
<source>MNU_ROTATION</source>
<translation>&amp;Dynamic Rotation</translation>
</message>
<message>
<source>MNU_AXO</source>
<translation>&amp;Axo</translation>
</message>
<message>
<source>MNU_NEW</source>
<translation>&amp;New</translation>
</message>
<message>
<source>MNU_PAN</source>
<translation>&amp;Dynamic Panning</translation>
</message>
<message>
<source>MNU_TOP</source>
<translation>&amp;Top</translation>
</message>
<message>
<source>MNU_TOOL_SHAD</source>
<translation>&amp;Shading</translation>
</message>
<message>
<source>MNU_TOOL_WIRE</source>
<translation>&amp;Wireframe</translation>
</message>
<message>
<source>TBR_BOTTOM</source>
<translation>Bottom</translation>
</message>
<message>
<source>MNU_BOTTOM</source>
<translation>&amp;Bottom</translation>
</message>
<message>
<source>BTN_BRONZE</source>
<translation>Bronze</translation>
</message>
<message>
<source>MNU_BRONZE</source>
<translation>&amp;Bronze</translation>
</message>
<message>
<source>TBR_BRONZE</source>
<translation>Bronze</translation>
</message>
<message>
<source>BTN_COPPER</source>
<translation>Copper</translation>
</message>
<message>
<source>MNU_COPPER</source>
<translation>&amp;Copper</translation>
</message>
<message>
<source>TBR_COPPER</source>
<translation>Copper</translation>
</message>
<message>
<source>MNU_TOOL_COLOR</source>
<translation>&amp;Color</translation>
</message>
<message>
<source>MNU_TOOL_MATER</source>
<translation>&amp;Material</translation>
</message>
<message>
<source>TBR_FITALL</source>
<translation>FitAll</translation>
</message>
<message>
<source>MNU_FITALL</source>
<translation>&amp;FilAll</translation>
</message>
<message>
<source>MNU_BACK</source>
<translation>&amp;Back</translation>
</message>
<message>
<source>MNU_FILE</source>
<translation>&amp;File</translation>
</message>
<message>
<source>MNU_GOLD</source>
<translation>&amp;Gold</translation>
</message>
<message>
<source>MNU_HELP</source>
<translation>&amp;Help</translation>
</message>
<message>
<source>MNU_LEFT</source>
<translation>&amp;Left</translation>
</message>
<message>
<source>MNU_QUIT</source>
<translation>&amp;Quit</translation>
</message>
<message>
<source>MNU_VIEW</source>
<translation>&amp;View</translation>
</message>
<message>
<source>MNU_ZOOM</source>
<translation>&amp;Dynamic Zooming</translation>
</message>
<message>
<source>MNU_HLROFF</source>
<translation>&amp;Hidden Off</translation>
</message>
<message>
<source>TBR_HLROFF</source>
<translation>Hidden Off</translation>
</message>
<message>
<source>MNU_TOOL_TRANS</source>
<translation>&amp;Transpatency</translation>
</message>
<message>
<source>BTN_BRASS</source>
<translation>Brass</translation>
</message>
<message>
<source>BTN_PEWTER</source>
<translation>Pewter</translation>
</message>
<message>
<source>TBR_PEWTER</source>
<translation>Pewter</translation>
</message>
<message>
<source>MNU_PEWTER</source>
<translation>&amp;Pewter</translation>
</message>
<message>
<source>MNU_SILVER</source>
<translation>&amp;Silver</translation>
</message>
<message>
<source>BTN_OK</source>
<translation>Ok</translation>
</message>
<message>
<source>TBR_SILVER</source>
<translation>Silver</translation>
</message>
<message>
<source>BTN_SILVER</source>
<translation>Silver</translation>
</message>
<message>
<source>INF_NULL_SHAPE</source>
<translation>Select the shape to export.</translation>
</message>
<message>
<source>MNU_WINDOW</source>
<translation>&amp;Window</translation>
</message>
<message>
<source>TBR_WINDOW</source>
<translation>Window</translation>
</message>
<message>
<source>BTN_PLASTIC</source>
<translation>Plastic</translation>
</message>
<message>
<source>BTN_PLASTER</source>
<translation>Plaster</translation>
</message>
<message>
<source>MNU_PLASTIC</source>
<translation>&amp;Plastic</translation>
</message>
<message>
<source>MNU_PLASTER</source>
<translation>&amp;Plaster</translation>
</message>
<message>
<source>TBR_PLASTIC</source>
<translation>Plastic</translation>
</message>
<message>
<source>TBR_PLASTER</source>
<translation>Plaster</translation>
</message>
<message>
<source>MNU_TOOL_BAR</source>
<translation>&amp;Toolbar</translation>
</message>
<message>
<source>MNU_TOOL_DEL</source>
<translation>&amp;Delete</translation>
</message>
<message>
<source>TBR_BACK</source>
<translation>Back</translation>
</message>
<message>
<source>TBR_GOLD</source>
<translation>Gold</translation>
</message>
<message>
<source>TBR_LEFT</source>
<translation>Left</translation>
</message>
<message>
<source>TBR_QUIT</source>
<translation>Quit</translation>
</message>
<message>
<source>TBR_VIEW</source>
<translation>View</translation>
</message>
<message>
<source>TBR_ZOOM</source>
<translation>Dynamic Zooming</translation>
</message>
<message>
<source>MNU_CH_BACK</source>
<translation>&amp;Change Background</translation>
</message>
<message>
<source>TBR_CH_BACK</source>
<translation>Change Background</translation>
</message>
<message>
<source>TBR_TOOL_COLOR</source>
<translation>Color</translation>
</message>
<message>
<source>TBR_TOOL_MATER</source>
<translation>Material</translation>
</message>
<message>
<source>TBR_TOOL_BAR</source>
<translation>Toolbar</translation>
</message>
<message>
<source>TBR_TOOL_DEL</source>
<translation>Delete</translation>
</message>
<message>
<source>TBR_TOOL_TRANS</source>
<translation>Transparency</translation>
</message>
<message>
<source>TBR_ABOUT</source>
<translation>About</translation>
</message>
<message>
<source>TBR_BRASS</source>
<translation>Brass</translation>
</message>
<message>
<source>TBR_CLOSE</source>
<translation>Close</translation>
</message>
<message>
<source>TBR_FRONT</source>
<translation>Front</translation>
</message>
<message>
<source>TBR_HLRON</source>
<translation>Hidden On</translation>
</message>
<message>
<source>TBR_MATER</source>
<translation>Material</translation>
</message>
<message>
<source>TBR_RIGHT</source>
<translation>Right</translation>
</message>
<message>
<source>TBR_RESET</source>
<translation>Reset</translation>
</message>
<message>
<source>TBR_AXO</source>
<translation>Axo</translation>
</message>
<message>
<source>TBR_NEW</source>
<translation>New</translation>
</message>
<message>
<source>TBR_PAN</source>
<translation>Dynamic Panning</translation>
</message>
<message>
<source>TBR_TOP</source>
<translation>Top</translation>
</message>
<message>
<source>TIT_INF</source>
<translation>Info</translation>
</message>
<message>
<source>BTN_GOLD</source>
<translation>Gold</translation>
</message>
<message>
<source>TBR_WINDOW_NEW3D</source>
<translation>New 3d View</translation>
</message>
<message>
<source>MNU_WINDOW_NEW3D</source>
<translation>&amp;New 3d View</translation>
</message>
<message>
<source>MNU_STATUS_BAR</source>
<translation>&amp;Statusbar</translation>
</message>
<message>
<source>TIT_ERROR</source>
<translation>Error</translation>
</message>
<message>
<source>TBR_FITAREA</source>
<translation>Zoom Window</translation>
</message>
<message>
<source>MNU_FITAREA</source>
<translation>&amp;Zoom Window</translation>
</message>
<message>
<source>TBR_GLOBALPAN</source>
<translation>Global Panning</translation>
</message>
<message>
<source>MNU_ABOUT</source>
<translation>&amp;About</translation>
</message>
<message>
<source>MNU_BRASS</source>
<translation>&amp;Brass</translation>
</message>
<message>
<source>MNU_CLOSE</source>
<translation>&amp;Close</translation>
</message>
<message>
<source>MNU_FRONT</source>
<translation>&amp;Front</translation>
</message>
<message>
<source>MNU_HLRON</source>
<translation>&amp;Hidden On</translation>
</message>
<message>
<source>MNU_MATER</source>
<translation>&amp;Material</translation>
</message>
<message>
<source>MNU_RIGHT</source>
<translation>&amp;Right</translation>
</message>
<message>
<source>MNU_RESET</source>
<translation>&amp;Reset</translation>
</message>
<message>
<source>INF_ABOUT</source>
<translation>Qt based application for tutorial to Open CASCADE Technology</translation>
</message>
<message>
<source>INF_READY</source>
<translation>Ready</translation>
</message>
<message>
<source>TBR_TOOL_SHAD</source>
<translation>Shading</translation>
</message>
<message>
<source>TBR_TOOL_WIRE</source>
<translation>Wireframe</translation>
</message>
<message>
<source>TBR_WINDOW_TILE</source>
<translation>Tile</translation>
</message>
<message>
<source>TBR_STATUS_BAR</source>
<translation>Statusbar</translation>
</message>
<message>
<source>MNU_WINDOW_CASCADE</source>
<translation>Cascade</translation>
</message>
<message>
<source>TBR_WINDOW_CASCADE</source>
<translation>&amp;Cascade</translation>
</message>
<message>
<source>MNU_WINDOW_TILE</source>
<translation>&amp;Tile</translation>
</message>
</context>
</TS>

View File

@@ -0,0 +1,22 @@
#ifndef COMMONSAMPLE_H
#define COMMONSAMPLE_H
#ifndef NO_COMMONSAMPLE_EXPORTS
#ifdef COMMONSAMPLE_EXPORTS
#ifdef WIN32
#define COMMONSAMPLE_EXPORT __declspec( dllexport )
#else
#define COMMONSAMPLE_EXPORT
#endif
#else
#ifdef WIN32
#define COMMONSAMPLE_EXPORT __declspec( dllimport )
#else
#define COMMONSAMPLE_EXPORT
#endif
#endif
#else
#define COMMONSAMPLE_EXPORT
#endif
#endif

View File

@@ -0,0 +1,234 @@
#include "DocumentCommon.h"
#include "ApplicationCommon.h"
#include "Transparency.h"
#include "Material.h"
#include <QStatusBar>
#include <QApplication>
#include <QColor>
#include <QColorDialog>
#ifndef WNT
#include <Graphic3d_GraphicDevice.hxx>
#else
#include <Graphic3d_WNTGraphicDevice.hxx>
#endif
#include <AIS_InteractiveObject.hxx>
#include <Graphic3d_NameOfMaterial.hxx>
Handle(V3d_Viewer) DocumentCommon::Viewer( const Standard_CString aDisplay,
const Standard_ExtString aName,
const Standard_CString aDomain,
const Standard_Real ViewSize,
const V3d_TypeOfOrientation ViewProj,
const Standard_Boolean ComputedMode,
const Standard_Boolean aDefaultComputedMode )
{
#ifndef WNT
static Handle(Graphic3d_GraphicDevice) defaultdevice;
if( defaultdevice.IsNull() )
defaultdevice = new Graphic3d_GraphicDevice( aDisplay );
return new V3d_Viewer(defaultdevice,aName,aDomain,ViewSize,ViewProj,
Quantity_NOC_GRAY30,V3d_ZBUFFER,V3d_GOURAUD,V3d_WAIT,
ComputedMode,aDefaultComputedMode,V3d_TEX_NONE);
#else
static Handle(Graphic3d_WNTGraphicDevice) defaultdevice;
if( defaultdevice.IsNull() )
defaultdevice = new Graphic3d_WNTGraphicDevice();
return new V3d_Viewer(defaultdevice,aName,aDomain,ViewSize,ViewProj,
Quantity_NOC_GRAY30,V3d_ZBUFFER,V3d_GOURAUD,V3d_WAIT,
ComputedMode,aDefaultComputedMode,V3d_TEX_NONE);
#endif
}
DocumentCommon::DocumentCommon( const int theIndex, ApplicationCommonWindow* app )
: QObject( app ),
myApp( app ),
myIndex( theIndex ),
myNbViews( 0 )
{
TCollection_ExtendedString a3DName("Visu3D");
myViewer = Viewer( getenv("DISPLAY"), a3DName.ToExtString(), "", 1000.0,
V3d_XposYnegZpos, Standard_True, Standard_True );
myViewer->Init();
myViewer->SetDefaultLights();
myViewer->SetLightOn();
myContext =new AIS_InteractiveContext(myViewer);
//onCreateNewView();
}
DocumentCommon::~DocumentCommon()
{
}
ApplicationCommonWindow* DocumentCommon::getApplication()
{
return myApp;
}
MDIWindow* DocumentCommon::createNewMDIWindow()
{
QWorkspace* ws = myApp->getWorkspace();
return new MDIWindow( this, ws, 0 );
}
void DocumentCommon::onCreateNewView()
{
QWorkspace* ws = myApp->getWorkspace();
MDIWindow* w = createNewMDIWindow();
if( !w )
return;
ws->addWindow( w );
myViews.append(w);
connect( w, SIGNAL( selectionChanged() ),
this, SIGNAL( selectionChanged() ) );
connect( w, SIGNAL( message( const QString&, int ) ),
myApp->statusBar(), SLOT( message( const QString&, int ) ) );
connect( w, SIGNAL( sendCloseView( MDIWindow* ) ),
this, SLOT( onCloseView( MDIWindow* ) ) );
QString aName;
w->setWindowTitle( aName.sprintf( "Document %d:%d", myIndex, ++myNbViews ) );
QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" );
w->setWindowIcon( QPixmap( dir + QObject::tr("ICON_DOC") ) );
if ( ws->windowList().isEmpty() )
{
// Due to strange Qt4.2.3 feature the child window icon is not drawn
// in the main menu if showMaximized() is called for a non-visible child window
// Therefore calling show() first...
w->show();
w->showMaximized();
}
else
w->show();
w->setFocus();
getApplication()->onSelectionChanged();
}
void DocumentCommon::onCloseView(MDIWindow* theView)
{
removeView(theView);
if( countOfWindow() == 0 )
emit sendCloseDocument( this );
}
void DocumentCommon::removeView(MDIWindow* theView)
{
if ( myViews.count( theView ) )
{
myViews.removeAll(theView);
delete theView;
}
}
void DocumentCommon::removeViews()
{
while( myViews.count() )
removeView( (MDIWindow*)myViews.first() );
}
int DocumentCommon::countOfWindow()
{
return myViews.count();
}
Handle(AIS_InteractiveContext) DocumentCommon::getContext()
{
return myContext;
}
void DocumentCommon::fitAll()
{
QList<MDIWindow*>::iterator i;
for ( i = myViews.begin(); i != myViews.end(); i++ )
(*i)->fitAll();
}
void DocumentCommon::onWireframe()
{
QApplication::setOverrideCursor( Qt::WaitCursor );
for( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextCurrent() )
myContext->SetDisplayMode( myContext->Current(), 0, false );
myContext->UpdateCurrentViewer();
getApplication()->onSelectionChanged();
QApplication::restoreOverrideCursor();
}
void DocumentCommon::onShading()
{
QApplication::setOverrideCursor( Qt::WaitCursor );
for( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextCurrent() )
myContext->SetDisplayMode( myContext->Current(), 1, false );
myContext->UpdateCurrentViewer();
getApplication()->onSelectionChanged();
QApplication::restoreOverrideCursor();
}
void DocumentCommon::onColor()
{
QColor aColor ;
Quantity_Color aShapeColor;
myContext->InitCurrent();
Handle_AIS_InteractiveObject Current = myContext->Current() ;
if ( Current->HasColor () )
{
aShapeColor = myContext->Color( Current );
aColor.setRgb( aShapeColor.Red() * 255, aShapeColor.Green() * 255, aShapeColor.Blue() * 255 );
}
else
aColor.setRgb( 255, 255, 255 );
QColor aRetColor = QColorDialog::getColor( aColor );
if ( aRetColor.isValid() )
{
Quantity_Color color( aRetColor.red() / 255., aRetColor.green() / 255.,
aRetColor.blue() / 255., Quantity_TOC_RGB );
for (; myContext->MoreCurrent(); myContext->NextCurrent() )
myContext->SetColor( myContext->Current(), color.Name() );
}
}
void DocumentCommon::onMaterial( int theMaterial )
{
for ( myContext->InitCurrent(); myContext->MoreCurrent (); myContext->NextCurrent () )
myContext->SetMaterial( myContext->Current(), (Graphic3d_NameOfMaterial)theMaterial );
}
void DocumentCommon::onMaterial()
{
DialogMaterial* m = new DialogMaterial();
connect( m, SIGNAL( sendMaterialChanged( int ) ), this, SLOT( onMaterial( int ) ) );
m->exec();
}
void DocumentCommon::onTransparency( int theTrans )
{
for( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextSelected() )
myContext->SetTransparency( myContext->Current(), ((Standard_Real)theTrans) / 10.0 );
}
void DocumentCommon::onTransparency()
{
DialogTransparency* aDialog = new DialogTransparency();
connect( aDialog, SIGNAL( sendTransparencyChanged( int ) ), this, SLOT( onTransparency( int ) ) );
aDialog->exec();
}
void DocumentCommon::onDelete()
{
for ( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextCurrent() )
myContext->Erase( myContext->Current(), false, true );
myContext->ClearSelected();
getApplication()->onSelectionChanged();
}

View File

@@ -0,0 +1,69 @@
#ifndef DOCUMENTCOMMON_H
#define DOCUMENTCOMMON_H
#include "MDIWindow.h"
//#include "IESample.h"
#include <QObject>
#include <QList>
#include <AIS_InteractiveContext.hxx>
#include <V3d_Viewer.hxx>
class ApplicationCommonWindow;
class COMMONSAMPLE_EXPORT DocumentCommon : public QObject
{
Q_OBJECT
public:
DocumentCommon( const int, ApplicationCommonWindow* );
~DocumentCommon();
ApplicationCommonWindow* getApplication();
Handle(AIS_InteractiveContext) getContext();
void removeView( MDIWindow* );
void removeViews();
int countOfWindow();
void fitAll();
protected:
virtual MDIWindow* createNewMDIWindow();
signals:
void selectionChanged();
void sendCloseDocument( DocumentCommon* );
public slots:
virtual void onCloseView( MDIWindow* );
virtual void onCreateNewView();
virtual void onMaterial();
virtual void onMaterial( int );
virtual void onDelete();
void onWireframe();
void onShading();
void onColor();
void onTransparency();
void onTransparency( int );
private:
Handle(V3d_Viewer) Viewer( const Standard_CString aDisplay,
const Standard_ExtString aName,
const Standard_CString aDomain,
const Standard_Real ViewSize,
const V3d_TypeOfOrientation ViewProj,
const Standard_Boolean ComputedMode,
const Standard_Boolean aDefaultComputedMode );
protected:
ApplicationCommonWindow* myApp;
QList<MDIWindow*> myViews;
Handle(V3d_Viewer) myViewer;
Handle(AIS_InteractiveContext) myContext;
int myIndex;
int myNbViews;
};
#endif

View File

@@ -0,0 +1,140 @@
#include "MDIWindow.h"
#include "View.h"
#include "DocumentCommon.h"
#include "ApplicationCommon.h"
#include <QFrame>
#include <QToolBar>
#include <QFileDialog>
#include <QMessageBox>
#include <QApplication>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QMainWindow>
#include <QVBoxLayout>
MDIWindow::MDIWindow(View* aView,
DocumentCommon* aDocument,
QWidget* parent,
Qt::WindowFlags wflags )
: QMainWindow( parent, wflags )
{
myView = aView;
myDocument = aDocument;
}
MDIWindow::MDIWindow( DocumentCommon* aDocument, QWidget* parent, Qt::WindowFlags wflags )
: QMainWindow( parent, wflags )
{
QFrame *vb = new QFrame( this );
QVBoxLayout *layout = new QVBoxLayout( vb );
layout->setMargin( 0 );
vb->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
setCentralWidget( vb );
myDocument = aDocument;
myView = new View( myDocument->getContext(), vb );
layout->addWidget( myView );
connect( myView, SIGNAL( selectionChanged() ),
this, SIGNAL( selectionChanged() ) );
createViewActions();
resize( sizeHint() );
setFocusPolicy( Qt::StrongFocus );
}
MDIWindow::~MDIWindow()
{
}
DocumentCommon* MDIWindow::getDocument()
{
return myDocument;
}
void MDIWindow::closeEvent(QCloseEvent* e)
{
emit sendCloseView(this);
}
void MDIWindow::fitAll()
{
myView->fitAll();
}
void MDIWindow::createViewActions()
{
// populate a tool bar with some actions
QToolBar* aToolBar = addToolBar( tr( "View Operations" ) );
QList<QAction*>* aList = myView->getViewActions();
aToolBar->addActions( *aList );
aToolBar->toggleViewAction()->setVisible(false);
aList->at(View::ViewHlrOffId)->setChecked( true );
}
void MDIWindow::onWindowActivated ()
{
getDocument()->getApplication()->onSelectionChanged();
}
void MDIWindow::dump()
{
QString datadir = (QString(getenv("CASROOT")) + "/../data/images");
static QString filter;
filter = "Images Files (*.bmp *.gif *.xwd *.ps *.eps *.tex *.pdf *.svg *.pgf)";
QFileDialog fd ( 0 );
fd.setModal( true );
fd.setFilter( filter );
fd.setWindowTitle( QObject::tr("INF_APP_EXPORT") );
fd.setFileMode( QFileDialog::AnyFile );
int ret = fd.exec();
/* update the desktop after the dialog is closed */
qApp->processEvents();
QStringList fileNames;
fileNames = fd.selectedFiles();
QString file ( (ret == QDialog::Accepted && !fileNames.isEmpty() )? fileNames[0] : QString::null);
if ( !file.isNull() )
{
QApplication::setOverrideCursor( Qt::WaitCursor );
if ( !QFileInfo( file ).completeSuffix().length() )
file += QString( ".bmp" );
bool res = myView->dump( (Standard_CString)file.toLatin1().constData() );
QApplication::restoreOverrideCursor();
if ( !res )
{
QWidgetList list = qApp->allWidgets();
QWidget* mainWidget;
for( int i = 0; i < list.size(); ++i )
{
if( qobject_cast<ApplicationCommonWindow*>( list.at( i ) ) )
mainWidget = qobject_cast<ApplicationCommonWindow*>( list.at( i ) );
}
QMessageBox::information ( mainWidget, QObject::tr("TIT_ERROR"), QObject::tr("INF_ERROR"), QObject::tr("BTN_OK"),
QString::null, QString::null, 0, 0 );
qApp->processEvents();
}
}
}
QSize MDIWindow::sizeHint() const
{
return QSize( 450, 300 );
}

View File

@@ -0,0 +1,42 @@
#ifndef MDIWINDOW_H
#define MDIWINDOW_H
#include <QMainWindow>
#include "CommonSample.h"
class DocumentCommon;
class View;
class COMMONSAMPLE_EXPORT MDIWindow: public QMainWindow
{
Q_OBJECT
public:
MDIWindow( DocumentCommon* aDocument, QWidget* parent, Qt::WindowFlags wflags );
MDIWindow( View* aView, DocumentCommon* aDocument, QWidget* parent, Qt::WindowFlags wflags );
~MDIWindow();
DocumentCommon* getDocument();
void fitAll();
virtual QSize sizeHint() const;
signals:
void selectionChanged();
void message(const QString&, int );
void sendCloseView(MDIWindow* theView);
public slots:
void closeEvent(QCloseEvent* e);
void onWindowActivated ();
void dump();
protected:
void createViewActions();
protected:
DocumentCommon* myDocument;
View* myView;
};
#endif

View File

@@ -0,0 +1,108 @@
#include "Material.h"
#include <QPushButton>
#include <QLayout>
#include <QSignalMapper>
#include <Graphic3d_NameOfMaterial.hxx>
DialogMaterial::DialogMaterial(QWidget * parent,
bool modal, Qt::WindowFlags f )
: QDialog(parent, f)
{
setModal( modal );
QPushButton* b;
QVBoxLayout* vbl = new QVBoxLayout( this );
vbl->setMargin( 8 );
QSignalMapper *sm = new QSignalMapper( this );
connect( sm, SIGNAL( mapped( int ) ), this, SIGNAL( sendMaterialChanged( int ) ) );
b = new QPushButton( QObject::tr("BTN_PLASTER"), this );
sm->setMapping( b, ( int )Graphic3d_NOM_PLASTER );
connect( b, SIGNAL( clicked() ), sm, SLOT( map() ) );
b->setCheckable( true );
connect( b, SIGNAL( toggled( bool ) ), this, SLOT( updateButtons( bool ) ) );
myButtons.append( b );
vbl->addWidget( b );
b = new QPushButton( QObject::tr( "BTN_BRASS" ), this );
sm->setMapping( b, ( int )Graphic3d_NOM_BRASS );
connect( b, SIGNAL( clicked() ), sm, SLOT( map() ) );
b->setCheckable( true );
connect( b, SIGNAL( toggled( bool ) ), this, SLOT( updateButtons( bool ) ) );
myButtons.append( b );
vbl->addWidget( b );
b = new QPushButton( QObject::tr( "BTN_BRONZE" ), this );
sm->setMapping( b, ( int )Graphic3d_NOM_BRONZE );
connect( b, SIGNAL( clicked() ), sm, SLOT( map() ) );
b->setCheckable( true );
connect( b, SIGNAL( toggled( bool ) ), this, SLOT( updateButtons( bool ) ) );
myButtons.append( b );
vbl->addWidget( b );
b = new QPushButton( QObject::tr( "BTN_COPPER" ), this );
sm->setMapping( b, ( int )Graphic3d_NOM_COPPER );
connect( b, SIGNAL( clicked() ), sm, SLOT( map() ) );
b->setCheckable( true );
connect( b, SIGNAL( toggled( bool ) ), this, SLOT( updateButtons( bool ) ) );
myButtons.append( b );
vbl->addWidget( b );
b = new QPushButton( QObject::tr( "BTN_GOLD" ), this );
sm->setMapping( b, ( int )Graphic3d_NOM_GOLD );
connect( b, SIGNAL( clicked() ), sm, SLOT( map() ) );
b->setCheckable( true );
connect( b, SIGNAL( toggled( bool ) ), this, SLOT( updateButtons( bool ) ) );
myButtons.append( b );
vbl->addWidget( b );
b = new QPushButton( QObject::tr( "BTN_PEWTER" ), this );
sm->setMapping( b, ( int )Graphic3d_NOM_PEWTER );
connect( b, SIGNAL( clicked() ), sm, SLOT( map() ) );
b->setCheckable( true );
connect( b, SIGNAL( toggled( bool ) ), this, SLOT( updateButtons( bool ) ) );
myButtons.append( b );
vbl->addWidget( b );
b = new QPushButton( QObject::tr( "BTN_PLASTIC" ), this );
sm->setMapping( b, ( int )Graphic3d_NOM_PLASTIC );
connect( b, SIGNAL( clicked() ), sm, SLOT( map() ) );
b->setCheckable( true );
connect( b, SIGNAL( toggled( bool ) ), this, SLOT( updateButtons( bool ) ) );
myButtons.append( b );
vbl->addWidget( b );
b = new QPushButton( QObject::tr( "BTN_SILVER" ), this );
sm->setMapping( b, ( int )Graphic3d_NOM_SILVER );
connect( b, SIGNAL( clicked() ), sm, SLOT( map() ) );
b->setCheckable( true );
connect( b, SIGNAL( toggled( bool ) ), this, SLOT( updateButtons( bool ) ) );
myButtons.append( b );
vbl->addWidget( b );
}
DialogMaterial::~DialogMaterial()
{
}
void DialogMaterial::updateButtons( bool isOn )
{
if( !isOn )
return;
QPushButton*sentBy = ( QPushButton* )sender();
for ( int i = 0; i < myButtons.size(); i++ )
{
QPushButton* b = myButtons.at( i );
if( b != sentBy ) {
b->setEnabled( true );
b->setChecked( false );
} else {
b->setEnabled( false );
}
}
}

View File

@@ -0,0 +1,27 @@
#ifndef MATERIAL_H
#define MATERIAL_H
#include <QDialog>
#include <QList>
#include <QPushButton>
#include <AIS_InteractiveContext.hxx>
class DialogMaterial : public QDialog
{
Q_OBJECT
public:
DialogMaterial (QWidget * parent=0, bool modal=true, Qt::WindowFlags f=0 );
~DialogMaterial();
signals:
void sendMaterialChanged(int);
public slots:
void updateButtons(bool isOn);
private:
QList<QPushButton*> myButtons;
};
#endif

View File

@@ -0,0 +1,22 @@
#include "Transparency.h"
#include <QHBoxLayout>
#include <QSpinBox>
DialogTransparency::DialogTransparency( QWidget* parent, Qt::WindowFlags f, bool modal )
: QDialog( parent, f )
{
setModal( modal );
QHBoxLayout* base = new QHBoxLayout( this );
base->setMargin( 3 );
base->setSpacing( 3 );
QSpinBox* aSpin = new QSpinBox( this );
aSpin->setRange( 0, 10 );
aSpin->setSingleStep( 1 );
base->addWidget( aSpin );
connect( aSpin, SIGNAL( valueChanged( int ) ), this, SIGNAL( sendTransparencyChanged( int ) ) );
}
DialogTransparency::~DialogTransparency()
{
}

View File

@@ -0,0 +1,13 @@
#include <QDialog>
#include <QWidget>
#include <AIS_InteractiveContext.hxx>
class DialogTransparency : public QDialog
{
Q_OBJECT
public:
DialogTransparency ( QWidget * parent=0, Qt::WindowFlags f=0, bool modal=true );
~DialogTransparency();
signals:
void sendTransparencyChanged(int value);
};

980
samples/qt/Common/src/View.cxx Executable file
View File

@@ -0,0 +1,980 @@
#if !defined WNT
#define QT_CLEAN_NAMESPACE /* avoid definition of INT32 and INT8 */
#endif
#include "View.h"
#include "ApplicationCommon.h"
#include <QApplication>
#include <QPainter>
#include <QMenu>
#include <QColorDialog>
#include <QCursor>
#include <QFileInfo>
#include <QMouseEvent>
#include <QRubberBand>
#include <Visual3d_View.hxx>
#include <Graphic3d_ExportFormat.hxx>
#include <QWindowsStyle>
#ifdef WNT
#include <WNT_Window.hxx>
#include <Graphic3d_WNTGraphicDevice.hxx>
#else
#include <QX11Info>
#include <GL/glx.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/Xmu/StdCmap.h>
#include <X11/Xlib.h>
#include <Xw_Window.hxx>
#include <Graphic3d_GraphicDevice.hxx>
#include <QColormap>
#endif
// the key for multi selection :
#define MULTISELECTIONKEY Qt::ShiftModifier
// the key for shortcut ( use to activate dynamic rotation, panning )
#define CASCADESHORTCUTKEY Qt::ControlModifier
// for elastic bean selection
#define ValZWMin 1
static QCursor* defCursor = NULL;
static QCursor* handCursor = NULL;
static QCursor* panCursor = NULL;
static QCursor* globPanCursor = NULL;
static QCursor* zoomCursor = NULL;
static QCursor* rotCursor = NULL;
View::View( Handle(AIS_InteractiveContext) theContext, QWidget* parent )
: QWidget( parent ),
myViewActions( 0 )
{
#ifndef WNT
//XSynchronize( x11Display(),true ); // it is possible to use QApplication::syncX();
XSynchronize( x11Info().display(),true ); // it is possible to use QApplication::syncX();
#endif
myFirst = true;
myContext = theContext;
myXmin = 0;
myYmin = 0;
myXmax = 0;
myYmax = 0;
myCurZoom = 0;
myRectBand = 0;
setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_NoSystemBackground);
#if !defined WNT
XVisualInfo* pVisualInfo;
if ( x11Info().display() )
{
/* Initialization with the default VisualID */
Visual *v = DefaultVisual( x11Info().display(), DefaultScreen( x11Info().display() ) );
int visualID = XVisualIDFromVisual( v );
/* Here we use the settings from Optimizer_ViewInfo::TxglCreateWindow() */
int visualAttr[] = { GLX_RGBA, GLX_DEPTH_SIZE, 1, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, None };
pVisualInfo = ::glXChooseVisual( x11Info().display(), DefaultScreen( x11Info().display() ), visualAttr );
if ( isVisible() )
hide();
XSetWindowAttributes a;
Window p = RootWindow( x11Info().display(), DefaultScreen( x11Info().display() ) );
a.colormap = XCreateColormap( x11Info().display(), RootWindow( x11Info().display(), pVisualInfo->screen ),
pVisualInfo->visual, AllocNone );
QColor color = palette().color( backgroundRole() );
QColormap colmap = QColormap::instance();
a.background_pixel = colmap.pixel( color );
a.border_pixel = colmap.pixel( Qt::black );
if ( parentWidget() )
p = parentWidget()->winId();
Window w = XCreateWindow( x11Info().display(), p, x(), y(), width(), height(),
0, pVisualInfo->depth, InputOutput, pVisualInfo->visual,
CWBackPixel | CWBorderPixel | CWColormap, &a );
Window *cmw;
Window *cmwret;
int count;
if ( XGetWMColormapWindows( x11Info().display(), topLevelWidget()->winId(), &cmwret, &count ) )
{
cmw = new Window[count+1];
memcpy( (char *)cmw, (char *)cmwret, sizeof(Window)*count );
XFree( (char *)cmwret );
int i;
for ( i = 0; i < count; i++ )
{
if ( cmw[i] == winId() ) /* replace old window */
{
cmw[i] = w;
break;
}
}
if ( i >= count ) /* append new window */
cmw[count++] = w;
}
else
{
count = 1;
cmw = new Window[count];
cmw[0] = w;
}
/* Creating new window (with good VisualID) for this widget */
create(w);
XSetWMColormapWindows( x11Info().display(), topLevelWidget()->winId(), cmw, count );
delete [] cmw;
if ( isVisible() )
show();
if ( pVisualInfo )
XFree( (char *)pVisualInfo );
XFlush( x11Info().display() );
}
#endif
myCurrentMode = CurAction3d_Nothing;
myDegenerateModeIsOn = Standard_True;
setMouseTracking( true );
initViewActions();
initCursors();
}
View::~View()
{
}
void View::init()
{
if(myView.IsNull())
myView = myContext->CurrentViewer()->CreateView();
int windowHandle = (int) winId();
short hi, lo;
lo = (short) windowHandle;
hi = (short) (windowHandle >> 16);
#ifdef WNT
Handle(WNT_Window) hWnd = new WNT_Window(Handle(Graphic3d_WNTGraphicDevice)::DownCast(myContext->CurrentViewer()->Device()),(int) hi,(int) lo);
#else
Handle(Xw_Window) hWnd = new Xw_Window(Handle(Graphic3d_GraphicDevice)::DownCast(myContext->CurrentViewer()->Device()),(int) hi,(int) lo,Xw_WQ_SAMEQUALITY);
#endif // WNT
myView->SetWindow( hWnd );
if ( !hWnd->IsMapped() )
hWnd->Map();
myView->SetBackgroundColor(Quantity_NOC_BLACK);
myView->MustBeResized();
}
void View::paintEvent( QPaintEvent * e )
{
// QApplication::syncX();
if( myFirst )
{
init();
myFirst = false;
}
myView->Redraw();
}
void View::resizeEvent( QResizeEvent * e)
{
// QApplication::syncX();
if( !myView.IsNull() )
{
myView->MustBeResized();
}
}
void View::fitAll()
{
myView->FitAll();
myView->ZFitAll();
myView->Redraw();
}
void View::fitArea()
{
myCurrentMode = CurAction3d_WindowZooming;
}
void View::zoom()
{
myCurrentMode = CurAction3d_DynamicZooming;
}
void View::pan()
{
myCurrentMode = CurAction3d_DynamicPanning;
}
void View::rotation()
{
myCurrentMode = CurAction3d_DynamicRotation;
}
void View::globalPan()
{
// save the current zoom value
myCurZoom = myView->Scale();
// Do a Global Zoom
myView->FitAll();
// Set the mode
myCurrentMode = CurAction3d_GlobalPanning;
}
void View::front()
{
myView->SetProj( V3d_Xpos );
}
void View::back()
{
myView->SetProj( V3d_Xneg );
}
void View::top()
{
myView->SetProj( V3d_Zpos );
}
void View::bottom()
{
myView->SetProj( V3d_Zneg );
}
void View::left()
{
myView->SetProj( V3d_Ypos );
}
void View::right()
{
myView->SetProj( V3d_Yneg );
}
void View::axo()
{
myView->SetProj( V3d_XposYnegZpos );
}
void View::reset()
{
myView->Reset();
}
void View::hlrOff()
{
QApplication::setOverrideCursor( Qt::WaitCursor );
myView->SetDegenerateModeOn();
myDegenerateModeIsOn = Standard_True;
QApplication::restoreOverrideCursor();
}
void View::hlrOn()
{
QApplication::setOverrideCursor( Qt::WaitCursor );
myView->SetDegenerateModeOff();
myDegenerateModeIsOn = Standard_False;
QApplication::restoreOverrideCursor();
}
void View::updateToggled( bool isOn )
{
QAction* sentBy = (QAction*)sender();
if( !isOn )
return;
for ( int i = ViewFitAllId; i < ViewHlrOffId; i++ )
{
QAction* anAction = myViewActions->at( i );
if ( ( anAction == myViewActions->at( ViewFitAreaId ) ) ||
( anAction == myViewActions->at( ViewZoomId ) ) ||
( anAction == myViewActions->at( ViewPanId ) ) ||
( anAction == myViewActions->at( ViewGlobalPanId ) ) ||
( anAction == myViewActions->at( ViewRotationId ) ) )
{
if ( anAction && ( anAction != sentBy ) )
{
anAction->setCheckable( true );
anAction->setChecked( false );
}
else
{
if ( sentBy == myViewActions->at( ViewFitAreaId ) )
setCursor( *handCursor );
else if ( sentBy == myViewActions->at( ViewZoomId ) )
setCursor( *zoomCursor );
else if ( sentBy == myViewActions->at( ViewPanId ) )
setCursor( *panCursor );
else if ( sentBy == myViewActions->at( ViewGlobalPanId ) )
setCursor( *globPanCursor );
else if ( sentBy == myViewActions->at( ViewRotationId ) )
setCursor( *rotCursor );
else
setCursor( *defCursor );
sentBy->setCheckable( false );
}
}
}
}
void View::initCursors()
{
if ( !defCursor )
defCursor = new QCursor( Qt::ArrowCursor );
if ( !handCursor )
handCursor = new QCursor( Qt::PointingHandCursor );
if ( !panCursor )
panCursor = new QCursor( Qt::SizeAllCursor );
if ( !globPanCursor )
globPanCursor = new QCursor( Qt::CrossCursor );
if ( !zoomCursor )
zoomCursor = new QCursor( QPixmap( ApplicationCommonWindow::getResourceDir() + QString( "/" ) + QObject::tr( "ICON_CURSOR_ZOOM" ) ) );
if ( !rotCursor )
rotCursor = new QCursor( QPixmap( ApplicationCommonWindow::getResourceDir() + QString( "/" ) + QObject::tr( "ICON_CURSOR_ROTATE" ) ) );
}
QList<QAction*>* View::getViewActions()
{
initViewActions();
return myViewActions;
}
void View::initViewActions()
{
if ( myViewActions )
return;
myViewActions = new QList<QAction*>();
QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" );
QAction* a;
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_FITALL") ), QObject::tr("MNU_FITALL"), this );
a->setToolTip( QObject::tr("TBR_FITALL") );
a->setStatusTip( QObject::tr("TBR_FITALL") );
connect( a, SIGNAL( activated() ) , this, SLOT( fitAll() ) );
myViewActions->insert(ViewFitAllId, a);
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_FITAREA") ), QObject::tr("MNU_FITAREA"), this );
a->setToolTip( QObject::tr("TBR_FITAREA") );
a->setStatusTip( QObject::tr("TBR_FITAREA") );
connect( a, SIGNAL( activated() ) , this, SLOT( fitArea() ) );
a->setCheckable( true );
connect( a, SIGNAL( toggled( bool ) ) , this, SLOT( updateToggled( bool ) ) );
myViewActions->insert( ViewFitAreaId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_ZOOM") ), QObject::tr("MNU_ZOOM"), this );
a->setToolTip( QObject::tr("TBR_ZOOM") );
a->setStatusTip( QObject::tr("TBR_ZOOM") );
connect( a, SIGNAL( activated() ) , this, SLOT( zoom() ) );
a->setCheckable( true );
connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
myViewActions->insert( ViewZoomId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_PAN") ), QObject::tr("MNU_PAN"), this );
a->setToolTip( QObject::tr("TBR_PAN") );
a->setStatusTip( QObject::tr("TBR_PAN") );
connect( a, SIGNAL( activated() ) , this, SLOT( pan() ) );
a->setCheckable( true );
connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
myViewActions->insert( ViewPanId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_GLOBALPAN") ), QObject::tr("MNU_GLOBALPAN"), this );
a->setToolTip( QObject::tr("TBR_GLOBALPAN") );
a->setStatusTip( QObject::tr("TBR_GLOBALPAN") );
connect( a, SIGNAL( activated() ) , this, SLOT( globalPan() ) );
a->setCheckable( true );
connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
myViewActions->insert( ViewGlobalPanId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_FRONT") ), QObject::tr("MNU_FRONT"), this );
a->setToolTip( QObject::tr("TBR_FRONT") );
a->setStatusTip( QObject::tr("TBR_FRONT") );
connect( a, SIGNAL( activated() ) , this, SLOT( front() ) );
myViewActions->insert( ViewFrontId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_BACK") ), QObject::tr("MNU_BACK"), this );
a->setToolTip( QObject::tr("TBR_BACK") );
a->setStatusTip( QObject::tr("TBR_BACK") );
connect( a, SIGNAL( activated() ) , this, SLOT( back() ) );
myViewActions->insert(ViewBackId, a);
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_TOP") ), QObject::tr("MNU_TOP"), this );
a->setToolTip( QObject::tr("TBR_TOP") );
a->setStatusTip( QObject::tr("TBR_TOP") );
connect( a, SIGNAL( activated() ) , this, SLOT( top() ) );
myViewActions->insert( ViewTopId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_BOTTOM") ), QObject::tr("MNU_BOTTOM"), this );
a->setToolTip( QObject::tr("TBR_BOTTOM") );
a->setStatusTip( QObject::tr("TBR_BOTTOM") );
connect( a, SIGNAL( activated() ) , this, SLOT( bottom() ) );
myViewActions->insert( ViewBottomId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_LEFT") ), QObject::tr("MNU_LEFT"), this );
a->setToolTip( QObject::tr("TBR_LEFT") );
a->setStatusTip( QObject::tr("TBR_LEFT") );
connect( a, SIGNAL( activated() ) , this, SLOT( left() ) );
myViewActions->insert( ViewLeftId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_RIGHT") ), QObject::tr("MNU_RIGHT"), this );
a->setToolTip( QObject::tr("TBR_RIGHT") );
a->setStatusTip( QObject::tr("TBR_RIGHT") );
connect( a, SIGNAL( activated() ) , this, SLOT( right() ) );
myViewActions->insert( ViewRightId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_AXO") ), QObject::tr("MNU_AXO"), this );
a->setToolTip( QObject::tr("TBR_AXO") );
a->setStatusTip( QObject::tr("TBR_AXO") );
connect( a, SIGNAL( activated() ) , this, SLOT( axo() ) );
myViewActions->insert( ViewAxoId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_ROTATION") ), QObject::tr("MNU_ROTATION"), this );
a->setToolTip( QObject::tr("TBR_ROTATION") );
a->setStatusTip( QObject::tr("TBR_ROTATION") );
connect( a, SIGNAL( activated() ) , this, SLOT( rotation() ) );
a->setCheckable( true );
connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
myViewActions->insert( ViewRotationId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_RESET") ), QObject::tr("MNU_RESET"), this );
a->setToolTip( QObject::tr("TBR_RESET") );
a->setStatusTip( QObject::tr("TBR_RESET") );
connect( a, SIGNAL( activated() ) , this, SLOT( reset() ) );
myViewActions->insert( ViewResetId, a );
QActionGroup* ag = new QActionGroup( this );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_HLROFF") ), QObject::tr("MNU_HLROFF"), this );
a->setToolTip( QObject::tr("TBR_HLROFF") );
a->setStatusTip( QObject::tr("TBR_HLROFF") );
connect( a, SIGNAL( activated() ) , this, SLOT( hlrOff() ) );
a->setCheckable( true );
ag->addAction(a);
myViewActions->insert(ViewHlrOffId, a);
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_HLRON") ), QObject::tr("MNU_HLRON"), this );
a->setToolTip( QObject::tr("TBR_HLRON") );
a->setStatusTip( QObject::tr("TBR_HLRON") );
connect( a, SIGNAL( activated() ) ,this, SLOT( hlrOn() ) );
a->setCheckable( true );
ag->addAction(a);
myViewActions->insert( ViewHlrOnId, a );
}
void View::mousePressEvent( QMouseEvent* e )
{
if ( e->button() == Qt::LeftButton )
onLButtonDown( ( e->buttons() | e->modifiers() ), e->pos() );
else if ( e->button() == Qt::MidButton )
onMButtonDown( e->buttons() | e->modifiers(), e->pos() );
else if ( e->button() == Qt::RightButton )
onRButtonDown( e->buttons() | e->modifiers(), e->pos() );
}
void View::mouseReleaseEvent(QMouseEvent* e)
{
if ( e->button() == Qt::LeftButton )
onLButtonUp( e->buttons(), e->pos() );
else if ( e->button() == Qt::MidButton )
onMButtonUp( e->buttons(), e->pos() );
else if( e->button() == Qt::RightButton )
onRButtonUp( e->buttons(), e->pos() );
}
void View::mouseMoveEvent(QMouseEvent* e)
{
onMouseMove( e->buttons(), e->pos() );
}
void View::activateCursor( const CurrentAction3d mode )
{
switch( mode )
{
case CurAction3d_DynamicPanning:
setCursor( *panCursor );
break;
case CurAction3d_DynamicZooming:
setCursor( *zoomCursor );
break;
case CurAction3d_DynamicRotation:
setCursor( *rotCursor );
break;
case CurAction3d_GlobalPanning:
setCursor( *globPanCursor );
break;
case CurAction3d_WindowZooming:
setCursor( *handCursor );
break;
case CurAction3d_Nothing:
default:
setCursor( *defCursor );
break;
}
}
void View::onLButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint point )
{
// save the current mouse coordinate in min
myXmin = point.x();
myYmin = point.y();
myXmax = point.x();
myYmax = point.y();
if ( nFlags & CASCADESHORTCUTKEY )
{
myCurrentMode = CurAction3d_DynamicZooming;
}
else
{
switch ( myCurrentMode )
{
case CurAction3d_Nothing:
if ( nFlags & MULTISELECTIONKEY )
MultiDragEvent( myXmax, myYmax, -1 );
else
DragEvent( myXmax, myYmax, -1 );
break;
case CurAction3d_DynamicZooming:
break;
case CurAction3d_WindowZooming:
break;
case CurAction3d_DynamicPanning:
break;
case CurAction3d_GlobalPanning:
break;
case CurAction3d_DynamicRotation:
if ( !myDegenerateModeIsOn )
myView->SetDegenerateModeOn();
myView->StartRotation( point.x(), point.y() );
break;
default:
Standard_Failure::Raise( "incompatible Current Mode" );
break;
}
}
activateCursor( myCurrentMode );
}
void View::onMButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint point )
{
if ( nFlags & CASCADESHORTCUTKEY )
myCurrentMode = CurAction3d_DynamicPanning;
activateCursor( myCurrentMode );
}
void View::onRButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint point )
{
if ( nFlags & CASCADESHORTCUTKEY )
{
if ( !myDegenerateModeIsOn )
myView->SetDegenerateModeOn();
myCurrentMode = CurAction3d_DynamicRotation;
myView->StartRotation( point.x(), point.y() );
}
else
{
Popup( point.x(), point.y() );
}
activateCursor( myCurrentMode );
}
void View::onLButtonUp( Qt::MouseButtons nFlags, const QPoint point )
{
switch( myCurrentMode )
{
case CurAction3d_Nothing:
if ( point.x() == myXmin && point.y() == myYmin )
{
// no offset between down and up --> selectEvent
myXmax = point.x();
myYmax = point.y();
if ( nFlags & MULTISELECTIONKEY )
MultiInputEvent( point.x(), point.y() );
else
InputEvent( point.x(), point.y() );
}
else
{
DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );
myXmax = point.x();
myYmax = point.y();
if ( nFlags & MULTISELECTIONKEY )
MultiDragEvent( point.x(), point.y(), 1 );
else
DragEvent( point.x(), point.y(), 1 );
}
break;
case CurAction3d_DynamicZooming:
myCurrentMode = CurAction3d_Nothing;
noActiveActions();
break;
case CurAction3d_WindowZooming:
DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );//,LongDash);
myXmax = point.x();
myYmax = point.y();
if ( (abs( myXmin - myXmax ) > ValZWMin ) ||
(abs( myYmin - myYmax ) > ValZWMin ) )
myView->WindowFitAll( myXmin, myYmin, myXmax, myYmax );
myCurrentMode = CurAction3d_Nothing;
noActiveActions();
break;
case CurAction3d_DynamicPanning:
myCurrentMode = CurAction3d_Nothing;
noActiveActions();
break;
case CurAction3d_GlobalPanning :
myView->Place( point.x(), point.y(), myCurZoom );
myCurrentMode = CurAction3d_Nothing;
noActiveActions();
break;
case CurAction3d_DynamicRotation:
myCurrentMode = CurAction3d_Nothing;
noActiveActions();
break;
default:
Standard_Failure::Raise(" incompatible Current Mode ");
break;
}
activateCursor( myCurrentMode );
ApplicationCommonWindow::getApplication()->onSelectionChanged();
}
void View::onMButtonUp( Qt::MouseButtons nFlags, const QPoint point )
{
myCurrentMode = CurAction3d_Nothing;
activateCursor( myCurrentMode );
}
void View::onRButtonUp( Qt::MouseButtons nFlags, const QPoint point )
{
if ( myCurrentMode == CurAction3d_Nothing )
Popup( point.x(), point.y() );
else
{
QApplication::setOverrideCursor( Qt::WaitCursor );
// reset tyhe good Degenerated mode according to the strored one
// --> dynamic rotation may have change it
if ( !myDegenerateModeIsOn )
{
myView->SetDegenerateModeOff();
myDegenerateModeIsOn = Standard_False;
}
else
{
myView->SetDegenerateModeOn();
myDegenerateModeIsOn = Standard_True;
}
QApplication::restoreOverrideCursor();
myCurrentMode = CurAction3d_Nothing;
}
activateCursor( myCurrentMode );
}
void View::onMouseMove( Qt::MouseButtons nFlags, const QPoint point )
{
if ( nFlags & Qt::LeftButton || nFlags & Qt::RightButton || nFlags & Qt::MidButton )
{
switch ( myCurrentMode )
{
case CurAction3d_Nothing:
myXmax = point.x();
myYmax = point.y();
DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );
if ( nFlags & MULTISELECTIONKEY )
MultiDragEvent( myXmax, myYmax, 0 );
else
DragEvent( myXmax, myYmax, 0 );
DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_True );
break;
case CurAction3d_DynamicZooming:
myView->Zoom( myXmax, myYmax, point.x(), point.y() );
myXmax = point.x();
myYmax = point.y();
break;
case CurAction3d_WindowZooming:
myXmax = point.x();
myYmax = point.y();
DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );
DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_True );
break;
case CurAction3d_DynamicPanning:
myView->Pan( point.x() - myXmax, myYmax - point.y() );
myXmax = point.x();
myYmax = point.y();
break;
case CurAction3d_GlobalPanning:
break;
case CurAction3d_DynamicRotation:
myView->Rotation( point.x(), point.y() );
myView->Redraw();
break;
default:
Standard_Failure::Raise( "incompatible Current Mode" );
break;
}
}
else
{
myXmax = point.x();
myYmax = point.y();
if ( nFlags & MULTISELECTIONKEY )
MultiMoveEvent( point.x(), point.y() );
else
MoveEvent( point.x(), point.y() );
}
}
void View::DragEvent( const int x, const int y, const int TheState )
{
// TheState == -1 button down
// TheState == 0 move
// TheState == 1 button up
static Standard_Integer theButtonDownX = 0;
static Standard_Integer theButtonDownY = 0;
if ( TheState == -1 )
{
theButtonDownX = x;
theButtonDownY = y;
}
if ( TheState == 0 )
{
myContext->Select( theButtonDownX, theButtonDownY, x, y, myView );
emit selectionChanged();
}
}
void View::InputEvent( const int x, const int y )
{
myContext->Select();
emit selectionChanged();
}
void View::MoveEvent( const int x, const int y )
{
myContext->MoveTo( x, y, myView );
}
void View::MultiMoveEvent( const int x, const int y )
{
myContext->MoveTo( x, y, myView );
}
void View::MultiDragEvent( const int x, const int y, const int TheState )
{
static Standard_Integer theButtonDownX = 0;
static Standard_Integer theButtonDownY = 0;
if ( TheState == -1 )
{
theButtonDownX = x;
theButtonDownY = y;
}
if ( TheState == 0 )
{
myContext->ShiftSelect( theButtonDownX, theButtonDownY, x, y, myView );
emit selectionChanged();
}
}
void View::MultiInputEvent( const int x, const int y )
{
myContext->ShiftSelect();
emit selectionChanged();
}
void View::Popup( const int x, const int y )
{
ApplicationCommonWindow* stApp = ApplicationCommonWindow::getApplication();
QWorkspace* ws = ApplicationCommonWindow::getWorkspace();
QWidget* w = ws->activeWindow();
if ( myContext->NbSelected() )
{
QList<QAction*>* aList = stApp->getToolActions();
QMenu* myToolMenu = new QMenu( 0 );
myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolWireframeId ) );
myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolShadingId ) );
myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolColorId ) );
QMenu* myMaterMenu = new QMenu( myToolMenu );
QList<QAction*>* aMeterActions = ApplicationCommonWindow::getApplication()->getMaterialActions();
QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" );
myMaterMenu = myToolMenu->addMenu( QPixmap( dir+QObject::tr("ICON_TOOL_MATER")), QObject::tr("MNU_MATER") );
for ( int i = 0; i < aMeterActions->size(); i++ )
myMaterMenu->addAction( aMeterActions->at( i ) );
myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolTransparencyId ) );
myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolDeleteId ) );
addItemInPopup(myToolMenu);
myToolMenu->exec( QCursor::pos() );
delete myToolMenu;
}
else
{
QMenu* myBackMenu = new QMenu( 0 );
QAction* a = new QAction( QObject::tr("MNU_CH_BACK"), this );
a->setToolTip( QObject::tr("TBR_CH_BACK") );
connect( a,SIGNAL( activated() ), this, SLOT( onBackground() ) );
myBackMenu->addAction( a );
addItemInPopup(myBackMenu);
myBackMenu->exec( QCursor::pos() );
delete myBackMenu;
}
if ( w )
w->setFocus();
}
void View::addItemInPopup( QMenu* theMenu)
{
}
void View::DrawRectangle(const int MinX, const int MinY,
const int MaxX, const int MaxY, const bool Draw)
{
static Standard_Integer StoredMinX, StoredMaxX, StoredMinY, StoredMaxY;
static Standard_Boolean m_IsVisible;
StoredMinX = (MinX < MaxX) ? MinX: MaxX ;
StoredMinY = (MinY < MaxY) ? MinY: MaxY ;
StoredMaxX = (MinX > MaxX) ? MinX: MaxX ;
StoredMaxY = (MinY > MaxY) ? MinY: MaxY ;
QRect aRect;
aRect.setRect( StoredMinX, StoredMinY, abs(StoredMaxX-StoredMinX), abs(StoredMaxY-StoredMinY));
if ( !myRectBand )
{
myRectBand = new QRubberBand( QRubberBand::Rectangle, this );
myRectBand->setStyle(new QWindowsStyle);
myRectBand->setGeometry( aRect );
myRectBand->show();
/*QPalette palette;
palette.setColor(myRectBand->foregroundRole(), Qt::white);
myRectBand->setPalette(palette);*/
}
if ( m_IsVisible && !Draw ) // move or up : erase at the old position
{
myRectBand->hide();
delete myRectBand;
myRectBand = 0;
m_IsVisible = false;
}
if (Draw) // move : draw
{
//aRect.setRect( StoredMinX, StoredMinY, abs(StoredMaxX-StoredMinX), abs(StoredMaxY-StoredMinY));
m_IsVisible = true;
myRectBand->setGeometry( aRect );
//myRectBand->show();
}
}
void View::noActiveActions()
{
for ( int i = ViewFitAllId; i < ViewHlrOffId ; i++ )
{
QAction* anAction = myViewActions->at( i );
if( ( anAction == myViewActions->at( ViewFitAreaId ) ) ||
( anAction == myViewActions->at( ViewZoomId ) ) ||
( anAction == myViewActions->at( ViewPanId ) ) ||
( anAction == myViewActions->at( ViewGlobalPanId ) ) ||
( anAction == myViewActions->at( ViewRotationId ) ) )
{
setCursor( *defCursor );
anAction->setCheckable( true );
anAction->setChecked( false );
}
}
}
void View::onBackground()
{
QColor aColor ;
Standard_Real R1;
Standard_Real G1;
Standard_Real B1;
myView->BackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
aColor.setRgb(R1*255,G1*255,B1*255);
QColor aRetColor = QColorDialog::getColor(aColor);
if( aRetColor.isValid() )
{
R1 = aRetColor.red()/255.;
G1 = aRetColor.green()/255.;
B1 = aRetColor.blue()/255.;
myView->SetBackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
}
myView->Redraw();
}
bool View::dump(Standard_CString theFile)
{
myView->Redraw();
QString ext = QFileInfo( QString( theFile ) ).completeSuffix();
if ( !ext.compare("ps") || !ext.compare("eps") || !ext.compare("tex") || !ext.compare("pdf") || !ext.compare("svg") || !ext.compare("pgf") )
{
Graphic3d_ExportFormat exFormat;
if ( !ext.compare("ps") )
exFormat = Graphic3d_EF_PostScript;
if ( !ext.compare("eps") )
exFormat = Graphic3d_EF_EnhPostScript;
if ( !ext.compare("tex") )
exFormat = Graphic3d_EF_TEX;
if ( !ext.compare("pdf") )
exFormat = Graphic3d_EF_PDF;
if ( !ext.compare("svg") )
exFormat = Graphic3d_EF_SVG;
if ( !ext.compare("pgf") )
exFormat = Graphic3d_EF_PGF;
try
{
myView->View()->Export( theFile, exFormat );
}
catch(...)
{
return false;
}
return true;
}
return myView->Dump(theFile);
}
Handle(V3d_View)& View::getView()
{
return myView;
}
Handle(AIS_InteractiveContext)& View::getContext()
{
return myContext;
}
View::CurrentAction3d View::getCurrentMode()
{
return myCurrentMode;
}

126
samples/qt/Common/src/View.h Executable file
View File

@@ -0,0 +1,126 @@
#ifndef VIEW_H
#define VIEW_H
#include <QWidget>
#include <QAction>
#include <QList>
#include <AIS_InteractiveContext.hxx>
#include <V3d_View.hxx>
class TopoDS_Shape;
class QRubberBand;
//class COMMONSAMPLE_EXPORT View: public QWidget
class View: public QWidget
{
Q_OBJECT
protected:
enum CurrentAction3d { CurAction3d_Nothing, CurAction3d_DynamicZooming,
CurAction3d_WindowZooming, CurAction3d_DynamicPanning,
CurAction3d_GlobalPanning, CurAction3d_DynamicRotation };
public:
enum ViewAction { ViewFitAllId, ViewFitAreaId, ViewZoomId, ViewPanId, ViewGlobalPanId,
ViewFrontId, ViewBackId, ViewTopId, ViewBottomId, ViewLeftId, ViewRightId,
ViewAxoId, ViewRotationId, ViewResetId, ViewHlrOffId, ViewHlrOnId };
View( Handle(AIS_InteractiveContext) theContext,
QWidget* parent);
~View();
virtual void init();
bool dump( Standard_CString theFile );
QList<QAction*>* getViewActions();
void noActiveActions();
bool isShadingMode();
static QString GetMessages( int type,TopAbs_ShapeEnum aSubShapeType,
TopAbs_ShapeEnum aShapeType );
static QString GetShapeType( TopAbs_ShapeEnum aShapeType );
Standard_EXPORT static void OnButtonuseraction( int ExerciceSTEP,
Handle(AIS_InteractiveContext)& );
Standard_EXPORT static void DoSelection( int Id,
Handle(AIS_InteractiveContext)& );
Standard_EXPORT static void OnSetSelectionMode( Handle(AIS_InteractiveContext)&,
Standard_Integer&,
TopAbs_ShapeEnum& SelectionMode,
Standard_Boolean& );
signals:
void selectionChanged();
public slots:
void fitAll();
void fitArea();
void zoom();
void pan();
void globalPan();
void front();
void back();
void top();
void bottom();
void left();
void right();
void axo();
void rotation();
void reset();
void hlrOn();
void hlrOff();
void updateToggled( bool );
void onBackground();
protected:
virtual void paintEvent( QPaintEvent* );
virtual void resizeEvent( QResizeEvent* );
virtual void mousePressEvent( QMouseEvent* );
virtual void mouseReleaseEvent(QMouseEvent* );
virtual void mouseMoveEvent( QMouseEvent* );
virtual void addItemInPopup( QMenu* );
Handle(V3d_View)& getView();
Handle(AIS_InteractiveContext)& getContext();
void activateCursor( const CurrentAction3d );
void Popup( const int x, const int y );
CurrentAction3d getCurrentMode();
virtual void onLButtonDown( const int nFlags, const QPoint point );
virtual void onMButtonDown( const int nFlags, const QPoint point );
virtual void onRButtonDown( const int nFlags, const QPoint point );
virtual void onLButtonUp( Qt::MouseButtons nFlags, const QPoint point );
virtual void onMButtonUp( Qt::MouseButtons nFlags, const QPoint point );
virtual void onRButtonUp( Qt::MouseButtons nFlags, const QPoint point );
virtual void onMouseMove( Qt::MouseButtons nFlags, const QPoint point );
private:
void initCursors();
void initViewActions();
void DragEvent( const int x, const int y, const int TheState );
void InputEvent( const int x, const int y );
void MoveEvent( const int x, const int y );
void MultiMoveEvent( const int x, const int y );
void MultiDragEvent( const int x, const int y, const int TheState );
void MultiInputEvent( const int x, const int y );
void DrawRectangle( const int MinX, const int MinY,
const int MaxX, const int MaxY, const bool Draw );
private:
bool myFirst;
bool myDrawRect; // set when a rect is used for selection or magnify
Handle(V3d_View) myView;
Handle(AIS_InteractiveContext) myContext;
CurrentAction3d myCurrentMode;
Standard_Integer myXmin;
Standard_Integer myYmin;
Standard_Integer myXmax;
Standard_Integer myYmax;
Quantity_Factor myCurZoom;
Standard_Boolean myDegenerateModeIsOn;
QList<QAction*>* myViewActions;
QRubberBand* myRectBand; //!< selection rectangle rubber band
};
#endif