mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
Integration of OCCT 6.5.0 from SVN
This commit is contained in:
695
samples/qt/Graphic3dDemo/src/Application.cxx
Executable file
695
samples/qt/Graphic3dDemo/src/Application.cxx
Executable file
@@ -0,0 +1,695 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <AIS_InteractiveContext.hxx>
|
||||
#include <OSD_Timer.hxx>
|
||||
#include <Graphic3d_ArrayOfPrimitives.hxx>
|
||||
#include <AIS_ListOfInteractive.hxx>
|
||||
#include <AIS_ListIteratorOfListOfInteractive.hxx>
|
||||
#include <AIS_Shape.hxx>
|
||||
#include <TopoDS_Shape.hxx>
|
||||
#include <TopExp_Explorer.hxx>
|
||||
#include <TopoDS_Face.hxx>
|
||||
#include <Poly_Triangulation.hxx>
|
||||
#include <BRep_TFace.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <Sphere_Sphere.hxx>
|
||||
#include <AIS_Trihedron.hxx>
|
||||
|
||||
#include <qapplication.h>
|
||||
#include <qframe.h>
|
||||
#include <qworkspace.h>
|
||||
#include <qstatusbar.h>
|
||||
#include <qmenubar.h>
|
||||
#include <qmessagebox.h>
|
||||
#include <qtextedit.h>
|
||||
#include <qlayout.h>
|
||||
#include <qevent.h>
|
||||
|
||||
#include "global.h"
|
||||
#include "Application.h"
|
||||
#include "Document.h"
|
||||
#include "MDIWindow.h"
|
||||
#include "Translate.h"
|
||||
#include "ViewOperations.h" // to have access to its enumeration
|
||||
#include "AutoTestDlg.h"
|
||||
|
||||
//#define OUTPUT_WINDOW
|
||||
|
||||
static Application* stApp;
|
||||
static OSD_Timer timer;
|
||||
|
||||
Application::Application() : QMainWindow( 0 )
|
||||
{
|
||||
myNbDocuments = 0;
|
||||
stApp = this;
|
||||
myIsDocuments = false;
|
||||
|
||||
// create and define the central widget
|
||||
QFrame* vBox = new QFrame( this );
|
||||
vBox->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
|
||||
QVBoxLayout* main = new QVBoxLayout( vBox );
|
||||
main->setMargin( 0 );
|
||||
|
||||
myWorkSpace = new QWorkspace( vBox );
|
||||
main->addWidget( myWorkSpace );
|
||||
setCentralWidget( vBox );
|
||||
|
||||
createActions();
|
||||
createCCActions();
|
||||
|
||||
statusBar()->showMessage( tr("INF_READY"), 2001 );
|
||||
resize( 800, 650 );
|
||||
verify( connect( myWorkSpace, SIGNAL( windowActivated( QWidget* ) ),
|
||||
this, SLOT( onWindowActivated( QWidget* ) ) ) );
|
||||
#ifdef OUTPUT_WINDOW
|
||||
myOutput = new OutputWindow( 0 );
|
||||
myOutput->show();
|
||||
#else
|
||||
myOutput = 0;
|
||||
#endif
|
||||
myViewDlg = NULL;
|
||||
}
|
||||
|
||||
Application::~Application()
|
||||
{
|
||||
if (myViewDlg) delete myViewDlg;
|
||||
if (myOutput) delete myOutput;
|
||||
}
|
||||
|
||||
void Application::createActions()
|
||||
{
|
||||
QString dir = getResourceDir();
|
||||
QPixmap newIcon( dir + tr( "ICON_NEW" ) ),
|
||||
helpIcon( dir + tr( "ICON_HELP" ) ),
|
||||
closeIcon( dir + tr( "ICON_CLOSE" ) ),
|
||||
autoIcon( dir + tr( "ICON_AUTO_TEST" ) ),
|
||||
optimIcon( dir + tr( "ICON_OPTIM" ) ),
|
||||
stopIcon( dir + tr( "ICON_STOP" ) ),
|
||||
tileIcon( dir + tr( "ICON_TILE" ) ),
|
||||
cascadeIcon( dir + tr( "ICON_CASCADE" ) );
|
||||
|
||||
// toolbar with standard actions: new, save...
|
||||
myStdToolBar = new QToolBar( this );
|
||||
addToolBar( Qt::TopToolBarArea, myStdToolBar );
|
||||
|
||||
// menu with all actions
|
||||
myFilePopup = menuBar()->addMenu( tr( "MEN_FILE" ) );
|
||||
|
||||
// view menu
|
||||
QMenu* view = menuBar()->addMenu( tr( "MEN_VIEW" ) );
|
||||
|
||||
// Tools menu (it is shown or hidden dynamically)
|
||||
myToolsMenu = new QMenu( tr( "MEN_TOOLS" ), this );
|
||||
|
||||
// Window menu
|
||||
myWinMenu = menuBar()->addMenu( tr( "MEN_WINDOWS" ) );
|
||||
verify(connect( myWinMenu, SIGNAL( aboutToShow() ),
|
||||
this, SLOT( updateWindowList() ) ));
|
||||
|
||||
// add a help menu
|
||||
QMenu* help = menuBar()->addMenu( tr( "MEN_HELP" ) );
|
||||
menuBar()->addSeparator();
|
||||
|
||||
QAction* a = new QAction( newIcon, tr( "MEN_NEW" ), this );
|
||||
a->setToolTip( tr( "TBR_NEW" ) );
|
||||
a->setShortcut( Qt::CTRL+Qt::Key_N );
|
||||
verify( connect( a, SIGNAL( activated() ), this, SLOT( onNewDocument() ) ) );
|
||||
myStdActions.insert( FileNewId, a );
|
||||
myStdToolBar->addAction( a );
|
||||
myFilePopup ->addAction( a );
|
||||
|
||||
a = new QAction( tr( "MEN_QUIT" ), this );
|
||||
a->setShortcut( Qt::CTRL+Qt::Key_Q );
|
||||
a->setToolTip( tr( "TBR_QUIT" ) );
|
||||
verify( connect( a, SIGNAL( activated() ), qApp, SLOT( closeAllWindows() ) ) );
|
||||
myStdActions.insert( FileQuitId, a );
|
||||
myFilePopup ->addAction( a );
|
||||
|
||||
a = new QAction( tr( "MEN_TOOL_BAR" ), this );
|
||||
a->setToolTip( tr( "TBR_TOOL_BAR" ) );
|
||||
verify( connect( a, SIGNAL( activated() ), this, SLOT( onViewToolBar() ) ) );
|
||||
a->setCheckable(true);
|
||||
a->setChecked( true );
|
||||
myStdActions.insert( ViewToolId, a );
|
||||
view->addAction( a );
|
||||
|
||||
a = new QAction( tr("MEN_STATUS_BAR"), this );
|
||||
a->setToolTip( tr( "TBR_STATUS_BAR" ) );
|
||||
verify( connect( a, SIGNAL( activated() ), this, SLOT( onViewStatusBar() ) ) );
|
||||
a->setCheckable(true);
|
||||
a->setChecked( true );
|
||||
myStdActions.insert( ViewStatusId, a );
|
||||
view->addAction( a );
|
||||
|
||||
a = new QAction( helpIcon, tr( "MEN_ABOUT" ), this );
|
||||
a->setShortcut( Qt::Key_F1 );
|
||||
a->setToolTip( tr( "TBR_ABOUT" ) );
|
||||
verify( connect( a, SIGNAL( activated() ) , this, SLOT( onAbout() ) ) );
|
||||
myStdActions.insert( HelpAboutId, a );
|
||||
myStdToolBar->addAction( a );
|
||||
help->addAction( a );
|
||||
|
||||
myStdToolBar->addSeparator();
|
||||
|
||||
// Tools menu actions
|
||||
a = new QAction( optimIcon, tr( "MEN_OPTIM" ), this );
|
||||
a->setToolTip( tr( "TBR_OPTIM" ) );
|
||||
verify( connect( a, SIGNAL( toggled(bool) ) , this, SLOT( onToggleOptim(bool) ) ) );
|
||||
a->setCheckable(true);
|
||||
a->setChecked(Graphic3d_ArrayOfPrimitives::IsEnable());
|
||||
myStdActions.insert( OptimId, a );
|
||||
myToolsMenu->addAction( a );
|
||||
|
||||
a = new QAction( autoIcon, tr( "TBR_AUTO_TEST" ), this );
|
||||
a->setToolTip( tr( "TBR_AUTO_TEST" ) );
|
||||
verify( connect( a, SIGNAL( activated() ) , this, SLOT( onAutoTest() ) ) );
|
||||
myStdActions.insert( AutoTestId, a );
|
||||
myToolsMenu->addAction( a );
|
||||
|
||||
a = new QAction( stopIcon, tr( "TBR_STOP" ), this );
|
||||
a->setToolTip( tr( "TBR_STOP" ) );
|
||||
verify( connect( a, SIGNAL( activated() ) , this, SLOT( onStop() ) ) );
|
||||
myStdActions.insert( StopId, a );
|
||||
myToolsMenu->addAction( a );
|
||||
|
||||
// Window menu action
|
||||
a = new QAction( cascadeIcon, tr( "MEN_CASCADE" ), this );
|
||||
verify( connect( a, SIGNAL( activated() ) , myWorkSpace, SLOT( cascade() ) ) );
|
||||
myStdActions.insert( CascadeId, a );
|
||||
myWinMenu->addAction( a );
|
||||
|
||||
a = new QAction( tileIcon, tr( "MEN_TILE" ), this );
|
||||
verify( connect( a, SIGNAL( activated() ), myWorkSpace, SLOT( tile() ) ) );
|
||||
myStdActions.insert( TileId, a );
|
||||
myWinMenu->addAction( a );
|
||||
|
||||
}
|
||||
|
||||
void Application::createCCActions()
|
||||
{
|
||||
createIEPopups();
|
||||
}
|
||||
|
||||
void Application::createIEPopups()
|
||||
{
|
||||
myImportPopup = new QMenu( tr( "MEN_FILE_IMPORT" ), this );
|
||||
|
||||
QAction* a = new QAction( tr( "MEN_IMPORT_BREP" ), this );
|
||||
a->setToolTip( tr( "TBR_IMPORT_BREP" ) );
|
||||
verify( connect( a, SIGNAL( activated() ) , SLOT( onTranslate() ) ) );
|
||||
myCCActions.insert( FileImportBREPId, a );
|
||||
myImportPopup->addAction( a );
|
||||
}
|
||||
|
||||
QWorkspace* Application::getWorkspace()
|
||||
{
|
||||
return getApplication()->workspace();
|
||||
}
|
||||
|
||||
Application* Application::getApplication()
|
||||
{
|
||||
return stApp;
|
||||
}
|
||||
|
||||
void Application::updateWindowList()
|
||||
{
|
||||
while ( myWinMenu->actions().count() > 2)
|
||||
myWinMenu->removeAction(myWinMenu->actions().last());
|
||||
|
||||
QWidgetList lst = myWorkSpace->windowList();
|
||||
if (!lst.isEmpty())
|
||||
{
|
||||
myWinMenu->addSeparator();
|
||||
for ( int i = 0; i < int(lst.count()); ++i )
|
||||
{
|
||||
QAction* a = myWinMenu->addAction( lst.at(i)->windowTitle(),
|
||||
this, SLOT( activateWindow() ) );
|
||||
a->setCheckable( true );
|
||||
a->setChecked( myWorkSpace->activeWindow() == lst.at(i) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Application::activateWindow()
|
||||
{
|
||||
QAction* a = qobject_cast<QAction*>( sender() );
|
||||
if ( !a ) return;
|
||||
int idx = myWinMenu->actions().indexOf( a ) - 3; // tile, cascade and separator
|
||||
QWidget* w = myWorkSpace->windowList().at( idx );
|
||||
if ( w ) {
|
||||
w->showNormal();
|
||||
w->setFocus();
|
||||
// w->setActiveWindow();
|
||||
}
|
||||
}
|
||||
|
||||
void Application::updateActions()
|
||||
{
|
||||
int count = myFilePopup->actions().count() - 1;
|
||||
|
||||
int popupCount = menuBar()->actions().count();
|
||||
while (myWinMenu->actions().count() > 2)
|
||||
myWinMenu->removeAction(myWinMenu->actions().last());
|
||||
|
||||
if( myWorkSpace->windowList().isEmpty() )
|
||||
{
|
||||
QAction* optim = myStdActions.at(OptimId);
|
||||
QAction* autoTest = myStdActions.at(AutoTestId);
|
||||
QAction* stop = myStdActions.at(StopId);
|
||||
|
||||
if( myNbDocuments ) {
|
||||
myFilePopup->insertMenu( myFilePopup->actions().last(), myImportPopup );
|
||||
myFilePopup->insertSeparator( myFilePopup->actions().last() );
|
||||
|
||||
menuBar()->insertMenu( menuBar()->actions().at( popupCount - 3 ), myToolsMenu );
|
||||
|
||||
if (optim) myStdToolBar->addAction( optim );
|
||||
if (autoTest) myStdToolBar->addAction( autoTest );
|
||||
if (stop) myStdToolBar->addAction( stop );
|
||||
stop->setEnabled(false);
|
||||
myIsDocuments = true;
|
||||
}
|
||||
else {
|
||||
myFilePopup->actions().removeAt( --count );
|
||||
myFilePopup->actions().removeAt( --count );
|
||||
myFilePopup->actions().removeAt( --count );
|
||||
|
||||
menuBar()->actions().removeAt( popupCount - 4 );
|
||||
|
||||
if (optim) myStdToolBar->removeAction( optim );
|
||||
if (autoTest) myStdToolBar->removeAction( autoTest );
|
||||
if (stop) myStdToolBar->removeAction( stop );
|
||||
myIsDocuments = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Document* Application::onNewDocument()
|
||||
{
|
||||
++myNbDocuments;
|
||||
|
||||
updateActions();
|
||||
|
||||
Document* aDoc = new Document( myNbDocuments, this );
|
||||
verify( connect( aDoc, SIGNAL( sendCloseDocument( Document* ) ),
|
||||
SLOT( onCloseDocument( Document* ) ) ) );
|
||||
|
||||
return aDoc;
|
||||
}
|
||||
|
||||
void Application::onCloseDocument(Document* theDoc)
|
||||
{
|
||||
--myNbDocuments;
|
||||
delete theDoc;
|
||||
updateActions();
|
||||
}
|
||||
|
||||
void Application::onTranslate()
|
||||
{
|
||||
const QObject* sentBy = sender();
|
||||
typedef void (Translate::*LPFN_IMPORT)
|
||||
( const Handle( AIS_InteractiveContext ));//, const QString& );
|
||||
|
||||
static LPFN_IMPORT lpfnImport[] = { &Translate::importBREP };
|
||||
|
||||
static QAction* actions[] = { myCCActions.at( FileImportBREPId ) };
|
||||
|
||||
for ( int i = 0; i < sizeof(actions)/sizeof(QAction*); i++ )
|
||||
{
|
||||
if ( actions[i] == sentBy )
|
||||
{
|
||||
Translate* anTrans = new Translate( 0 );
|
||||
MDIWindow* win = myActiveMDI;//(MDIWindow*) myWorkSpace->activeWindow();
|
||||
Handle(AIS_InteractiveContext) aContext = win->getDocument()->getContext();
|
||||
try
|
||||
{
|
||||
/* import */
|
||||
(anTrans->*lpfnImport[i])( aContext );
|
||||
}
|
||||
catch ( Standard_Failure )
|
||||
{
|
||||
/* WARNING: an exception raised but we eat it
|
||||
silently because the shape seems OK
|
||||
*/
|
||||
}
|
||||
delete anTrans;
|
||||
/* commit transaction */
|
||||
win->activateAction( ViewOperations::ViewFitAllId );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Application::importBREP()
|
||||
{
|
||||
Translate* anTrans = new Translate( 0 );
|
||||
MDIWindow* win = myActiveMDI;//(MDIWindow*) myWorkSpace->activeWindow();
|
||||
Handle(AIS_InteractiveContext) aContext = win->getDocument()->getContext();
|
||||
try {
|
||||
/* import */
|
||||
anTrans->importBREP( aContext );
|
||||
}
|
||||
catch ( Standard_Failure ) {
|
||||
/* WARNING: an exception raised but we eat it
|
||||
silently because the shape seems OK
|
||||
*/
|
||||
}
|
||||
delete anTrans;
|
||||
win->activateAction( ViewOperations::ViewFitAllId );
|
||||
}
|
||||
|
||||
QString Application::getResourceDir()
|
||||
{
|
||||
static QString resDir( getenv( "CSF_ResourcesDefaults" ) + QString( "/" ) );
|
||||
return resDir;
|
||||
}
|
||||
|
||||
void Application::onViewToolBar()
|
||||
{
|
||||
bool show = myStdActions.at( ViewToolId )->isChecked();
|
||||
if ( show == myStdToolBar->isVisible() )
|
||||
return;
|
||||
if ( show )
|
||||
myStdToolBar->show();
|
||||
else
|
||||
myStdToolBar->hide();
|
||||
}
|
||||
|
||||
void Application::onViewStatusBar()
|
||||
{
|
||||
bool show = myStdActions.at( ViewStatusId )->isChecked();
|
||||
if ( show == statusBar()->isVisible() )
|
||||
return;
|
||||
if ( show )
|
||||
statusBar()->show();
|
||||
else
|
||||
statusBar()->hide();
|
||||
}
|
||||
|
||||
void Application::onAbout()
|
||||
{
|
||||
QMessageBox::information(this,tr("TIT_ABOUT"),tr("INF_ABOUT"), tr("BTN_OK"),
|
||||
QString::null, QString::null, 0, 0);
|
||||
}
|
||||
|
||||
void Application::onQuit()
|
||||
{
|
||||
#ifdef aaa
|
||||
QWidgetList aList = stWs->windowList();
|
||||
for(MDIWindow* aWindow = (MDIWindow*) aList.first();aWindow;aWindow = (MDIWindow*) aList.next()) {
|
||||
aWindow->closeEvent(0);
|
||||
}
|
||||
|
||||
emit sendQuit();
|
||||
#endif
|
||||
}
|
||||
|
||||
MDIWindow* Application::getActiveMDI()
|
||||
{
|
||||
return myActiveMDI;
|
||||
}
|
||||
|
||||
void Application::onWindowActivated( QWidget* w )
|
||||
{
|
||||
if ( w != NULL && w->inherits( "MDIWindow" ) ){
|
||||
myActiveMDI = (MDIWindow*)w;
|
||||
w->setFocus();
|
||||
}
|
||||
else if (myViewDlg)
|
||||
{
|
||||
delete myViewDlg; myViewDlg = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void Application::startTimer()
|
||||
{
|
||||
timer.Reset();
|
||||
timer.Start();
|
||||
}
|
||||
|
||||
void Application::stopTimer( int count, const char* mes, bool addToGraph, int aOpt )
|
||||
{
|
||||
Standard_Integer m,h;
|
||||
Standard_Real fps,elaps,cpu;
|
||||
char title[256];
|
||||
const char* message = ( mes == NULL ) ? "" : mes;
|
||||
|
||||
timer.Stop();
|
||||
timer.Show( elaps, m, h, cpu );
|
||||
elaps += m * 60. + h * 3600.;
|
||||
fps = Standard_Real( count ) / elaps;
|
||||
if( fps > 1. )
|
||||
sprintf( title, " ====> '%s'. speed is %f frames/second", message, fps );
|
||||
else {
|
||||
if( count > 1 ) {
|
||||
elaps /= count; cpu /= count;
|
||||
sprintf( title, " ====> '%s'. average elapsed/cpu time is %f/%f seconds", message, elaps, cpu );
|
||||
}
|
||||
else {
|
||||
sprintf( title," ====> '%s'. elapsed/cpu time is %f/%f seconds.", message, elaps, cpu );
|
||||
}
|
||||
}
|
||||
|
||||
if (addToGraph)
|
||||
{
|
||||
QString qmes(mes);
|
||||
MDIWindow::ResultType type = MDIWindow::Undefined;
|
||||
bool isOptOn = false;
|
||||
if(aOpt >= 0) {
|
||||
isOptOn |= (aOpt > 0);
|
||||
} else {
|
||||
isOptOn = Graphic3d_ArrayOfPrimitives::IsEnable();
|
||||
}
|
||||
if (qmes.contains(tr("MES_DISPLAY"), Qt::CaseInsensitive))
|
||||
type = isOptOn ? MDIWindow::DisplayOpt : MDIWindow::DisplayNonOpt;
|
||||
else if (qmes.contains(tr("MES_UPDATE"), Qt::CaseInsensitive))
|
||||
type = isOptOn ? MDIWindow::UpdateOpt : MDIWindow::UpdateNonOpt;
|
||||
if (type != MDIWindow::Undefined)
|
||||
{
|
||||
addResult(type, elaps);
|
||||
}
|
||||
}
|
||||
|
||||
QString str( title );
|
||||
cout << title << endl;
|
||||
Application::getApplication()->statusBar()->showMessage( str );
|
||||
Application::getApplication()->showMessage( str );
|
||||
//printf("%s\n",title);
|
||||
}
|
||||
|
||||
void Application::showTimer( const char* mes )
|
||||
{
|
||||
Standard_Integer m,h;
|
||||
Standard_Real elaps,cpu;
|
||||
char title[256];
|
||||
const char* message = ( mes == NULL) ? "" : mes;
|
||||
|
||||
timer.Show( elaps, m, h, cpu );
|
||||
elaps += m * 60. + h * 3600.;
|
||||
sprintf( title," ====> '%s'. elapsed/cpu time is %f/%f seconds", message, elaps, cpu );
|
||||
|
||||
QString str( title );
|
||||
Application::getApplication()->statusBar()->showMessage( str );
|
||||
Application::getApplication()->showMessage( str );
|
||||
cout << title << endl;
|
||||
}
|
||||
|
||||
void Application::showMessage( QString& message )
|
||||
{
|
||||
#ifdef OUTPUT_WINDOW
|
||||
myOutput->print( message );
|
||||
#endif
|
||||
}
|
||||
|
||||
void Application::onToggleOptim(bool state)
|
||||
{
|
||||
state ? Graphic3d_ArrayOfPrimitives::Enable() : Graphic3d_ArrayOfPrimitives::Disable();
|
||||
}
|
||||
|
||||
void Application::addResult(MDIWindow::ResultType item, double value)
|
||||
{
|
||||
MDIWindow* activeWin = getApplication()->getActiveMDI();
|
||||
Handle(AIS_InteractiveContext) activeCtx = activeWin->getDocument()->getContext();
|
||||
|
||||
// Counting triangles...
|
||||
int nbTriangles = 0;
|
||||
AIS_ListOfInteractive displayedObjs;
|
||||
activeCtx->DisplayedObjects(displayedObjs);
|
||||
AIS_ListIteratorOfListOfInteractive dispIt(displayedObjs);
|
||||
for ( ; dispIt.More(); dispIt.Next())
|
||||
{
|
||||
Handle(AIS_InteractiveObject) aisObj = dispIt.Value();
|
||||
if (aisObj->IsKind(STANDARD_TYPE(Sphere_Sphere)))
|
||||
{
|
||||
Handle(Sphere_Sphere) sphere = Handle(Sphere_Sphere)::DownCast(aisObj);
|
||||
Standard_Real rad = sphere->Radius();
|
||||
Standard_Real defl = sphere->Sphere_BasicShape::Deflection();
|
||||
|
||||
nbTriangles += Sphere_Sphere::NbItems(Sphere_Sphere::NbPanes(rad, defl));
|
||||
}
|
||||
else if (aisObj->IsKind(STANDARD_TYPE(AIS_Shape)))
|
||||
{
|
||||
Handle(AIS_Shape) shape = Handle(AIS_Shape)::DownCast(aisObj);
|
||||
TopoDS_Shape topoShape = shape->Shape();
|
||||
TopExp_Explorer exp(topoShape, TopAbs_FACE);
|
||||
for ( ; exp.More(); exp.Next())
|
||||
{
|
||||
TopoDS_Face face = TopoDS::Face(exp.Current());
|
||||
if (!face.IsNull())
|
||||
{
|
||||
Handle(Poly_Triangulation) triangles =
|
||||
Handle(BRep_TFace)::DownCast(face.TShape())->Triangulation();
|
||||
if (!triangles.IsNull())
|
||||
{
|
||||
nbTriangles += triangles->NbTriangles();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
activeWin->addResult(item, nbTriangles, value);
|
||||
}
|
||||
|
||||
QWorkspace* Application::workspace() const
|
||||
{
|
||||
return myWorkSpace;
|
||||
}
|
||||
|
||||
void Application::keyPressEvent(QKeyEvent* e)
|
||||
{
|
||||
if (e->key() == Qt::Key_Escape)
|
||||
myEscPressed = true;
|
||||
}
|
||||
|
||||
void Application::onAutoTest()
|
||||
{
|
||||
AutoTestDlg autoDlg(getApplication());
|
||||
if (autoDlg.exec() == QDialog::Accepted)
|
||||
{
|
||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||
myEscPressed = false;
|
||||
myStopPressed = false;
|
||||
QAction* stop = myStdActions.at(StopId);
|
||||
|
||||
stop->setEnabled(true);
|
||||
|
||||
// Define the range for testing
|
||||
int startItems = autoDlg.getStartNbItems();
|
||||
int stopItems = autoDlg.getStopNbItems();
|
||||
int step = autoDlg.getStep();
|
||||
bool isTe = autoDlg.isText();
|
||||
if (stopItems < startItems) stopItems = startItems;
|
||||
|
||||
Standard_Real radius = 100; // default sphere radius
|
||||
gp_Pnt pos(0, 0, 0); // default sphere center position
|
||||
|
||||
Handle(AIS_InteractiveContext) ctx = getActiveMDI()->getDocument()->getContext();
|
||||
// Main loop
|
||||
for (int currItems = startItems; currItems <= stopItems; currItems += step)
|
||||
{
|
||||
for (int useOptim = 0; useOptim < 2; useOptim++)
|
||||
{
|
||||
qApp->processEvents();
|
||||
if (myEscPressed || myStopPressed)
|
||||
{
|
||||
QApplication::restoreOverrideCursor();
|
||||
stop->setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Toggle optimization
|
||||
useOptim || isTe ? Graphic3d_ArrayOfPrimitives::Enable() : Graphic3d_ArrayOfPrimitives::Disable();
|
||||
|
||||
// Remove all old objects
|
||||
AIS_ListOfInteractive displayedObjs;
|
||||
ctx->DisplayedObjects(displayedObjs);
|
||||
AIS_ListIteratorOfListOfInteractive dispIt(displayedObjs);
|
||||
for ( ; dispIt.More(); dispIt.Next())
|
||||
{
|
||||
Handle(AIS_InteractiveObject) obj = dispIt.Value();
|
||||
if (!obj->IsKind(STANDARD_TYPE(AIS_Trihedron)))
|
||||
ctx->Remove(obj, false);
|
||||
}
|
||||
ctx->UpdateCurrentViewer();
|
||||
|
||||
getActiveMDI()->getView()->SetScale(3.0316);
|
||||
|
||||
// Generate new sphere
|
||||
Standard_Integer nbPanes = Sphere_Sphere::NbPanes(currItems);
|
||||
Standard_Real deflection = Sphere_Sphere::Deflection(radius, nbPanes);
|
||||
Handle(Sphere_Sphere) sphere = new Sphere_Sphere(pos, radius, deflection,
|
||||
1/*myVNormalsFlag*/, 0/*myVColorsFlag*/, 0/*myVTexelsFlag*/, isTe, useOptim);
|
||||
|
||||
// Display the sphere
|
||||
ctx->SetDisplayMode( sphere, getActiveMDI()->getDisplayMode(), false );
|
||||
Application::startTimer();
|
||||
ctx->Display( sphere, false );
|
||||
Application::stopTimer( 0, "Display Sphere::Sphere", true, useOptim);
|
||||
|
||||
qApp->processEvents();
|
||||
if (myEscPressed || myStopPressed)
|
||||
{
|
||||
QApplication::restoreOverrideCursor();
|
||||
stop->setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the viewer
|
||||
Application::startTimer();
|
||||
getActiveMDI()->getView()->Update();
|
||||
Application::stopTimer( 0, "UPDATE", true, useOptim);
|
||||
}
|
||||
}
|
||||
QApplication::restoreOverrideCursor();
|
||||
stop->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------ class OutputWindow ----------------- */
|
||||
OutputWindow::OutputWindow( QWidget* parent ) : QWidget( parent ), myLineCounter( 0 )
|
||||
{
|
||||
setWindowTitle( "Output window" );
|
||||
resize( 400, 300 );
|
||||
|
||||
QVBoxLayout* topLayout = new QVBoxLayout( this );
|
||||
myLineEdit = new QTextEdit( this );
|
||||
|
||||
topLayout->addWidget( myLineEdit );
|
||||
}
|
||||
|
||||
OutputWindow::~OutputWindow()
|
||||
{
|
||||
}
|
||||
|
||||
void OutputWindow::print( QString& s )
|
||||
{
|
||||
myLineEdit->append( QString().setNum( myLineCounter ) + s );
|
||||
myLineCounter++;
|
||||
}
|
||||
|
||||
void Application::InitApp()
|
||||
{
|
||||
onNewDocument();
|
||||
}
|
||||
|
||||
void Application::onStop()
|
||||
{
|
||||
myStopPressed = true;
|
||||
}
|
||||
|
||||
void Application::onEditViewProperties()
|
||||
{
|
||||
if ( !myViewDlg ) {
|
||||
myViewDlg = new ViewDlg(this);
|
||||
verify( connect( myWorkSpace, SIGNAL( windowActivated( QWidget* ) ),
|
||||
myViewDlg, SLOT( Update() ) ) );
|
||||
}
|
||||
myViewDlg->raise();
|
||||
myViewDlg->show();
|
||||
}
|
||||
|
||||
void Application::updateViewDlg()
|
||||
{
|
||||
if(myViewDlg) myViewDlg->Update();
|
||||
}
|
169
samples/qt/Graphic3dDemo/src/AutoTestDlg.cxx
Executable file
169
samples/qt/Graphic3dDemo/src/AutoTestDlg.cxx
Executable file
@@ -0,0 +1,169 @@
|
||||
#include <qlayout.h>
|
||||
#include <qlabel.h>
|
||||
#include <qpushbutton.h>
|
||||
|
||||
#include "Application.h"
|
||||
#include "AutoTestDlg.h"
|
||||
#include "global.h"
|
||||
|
||||
AutoTestDlg::AutoTestDlg(QWidget* parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
setModal( true );
|
||||
setWindowTitle(tr("DLG_AUTO_TEST"));
|
||||
QString dir = Application::getResourceDir();
|
||||
QPixmap autoIcon( dir + tr( "ICON_AUTO_TEST" ) );
|
||||
setWindowIcon(autoIcon);
|
||||
|
||||
QGridLayout* pMainLayout = new QGridLayout(this);
|
||||
pMainLayout->setMargin(5);
|
||||
pMainLayout->setSpacing(5);
|
||||
|
||||
QLabel* lab = new QLabel(tr("LAB_START"), this);
|
||||
pMainLayout->addWidget(lab, 0, 0);
|
||||
|
||||
lab = new QLabel(tr("LAB_STOP"), this);
|
||||
pMainLayout->addWidget(lab, 1, 0);
|
||||
|
||||
lab = new QLabel(tr("LAB_STEP"), this);
|
||||
pMainLayout->addWidget(lab, 2, 0);
|
||||
|
||||
const int MinNbOfItems = 100000; // to see noticable effect
|
||||
const int MaxNbOfItems = 1000000; // to avoid too long computations
|
||||
const int ItemsStep = 100000;
|
||||
const int MinStep = 50000;
|
||||
const int StepStep = 50000;
|
||||
|
||||
myStartSpin = new QSpinBox(this);
|
||||
myStartSpin->setMinimum(MinNbOfItems);
|
||||
myStartSpin->setMaximum(MaxNbOfItems);
|
||||
myStartSpin->setSingleStep(ItemsStep);
|
||||
pMainLayout->addWidget(myStartSpin, 0, 1);
|
||||
verify(connect(myStartSpin, SIGNAL(valueChanged(int)), SLOT(checkStepSpinState())));
|
||||
|
||||
myStopSpin = new QSpinBox(this);
|
||||
myStopSpin->setMinimum(MinNbOfItems);
|
||||
myStopSpin->setMaximum(MaxNbOfItems);
|
||||
myStartSpin->setSingleStep(ItemsStep);
|
||||
pMainLayout->addWidget(myStopSpin, 1, 1);
|
||||
verify(connect(myStopSpin, SIGNAL(valueChanged(int)), SLOT(setStartMaxValue(int))));
|
||||
verify(connect(myStopSpin, SIGNAL(valueChanged(int)), SLOT(checkStepSpinState())));
|
||||
|
||||
const int StopSpinDefaultValue = 2 * myStartSpin -> minimum();
|
||||
myStopSpin -> setValue(StopSpinDefaultValue);
|
||||
myStartSpin -> setMaximum(myStopSpin -> value());
|
||||
|
||||
myStepSpin = new QSpinBox(this);
|
||||
myStepSpin->setMinimum(MinStep);
|
||||
myStepSpin->setMaximum(MaxNbOfItems - MinNbOfItems);
|
||||
myStepSpin->setSingleStep(StepStep);
|
||||
pMainLayout->addWidget(myStepSpin, 2, 1);
|
||||
|
||||
lab = new QLabel(tr("LAB_ITEMS"), this);
|
||||
pMainLayout->addWidget(lab, 0, 2);
|
||||
|
||||
lab = new QLabel(tr("LAB_ITEMS"), this);
|
||||
pMainLayout->addWidget(lab, 1, 2);
|
||||
|
||||
lab = new QLabel(tr("LAB_ITEMS"), this);
|
||||
pMainLayout->addWidget(lab, 2, 2);
|
||||
|
||||
QFrame* separator = new QFrame(this);
|
||||
separator->setFrameStyle(QFrame::HLine | QFrame::Sunken);
|
||||
pMainLayout->addWidget(separator, 3, 0, 1, 3 );
|
||||
|
||||
QHBoxLayout* hcbox = new QHBoxLayout();
|
||||
hcbox->setSpacing(5);
|
||||
|
||||
myTeCheck = new QCheckBox(tr( "MEN_BTN_TEXT" ), this);
|
||||
hcbox->addWidget(myTeCheck);
|
||||
verify(connect(myTeCheck, SIGNAL(clicked()), this, SLOT(onText())));
|
||||
|
||||
hcbox->addSpacing( 5 );
|
||||
|
||||
pMainLayout->addLayout(hcbox, 4, 0, 1, 3);
|
||||
|
||||
QHBoxLayout* hbox = new QHBoxLayout();
|
||||
hbox->setSpacing(5);
|
||||
|
||||
QPushButton* btn = new QPushButton(tr("BTN_START"), this);
|
||||
// btn->setDefault(true);
|
||||
verify(connect(btn, SIGNAL(clicked()), this, SLOT(onStart())));
|
||||
btn->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
|
||||
hbox->addWidget(btn);
|
||||
btn = new QPushButton(tr("BTN_CANCEL"), this);
|
||||
verify(connect(btn, SIGNAL(clicked()), this, SLOT(onCancel())));
|
||||
btn->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
|
||||
hbox->addWidget(btn);
|
||||
hbox->addSpacing(5);
|
||||
pMainLayout->addLayout(hbox, 5, 0, 1, 3);
|
||||
}
|
||||
|
||||
void AutoTestDlg::onStart()
|
||||
{
|
||||
accept();
|
||||
}
|
||||
|
||||
void AutoTestDlg::onCancel()
|
||||
{
|
||||
reject();
|
||||
}
|
||||
|
||||
void AutoTestDlg::setStartMaxValue(int i)
|
||||
{
|
||||
myStartSpin -> setMaximum(i);
|
||||
if (myStartSpin -> value() > myStartSpin -> maximum())
|
||||
myStartSpin -> setValue(myStartSpin -> maximum());
|
||||
}
|
||||
|
||||
void AutoTestDlg::checkStepSpinState()
|
||||
{
|
||||
if (isVisible())
|
||||
{
|
||||
if (myStartSpin -> value() == myStopSpin -> value())
|
||||
myStepSpin -> setEnabled(false);
|
||||
else
|
||||
myStepSpin -> setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void AutoTestDlg::onText()
|
||||
{
|
||||
int MinNbOfItems, MaxNbOfItems, DefaultStartSpinVal, DefaultStopSpinVal,
|
||||
ItemsStep, MinStep, StepStep;
|
||||
|
||||
if (myTeCheck -> isChecked())
|
||||
{
|
||||
MinNbOfItems = 1000; // to see noticeable effect
|
||||
MaxNbOfItems = 100000; // to avoid too long computations
|
||||
DefaultStartSpinVal = 10000;
|
||||
DefaultStopSpinVal = 20000;
|
||||
ItemsStep = 10000;
|
||||
MinStep = 5000;
|
||||
StepStep = 5000;
|
||||
}
|
||||
else
|
||||
{
|
||||
MinNbOfItems = 100000; // to see noticeable effect
|
||||
MaxNbOfItems = 1000000; // to avoid too long computations
|
||||
DefaultStartSpinVal = 100000;
|
||||
DefaultStopSpinVal = 200000;
|
||||
ItemsStep = 100000;
|
||||
MinStep = 50000;
|
||||
StepStep = 50000;
|
||||
}
|
||||
|
||||
myStartSpin -> setRange(MinNbOfItems, MaxNbOfItems);
|
||||
myStartSpin -> setSingleStep(ItemsStep);
|
||||
myStartSpin -> setValue(DefaultStartSpinVal);
|
||||
|
||||
myStopSpin -> setRange(MinNbOfItems, MaxNbOfItems);
|
||||
myStopSpin -> setSingleStep(ItemsStep);
|
||||
|
||||
myStopSpin -> setValue(DefaultStopSpinVal);
|
||||
myStartSpin -> setMaximum(myStopSpin -> value());
|
||||
|
||||
myStepSpin -> setRange(MinStep, MaxNbOfItems - MinNbOfItems);
|
||||
myStepSpin -> setSingleStep(StepStep);
|
||||
myStepSpin -> setValue(MinStep);
|
||||
}
|
147
samples/qt/Graphic3dDemo/src/Document.cxx
Executable file
147
samples/qt/Graphic3dDemo/src/Document.cxx
Executable file
@@ -0,0 +1,147 @@
|
||||
#include <qstatusbar.h>
|
||||
|
||||
#ifndef WNT
|
||||
#include <Graphic3d_GraphicDevice.hxx>
|
||||
#else
|
||||
#include <Graphic3d_WNTGraphicDevice.hxx>
|
||||
#endif
|
||||
|
||||
#include <V3d_View.hxx>
|
||||
|
||||
#include "Application.h"
|
||||
#include "Document.h"
|
||||
#include "global.h"
|
||||
|
||||
|
||||
|
||||
Handle(V3d_Viewer) Document::Viewer( const Standard_CString aDisplay,
|
||||
const Standard_ExtString aName,
|
||||
const Standard_CString aDomain,
|
||||
const Standard_Real ViewSize )
|
||||
{
|
||||
#ifndef WNT
|
||||
static Handle(Graphic3d_GraphicDevice) defaultdevice;
|
||||
|
||||
if ( defaultdevice.IsNull() )
|
||||
defaultdevice = new Graphic3d_GraphicDevice( aDisplay );
|
||||
|
||||
return new V3d_Viewer( defaultdevice, aName, aDomain, ViewSize,
|
||||
V3d_XposYnegZpos,Quantity_NOC_MIDNIGHTBLUE,
|
||||
V3d_ZBUFFER,V3d_GOURAUD,V3d_WAIT);
|
||||
#else
|
||||
static Handle(Graphic3d_WNTGraphicDevice) defaultdevice;
|
||||
if ( defaultdevice.IsNull() )
|
||||
defaultdevice = new Graphic3d_WNTGraphicDevice();
|
||||
|
||||
return new V3d_Viewer( defaultdevice, aName, aDomain, ViewSize,
|
||||
V3d_XposYnegZpos,Quantity_NOC_MIDNIGHTBLUE,
|
||||
V3d_ZBUFFER,V3d_GOURAUD,V3d_WAIT);
|
||||
#endif // WNT
|
||||
}
|
||||
|
||||
Document::Document( int theIndex, Application* app )
|
||||
: QObject( app )
|
||||
{
|
||||
myIndex = theIndex;
|
||||
myNbViews = 0;
|
||||
myApp = app;
|
||||
|
||||
TCollection_ExtendedString a3DName("Visual3D");
|
||||
myViewer = Viewer( getenv( "DISPLAY" ), a3DName.ToExtString(), "", 1000.0 );
|
||||
myViewer->SetDefaultLights();
|
||||
myViewer->SetLightOn();
|
||||
myViewer->SetZBufferManagment(false);
|
||||
myContext = new AIS_InteractiveContext( myViewer );
|
||||
|
||||
createNewView();
|
||||
|
||||
myOperations = new ViewOperations( myContext );
|
||||
}
|
||||
|
||||
Document::~Document()
|
||||
{
|
||||
qDeleteAll( myViews );
|
||||
}
|
||||
|
||||
Application* Document::getApplication()
|
||||
{
|
||||
return myApp;
|
||||
}
|
||||
|
||||
void Document::createNewView( V3d_TypeOfView type )
|
||||
{
|
||||
QWorkspace* ws = myApp->getWorkspace();
|
||||
|
||||
MDIWindow* w = new MDIWindow( this, ws, type );
|
||||
myViews.append( w );
|
||||
ws->addWindow( w );
|
||||
|
||||
//connect( w, SIGNAL( message(const QString&, int) ), myApp->statusBar(), SLOT( message(const QString&, int )) );
|
||||
verify( connect( w, SIGNAL( sendCloseView( MDIWindow* ) ),
|
||||
SLOT( onCloseView( MDIWindow* ) ) ) );
|
||||
|
||||
QString aName;
|
||||
w->setWindowTitle( aName.sprintf( "3D Viewer_%d:%d", myIndex, ++myNbViews ) );
|
||||
|
||||
QString dir = Application::getResourceDir();
|
||||
w->setWindowIcon( QPixmap( dir + tr( "ICON_DOC" ) ) );
|
||||
|
||||
// show the very first window in maximized mode
|
||||
if ( ws->windowList().isEmpty() )
|
||||
w->showMaximized();
|
||||
else
|
||||
w->show();
|
||||
}
|
||||
|
||||
void Document::createMagView( int xMin, int yMin, int xMax, int yMax )
|
||||
{
|
||||
#ifdef old
|
||||
Handle(V3d_View) currentView =
|
||||
( (MDIWindow*) myApp->getWorkspace()->activeWindow() )->getView();
|
||||
createNewView( false );
|
||||
MDIWindow* newView = myViews.last();
|
||||
Handle(V3d_View) nView = newView->getView();
|
||||
|
||||
newView->show();
|
||||
nView->FitAll();
|
||||
//nView->ZFitAll();
|
||||
//nView->Redraw();
|
||||
//nView->WindowFitAll( xMin, yMin, xMax, yMax );
|
||||
nView->SetMagnify( currentView->Window(), currentView, 10, 10, 100, 100 );
|
||||
//nView->SetMagnify( nView->Window(), currentView, xMin, yMin, xMax, yMax );
|
||||
#endif
|
||||
}
|
||||
|
||||
void Document::onCloseView(MDIWindow* theView)
|
||||
{
|
||||
if ( countOfWindow() == 1 )
|
||||
emit sendCloseDocument( this );
|
||||
else
|
||||
removeView( theView );
|
||||
}
|
||||
|
||||
void Document::removeView(MDIWindow* theView)
|
||||
{
|
||||
myViews.removeAll( theView );
|
||||
//delete theView;
|
||||
}
|
||||
|
||||
int Document::countOfWindow()
|
||||
{
|
||||
return myViews.count();
|
||||
}
|
||||
|
||||
Handle(AIS_InteractiveContext)& Document::getContext()
|
||||
{
|
||||
return myContext;
|
||||
}
|
||||
|
||||
void Document::onWireframe()
|
||||
{
|
||||
myOperations->onWireframe();
|
||||
}
|
||||
|
||||
void Document::onShading()
|
||||
{
|
||||
myOperations->onShading();
|
||||
}
|
3017
samples/qt/Graphic3dDemo/src/Graph.cpp
Executable file
3017
samples/qt/Graphic3dDemo/src/Graph.cpp
Executable file
File diff suppressed because it is too large
Load Diff
54
samples/qt/Graphic3dDemo/src/Graphic3dDemo.cxx
Executable file
54
samples/qt/Graphic3dDemo/src/Graphic3dDemo.cxx
Executable file
@@ -0,0 +1,54 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <qmainwindow.h>
|
||||
#include <qapplication.h>
|
||||
#include <qtranslator.h>
|
||||
#include <qpixmap.h>
|
||||
#include <qtranslator.h>
|
||||
|
||||
#include "global.h"
|
||||
#include "Application.h"
|
||||
|
||||
#define GLOBAL_CONTEXT "@default"
|
||||
|
||||
class Translator : public QTranslator
|
||||
{
|
||||
public:
|
||||
Translator( QObject* parent = 0 ) : QTranslator( parent ) {}
|
||||
virtual QString translate( const char* context,
|
||||
const char* sourceText,
|
||||
const char* comment = 0 ) const
|
||||
{
|
||||
QString res = QTranslator::translate( context, sourceText, comment );
|
||||
if( res.isNull() )
|
||||
res = QTranslator::translate( GLOBAL_CONTEXT, sourceText, comment );
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
QApplication a( argc, argv );
|
||||
|
||||
QString dir( getenv( "CSF_ResourcesDefaults" ) );
|
||||
|
||||
Translator msg( 0 ), img( 0 );
|
||||
msg.load( "Sample_msg.qm", dir );
|
||||
a.installTranslator( &msg );
|
||||
|
||||
img.load( "Sample_icons.qm", dir );
|
||||
a.installTranslator( &img );
|
||||
|
||||
QPixmap pix( dir + QString( "/" ) + QObject::tr( "ICON_SAMPLE" ) );
|
||||
|
||||
Application* app = new Application();
|
||||
app->setWindowTitle( QObject::tr( "TIT_SAMPLE" ) );
|
||||
app->setWindowIcon( pix );
|
||||
|
||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||
app->show();
|
||||
app->InitApp();
|
||||
QApplication::restoreOverrideCursor();
|
||||
|
||||
return a.exec();
|
||||
}
|
206
samples/qt/Graphic3dDemo/src/MDIWindow.cxx
Executable file
206
samples/qt/Graphic3dDemo/src/MDIWindow.cxx
Executable file
@@ -0,0 +1,206 @@
|
||||
#include <qlayout.h>
|
||||
#include <qframe.h>
|
||||
#include <qtoolbar.h>
|
||||
#include <qfiledialog.h>
|
||||
#include <qapplication.h>
|
||||
#include <qmessagebox.h>
|
||||
#include <qaction.h>
|
||||
#include <qsplitter.h>
|
||||
#include <qmenu.h>
|
||||
#include <qevent.h>
|
||||
|
||||
#include "MDIWindow.h"
|
||||
#include "global.h"
|
||||
#include "Document.h"
|
||||
#include "View.h"
|
||||
#include "ViewOperations.h"
|
||||
#include "Graph.h"
|
||||
#include "Application.h"
|
||||
|
||||
MDIWindow::MDIWindow( Document* aDocument, QWidget* parent, V3d_TypeOfView type )
|
||||
: QMainWindow( parent )
|
||||
{
|
||||
resize( 500, 300 );
|
||||
QSplitter* central = new QSplitter(Qt::Vertical, this);
|
||||
|
||||
myDocument = aDocument;
|
||||
Handle(AIS_InteractiveContext) cxt = myDocument->getContext();
|
||||
cxt->CurrentViewer()->SetDefaultTypeOfView( type );
|
||||
myView = new View( cxt, central, this );
|
||||
verify(connect(myView, SIGNAL(ViewInitialized()),
|
||||
Application::getApplication(), SLOT(updateViewDlg())));
|
||||
|
||||
// Graph initialization
|
||||
myGraphView = new GraphSplitView(central);
|
||||
GraphView* pGraph = myGraphView->getGraph();
|
||||
GraphItem* pItem = new GraphItem(pGraph, tr("LEG_NONOPT_DISPLAY"));
|
||||
pItem->setSorted(true);
|
||||
pItem->setMarker(0, QColor( Qt::blue ), Qt::SolidLine);
|
||||
pItem->addNode(0, 0);
|
||||
pItem = new GraphItem(pGraph, tr("LEG_OPT_DISPLAY"));
|
||||
pItem->setSorted(true);
|
||||
pItem->setMarker(1, QColor( Qt::red ), Qt::SolidLine);
|
||||
pItem->addNode(0, 0);
|
||||
pItem = new GraphItem(pGraph, tr("LEG_NONOPT_UPDATE"));
|
||||
pItem->setSorted(true);
|
||||
pItem->setMarker(2, QColor( Qt::blue ), Qt::DotLine);
|
||||
pItem->addNode(0, 0);
|
||||
pItem = new GraphItem(pGraph, tr("LEG_OPT_UPDATE"));
|
||||
pItem->setSorted(true);
|
||||
pItem->setMarker(3, QColor( Qt::red ), Qt::DotLine);
|
||||
pItem->addNode(0, 0);
|
||||
pGraph->setXTitle(tr("LAB_TRIANGLES"));
|
||||
pGraph->setYTitle(tr("LAB_SECONDS"));
|
||||
pGraph->installEventFilter(this);
|
||||
pGraph->setOperationEnabled(GraphView::voRect, true);
|
||||
pGraph->setOperationEnabled(GraphView::voZoom, true);
|
||||
pGraph->setOperationEnabled(GraphView::voZoomX, true);
|
||||
pGraph->setOperationEnabled(GraphView::voZoomY, true);
|
||||
pGraph->setOperationEnabled(GraphView::voPan, true);
|
||||
pGraph->setOperationEnabled(GraphView::voPanX, true);
|
||||
pGraph->setOperationEnabled(GraphView::voPanY, true);
|
||||
|
||||
central->setStretchFactor(0, 5);
|
||||
central->setStretchFactor(1, 1);
|
||||
setCentralWidget( central );
|
||||
|
||||
myGraphPopup = new QMenu(pGraph);
|
||||
|
||||
myOperations = new ViewOperations( myDocument->getContext() );
|
||||
|
||||
verify( connect( myView, SIGNAL( noActiveActions() ),
|
||||
myOperations, SLOT( onNoActiveActions() ) ) );
|
||||
verify( connect( myOperations, SIGNAL( setCursor( const QCursor& ) ),
|
||||
SLOT( setCursor( const QCursor& ) ) ) );
|
||||
|
||||
createViewActions();
|
||||
createGraphActions();
|
||||
}
|
||||
|
||||
MDIWindow::~MDIWindow()
|
||||
{
|
||||
delete myGraphView;
|
||||
}
|
||||
|
||||
Document* MDIWindow::getDocument()
|
||||
{
|
||||
return myDocument;
|
||||
}
|
||||
|
||||
int MDIWindow::getDisplayMode()
|
||||
{
|
||||
return myOperations->getDisplayMode();
|
||||
}
|
||||
|
||||
void MDIWindow::closeEvent(QCloseEvent* e)
|
||||
{
|
||||
emit sendCloseView( this );
|
||||
}
|
||||
|
||||
void MDIWindow::createViewActions()
|
||||
{
|
||||
QToolBar* aToolBar = new QToolBar( tr( "View Operations" ), this );
|
||||
addToolBar( Qt::TopToolBarArea, aToolBar );
|
||||
|
||||
QList<QAction*> aList = myOperations->getToolActions();
|
||||
|
||||
QActionGroup* dModeGroup = new QActionGroup( aToolBar );
|
||||
QAction* a;
|
||||
|
||||
int i = 0;
|
||||
foreach( a, aList ) {
|
||||
aToolBar->addAction( a );
|
||||
// if ( i == 1 )
|
||||
// aToolBar->addSeparator();
|
||||
if ( i == ViewOperations::ToolWireframeId || i == ViewOperations::ToolShadingId ) {
|
||||
dModeGroup->addAction( a );
|
||||
}
|
||||
i++;
|
||||
}
|
||||
aToolBar->addSeparator();
|
||||
|
||||
aList = myOperations->getViewActions();
|
||||
foreach( a, aList ) aToolBar->addAction( a );
|
||||
}
|
||||
|
||||
void MDIWindow::setCursor(const QCursor& aCursor)
|
||||
{
|
||||
myView->setCursor(aCursor);
|
||||
}
|
||||
|
||||
void MDIWindow::defineMagView()
|
||||
{
|
||||
myView->setCurrentAction();
|
||||
}
|
||||
|
||||
Handle(V3d_View)& MDIWindow::getView()
|
||||
{
|
||||
return myView->getView();
|
||||
}
|
||||
|
||||
void MDIWindow::activateAction( ViewOperations::Action action )
|
||||
{
|
||||
myView->startAction( action );
|
||||
}
|
||||
|
||||
void MDIWindow::addResult(ResultType item, int x, double y)
|
||||
{
|
||||
if (item == Undefined) return;
|
||||
|
||||
GraphView* pGraph = myGraphView->getGraph();
|
||||
pGraph->getItem((int)item)->addNode(x, y);
|
||||
double xMin, xMax, yMin, yMax;
|
||||
pGraph->getRange(xMin, yMin, xMax, yMax);
|
||||
pGraph->fitData(0, xMax, 0, yMax);
|
||||
}
|
||||
|
||||
bool MDIWindow::eventFilter(QObject* dstObj, QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::MouseButtonPress)
|
||||
{
|
||||
QMouseEvent* mEvent = (QMouseEvent*)event;
|
||||
if (mEvent->button() == Qt::RightButton &&
|
||||
!(mEvent->modifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::ShiftModifier)))
|
||||
graphPopup(mEvent->globalPos());
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void MDIWindow::createGraphActions()
|
||||
{
|
||||
QAction* a = new QAction( tr( "MEN_GRAPH_FIT_ALL" ), this );
|
||||
a->setToolTip( tr( "TBR_GRAPH_FIT_ALL" ) );
|
||||
verify( connect( a, SIGNAL( activated() ) , this, SLOT( onGraphFitAll() ) ) );
|
||||
myGraphPopup->addAction( a );
|
||||
|
||||
myGraphPopup->addSeparator();
|
||||
|
||||
a = new QAction( tr( "MEN_GRAPH_CLEAR" ), this );
|
||||
a->setToolTip( tr( "TBR_GRAPH_CLEAR" ) );
|
||||
verify( connect( a, SIGNAL( activated() ) , this, SLOT( onGraphClear() ) ) );
|
||||
myGraphPopup->addAction( a );
|
||||
}
|
||||
|
||||
void MDIWindow::graphPopup(const QPoint& pos)
|
||||
{
|
||||
myGraphPopup->popup(pos);
|
||||
}
|
||||
|
||||
void MDIWindow::onGraphClear()
|
||||
{
|
||||
GraphView* graph = myGraphView->getGraph();
|
||||
for (int i = 0; i < graph->getNbItems(); i++)
|
||||
{
|
||||
graph->getItem(i)->clear();
|
||||
graph->getItem(i)->addNode(0, 0);
|
||||
}
|
||||
graph->repaint();
|
||||
}
|
||||
|
||||
void MDIWindow::onGraphFitAll()
|
||||
{
|
||||
GraphView* graph = myGraphView->getGraph();
|
||||
double xMin, xMax, yMin, yMax;
|
||||
graph->getRange(xMin, yMin, xMax, yMax);
|
||||
graph->fitData(0, xMax, 0, yMax);
|
||||
}
|
291
samples/qt/Graphic3dDemo/src/ObjectDlg.cxx
Executable file
291
samples/qt/Graphic3dDemo/src/ObjectDlg.cxx
Executable file
@@ -0,0 +1,291 @@
|
||||
#include <qlayout.h>
|
||||
#include <qpushbutton.h>
|
||||
#include <qframe.h>
|
||||
#include <qcheckbox.h>
|
||||
#include <qlabel.h>
|
||||
#include <qcombobox.h>
|
||||
#include <qspinbox.h>
|
||||
|
||||
#include <Aspect_TypeOfLine.hxx>
|
||||
#include <Graphic3d_AspectFillArea3d.hxx>
|
||||
#include <Graphic3d_AspectLine3d.hxx>
|
||||
#include <V3d_TypeOfVisualization.hxx>
|
||||
#include <Prs3d_LineAspect.hxx>
|
||||
#include <Prs3d_ShadingAspect.hxx>
|
||||
#include <AIS_InteractiveObject.hxx>
|
||||
#include <AIS_Drawer.hxx>
|
||||
|
||||
#include "ObjectDlg.h"
|
||||
#include "global.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
ObjectDlg::ObjectDlg( QWidget* parent, Handle(V3d_View)& view,
|
||||
Handle(AIS_InteractiveContext)& cxt )
|
||||
: QDialog( parent ),
|
||||
myAutoApply( true ), myView( view ), myContext( cxt )
|
||||
{
|
||||
setModal( false );
|
||||
setWindowTitle( tr( "TITLE_OBJECT_DLG" ) );
|
||||
|
||||
QVBoxLayout* topLayout = new QVBoxLayout( this );
|
||||
topLayout->setMargin( 5 );
|
||||
|
||||
QFrame* mainFrame = new QFrame( this );
|
||||
mainFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
|
||||
topLayout->addWidget( mainFrame );
|
||||
topLayout->addSpacing( 10 );
|
||||
|
||||
// view properties
|
||||
QGridLayout* pLayout = new QGridLayout( mainFrame );
|
||||
pLayout->setMargin( 5 );
|
||||
myDegModelLabel = new QLabel( tr("MEN_DLG_DEGMODEL"), mainFrame );
|
||||
myDegRatioLabel = new QLabel( tr("MEN_DLG_DEGRATIO"), mainFrame );
|
||||
|
||||
myDegModelBox = new QComboBox( mainFrame );
|
||||
myDegModelBox->addItem( tr( "MEN_DLG_NODEGENERATION" ) );
|
||||
myDegModelBox->addItem( tr( "MEN_DLG_TINYDEGENERATION" ) );
|
||||
myDegModelBox->addItem( tr( "MEN_DLG_WIREDEGENERATION" ) );
|
||||
myDegModelBox->addItem( tr( "MEN_DLG_MARKERDEGENERATION" ) );
|
||||
myDegModelBox->addItem( tr( "MEN_DLG_BBOXDEGENERATION" ) );
|
||||
myCurrentDegModel = NoDegId;
|
||||
myCurrentDegRatio = 0.;
|
||||
verify( connect( myDegModelBox, SIGNAL( activated( int ) ), SLOT( onDegenerateModel( int ) ) ) );
|
||||
|
||||
//QSpinBox* degRatioSpin = new QSpinBox( mainFrame );
|
||||
//QSpinBox ( QWidget * parent = 0, const char * name = 0 )
|
||||
myDegRatioSpin = new QSpinBox( mainFrame );
|
||||
myDegRatioSpin->setRange(0, 10);
|
||||
myDegRatioSpin->setSingleStep(1);
|
||||
verify( connect( myDegRatioSpin, SIGNAL( valueChanged( int ) ), SLOT( onDegRatio( int ) ) ) );
|
||||
|
||||
QCheckBox* showEdges = new QCheckBox( mainFrame );
|
||||
showEdges->setText( tr( "BTN_SHOWEDGES" ) );
|
||||
verify( connect( showEdges, SIGNAL( toggled( bool ) ), SLOT( onShowEdges( bool ) ) ) );
|
||||
|
||||
myEdgeStyle = new QLabel( tr("MEN_DLG_EDGESTYLE"), mainFrame );
|
||||
myEdgeWidth = new QLabel( tr("MEN_DLG_EDGEWIDTH"), mainFrame );
|
||||
|
||||
myEdgeBox = new QComboBox( mainFrame );
|
||||
myEdgeBox->addItem( tr( "MEN_DLG_EDGESOLID" ) );
|
||||
myEdgeBox->addItem( tr( "MEN_DLG_EDGEDASH" ) );
|
||||
myEdgeBox->addItem( tr( "MEN_DLG_EDGEDOT" ) );
|
||||
myEdgeBox->addItem( tr( "MEN_DLG_EDGEDOTDASH" ) );
|
||||
myCurrentEdgeStyle = SolidEdgeId;
|
||||
verify( connect( myEdgeBox, SIGNAL( activated( int ) ), SLOT( onEdgeStyle( int ) ) ) );
|
||||
|
||||
//myEdgeSpin = new QSpinBox( mainFrame );
|
||||
myEdgeSpin = new QSpinBox( mainFrame );
|
||||
myEdgeSpin->setRange(1, 10);
|
||||
myEdgeSpin->setSingleStep(10);
|
||||
verify( connect( myEdgeSpin, SIGNAL( valueChanged( int ) ), SLOT( onEdgeWidth( int ) ) ) );
|
||||
|
||||
onShowEdges( false );
|
||||
|
||||
pLayout->addWidget( myDegModelLabel, 0, 0 );
|
||||
pLayout->addWidget( myDegRatioLabel, 1, 0 );
|
||||
pLayout->addWidget( myDegModelBox, 0, 2 );
|
||||
pLayout->addWidget( myDegRatioSpin, 1, 2 );
|
||||
pLayout->addWidget( showEdges, 2, 0 );
|
||||
pLayout->addWidget( myEdgeStyle, 3, 0 );
|
||||
pLayout->addWidget( myEdgeWidth, 4, 0 );
|
||||
pLayout->addWidget( myEdgeBox, 3, 2 );
|
||||
pLayout->addWidget( myEdgeSpin, 4, 2 );
|
||||
pLayout->setRowStretch( 5, 10 );
|
||||
pLayout->setColumnStretch( 1, 10 );
|
||||
|
||||
// apply controls
|
||||
QCheckBox *autoApply;
|
||||
autoApply = new QCheckBox( this );
|
||||
autoApply->setText( tr( "BTN_AUTOAPPLY" ) );
|
||||
autoApply->setChecked( true );
|
||||
verify( connect( autoApply, SIGNAL( toggled( bool ) ), SLOT( onAutoApply( bool ) ) ) );
|
||||
|
||||
QHBoxLayout* applyLayout = new QHBoxLayout();
|
||||
applyLayout->addWidget( autoApply );
|
||||
applyLayout->addStretch( 10 );
|
||||
topLayout->addLayout(applyLayout);
|
||||
topLayout->addSpacing( 10 );
|
||||
|
||||
// control buttons
|
||||
QPushButton *bOk, *bCancel/*, *bHelp*/;
|
||||
bOk = new QPushButton( tr( "BTN_OK" ), this );
|
||||
verify( connect( bOk, SIGNAL( clicked() ), SLOT( onOk() ) ) );
|
||||
bCancel = new QPushButton( tr( "BTN_CANCEL" ), this );
|
||||
verify( connect( bCancel, SIGNAL( clicked() ), SLOT( onCancel() ) ) );
|
||||
// bHelp = new QPushButton( tr( "BTN_HELP" ), this );
|
||||
// verify( connect( bHelp, SIGNAL( clicked() ), SLOT( onHelp() ) ) );
|
||||
|
||||
QHBoxLayout* btnLayout = new QHBoxLayout();
|
||||
btnLayout->setSpacing( 5 );
|
||||
btnLayout->addStretch( 10 );
|
||||
btnLayout->addWidget( bOk );
|
||||
btnLayout->addWidget( bCancel );
|
||||
btnLayout->addStretch( 10 );
|
||||
// btnLayout->addWidget( bHelp );
|
||||
topLayout->addLayout(btnLayout);
|
||||
|
||||
QSize s = topLayout->totalMinimumSize();
|
||||
s.setWidth( s.width() + topLayout->margin() + 10 );
|
||||
s.setHeight( s.height() + topLayout->margin() + 10 );
|
||||
setFixedSize( s );
|
||||
}
|
||||
|
||||
ObjectDlg::~ObjectDlg()
|
||||
{
|
||||
}
|
||||
|
||||
void ObjectDlg::showEvent ( QShowEvent* e )
|
||||
{
|
||||
QWidget::showEvent( e );
|
||||
|
||||
Standard_Boolean isDeg, isAnim, isEnabled;
|
||||
isAnim = myView->AnimationMode( isDeg );
|
||||
isEnabled = isDeg && isAnim;
|
||||
myDegModelLabel->setEnabled( isEnabled );
|
||||
myDegRatioLabel->setEnabled( isEnabled );
|
||||
myDegModelBox->setEnabled( isEnabled );
|
||||
myDegRatioSpin->setEnabled( isEnabled );
|
||||
}
|
||||
|
||||
void ObjectDlg::onOk()
|
||||
{
|
||||
hide();
|
||||
}
|
||||
|
||||
void ObjectDlg::onCancel()
|
||||
{
|
||||
hide();
|
||||
}
|
||||
|
||||
void ObjectDlg::onHelp()
|
||||
{
|
||||
}
|
||||
|
||||
void ObjectDlg::onShowEdges( bool on )
|
||||
{
|
||||
if ( myAutoApply ) {
|
||||
myEdgeStyle->setEnabled( on );
|
||||
myEdgeWidth->setEnabled( on );
|
||||
myEdgeBox->setEnabled( on );
|
||||
myEdgeSpin->setEnabled( on );
|
||||
|
||||
Handle(AIS_InteractiveObject) object;
|
||||
Handle(Prs3d_ShadingAspect) aspect;
|
||||
myContext->InitSelected();
|
||||
for( ; myContext->MoreSelected(); myContext->NextSelected() ) {
|
||||
object = myContext->SelectedInteractive();
|
||||
aspect = object->Attributes()->ShadingAspect();
|
||||
if ( on )
|
||||
aspect->Aspect()->SetEdgeOn();
|
||||
else
|
||||
aspect->Aspect()->SetEdgeOff();
|
||||
object->SetAspect( aspect );
|
||||
}
|
||||
//myContext->UpdateCurrentViewer();
|
||||
myView->Update();
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectDlg::onDegenerateModel( int index )
|
||||
{
|
||||
if ( myCurrentDegModel != index ) {
|
||||
|
||||
switch ( index ) {
|
||||
case NoDegId :
|
||||
myDegModel = Aspect_TDM_NONE;
|
||||
break;
|
||||
case TinyDegId :
|
||||
myDegModel = Aspect_TDM_TINY;
|
||||
break;
|
||||
case WireDegId :
|
||||
myDegModel = Aspect_TDM_WIREFRAME;
|
||||
break;
|
||||
case MarkerDegId :
|
||||
myDegModel = Aspect_TDM_MARKER;
|
||||
break;
|
||||
case BBoxDegId :
|
||||
myDegModel = Aspect_TDM_BBOX;
|
||||
break;
|
||||
}
|
||||
myCurrentDegModel = index;
|
||||
updateDegenerationModel();
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectDlg::onDegRatio( int ratio )
|
||||
{
|
||||
myCurrentDegRatio = ratio / 10.;
|
||||
updateDegenerationModel();
|
||||
}
|
||||
|
||||
void ObjectDlg::onEdgeStyle( int index )
|
||||
{
|
||||
if ( myCurrentEdgeStyle != index ) {
|
||||
myCurrentEdgeStyle = index;
|
||||
updateEdgeAspect( true );
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectDlg::onEdgeWidth( int value )
|
||||
{
|
||||
myCurrentEdgeWidth = (float) value;
|
||||
updateEdgeAspect( false );
|
||||
}
|
||||
|
||||
void ObjectDlg::onAutoApply( bool on )
|
||||
{
|
||||
myAutoApply = on;
|
||||
}
|
||||
|
||||
void ObjectDlg::updateEdgeAspect( bool edgeStyle )
|
||||
{
|
||||
Aspect_TypeOfLine type;
|
||||
if ( edgeStyle )
|
||||
switch( myCurrentEdgeStyle ) {
|
||||
case SolidEdgeId :
|
||||
type = Aspect_TOL_SOLID;
|
||||
break;
|
||||
case DashEdgeId :
|
||||
type = Aspect_TOL_DASH;
|
||||
break;
|
||||
case DotEdgeId :
|
||||
type = Aspect_TOL_DOT;
|
||||
break;
|
||||
case DotDashEdgeId :
|
||||
type = Aspect_TOL_DOTDASH;
|
||||
break;
|
||||
}
|
||||
Handle(AIS_InteractiveObject) object;
|
||||
Handle(Prs3d_ShadingAspect) aspect;
|
||||
myContext->InitSelected();
|
||||
for( ; myContext->MoreSelected(); myContext->NextSelected() ) {
|
||||
object = myContext->SelectedInteractive();
|
||||
aspect = object->Attributes()->ShadingAspect();
|
||||
if ( edgeStyle )
|
||||
aspect->Aspect()->SetEdgeLineType( type );
|
||||
else
|
||||
aspect->Aspect()->SetEdgeWidth( myCurrentEdgeWidth );
|
||||
object->SetAspect( aspect );
|
||||
}
|
||||
if ( myAutoApply )
|
||||
//myContext->UpdateCurrentViewer();
|
||||
myView->Viewer()->Update();
|
||||
}
|
||||
|
||||
void ObjectDlg::updateDegenerationModel()
|
||||
{
|
||||
//myView->SetAnimationModeOff();
|
||||
Handle(AIS_InteractiveObject) object;
|
||||
for( myContext->InitSelected(); myContext->MoreSelected(); myContext->NextSelected() ) {
|
||||
object = myContext->SelectedInteractive();
|
||||
object->SetDegenerateModel( myDegModel, myCurrentDegRatio );
|
||||
}
|
||||
//myView->SetAnimationModeOn();
|
||||
|
||||
if ( myAutoApply )
|
||||
//myView->Update();
|
||||
myContext->UpdateCurrentViewer();
|
||||
}
|
357
samples/qt/Graphic3dDemo/src/ShapeDlg.cxx
Executable file
357
samples/qt/Graphic3dDemo/src/ShapeDlg.cxx
Executable file
@@ -0,0 +1,357 @@
|
||||
#include <qapplication.h>
|
||||
#include <qlayout.h>
|
||||
#include <qpushbutton.h>
|
||||
#include <qframe.h>
|
||||
#include <qcheckbox.h>
|
||||
#include <qlabel.h>
|
||||
#include <qcombobox.h>
|
||||
#include <qspinbox.h>
|
||||
|
||||
#include <Aspect_TypeOfLine.hxx>
|
||||
#include <Graphic3d_AspectFillArea3d.hxx>
|
||||
#include <Graphic3d_AspectLine3d.hxx>
|
||||
#include <V3d_TypeOfVisualization.hxx>
|
||||
#include <Prs3d_LineAspect.hxx>
|
||||
#include <Prs3d_ShadingAspect.hxx>
|
||||
#include <AIS_InteractiveObject.hxx>
|
||||
#include <AIS_Drawer.hxx>
|
||||
#include <Graphic3d_ArrayOfPrimitives.hxx>
|
||||
|
||||
#include <Sphere_Sphere.hxx>
|
||||
#include <gp_Pnt.hxx>
|
||||
|
||||
#include "ShapeDlg.h"
|
||||
#include "Application.h"
|
||||
#include "MDIWindow.h"
|
||||
#include "Document.h"
|
||||
#include "global.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
ShapeDlg::ShapeDlg( QWidget* parent, Handle(V3d_View)& view,
|
||||
Handle(AIS_InteractiveContext)& cxt )
|
||||
: QDialog( parent ),
|
||||
myView( view ), myContext( cxt )
|
||||
{
|
||||
setModal( false );
|
||||
setWindowTitle( tr( "TITLE_SHAPE_DLG" ) );
|
||||
|
||||
myRadius = 100;
|
||||
myDeflection = 1.0;
|
||||
myNbPanes = 0;
|
||||
myNbItems = 0;
|
||||
|
||||
QVBoxLayout* topLayout = new QVBoxLayout( this );
|
||||
topLayout->setMargin( 5 );
|
||||
|
||||
// radius frame
|
||||
QFrame* rFrame = new QFrame( this );
|
||||
//rFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
|
||||
topLayout->addWidget( rFrame );
|
||||
topLayout->addSpacing( 10 );
|
||||
|
||||
QHBoxLayout* rBox = new QHBoxLayout( rFrame );
|
||||
rBox->setMargin( 5 );
|
||||
QLabel* rad = new QLabel( tr( "MEN_DLG_RADIUS" ), rFrame );
|
||||
QDoubleSpinBox* rSpin = new QDoubleSpinBox( rFrame );
|
||||
rSpin->setRange( 1, 10000 );
|
||||
rSpin->setSingleStep( 1 );
|
||||
// rSpin->setValueDouble( myRadius );
|
||||
rSpin->setValue( myRadius );
|
||||
// verify( connect( rSpin, SIGNAL( sbdValueChanged( double ) ), SLOT( onRadiusChanged( double ) ) ) );
|
||||
verify( connect( rSpin, SIGNAL( valueChanged( double ) ), SLOT( onRadiusChanged( double ) ) ) );
|
||||
|
||||
rBox->addWidget( rad );
|
||||
rBox->addWidget( rSpin );
|
||||
rBox->addStretch( 2 );
|
||||
|
||||
// sphere position frame
|
||||
QFrame* pFrame = new QFrame( this );
|
||||
QHBoxLayout* pBox = new QHBoxLayout( pFrame );
|
||||
pBox->setMargin( 5 );
|
||||
|
||||
pFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
|
||||
topLayout->addWidget( pFrame );
|
||||
topLayout->addSpacing( 10 );
|
||||
|
||||
QLabel *lX, *lY, *lZ;
|
||||
|
||||
lX = new QLabel( tr( "MEN_DLG_X" ), pFrame );
|
||||
lY = new QLabel( tr( "MEN_DLG_Y" ), pFrame );
|
||||
lZ = new QLabel( tr( "MEN_DLG_Z" ), pFrame );
|
||||
|
||||
myXSpin = new QDoubleSpinBox( pFrame );
|
||||
myXSpin->setRange( -10000, 10000 );
|
||||
myXSpin->setSingleStep( 1 );
|
||||
myXSpin->setValue( 0 );
|
||||
connect(myXSpin, SIGNAL(valueChanged (double)), SLOT(onPositionChanged()));
|
||||
myYSpin = new QDoubleSpinBox( pFrame );
|
||||
myYSpin->setRange( -10000, 10000 );
|
||||
myYSpin->setSingleStep( 1 );
|
||||
myYSpin->setValue( 0 );
|
||||
connect(myYSpin, SIGNAL(valueChanged (double)), SLOT(onPositionChanged()));
|
||||
myZSpin = new QDoubleSpinBox( pFrame );
|
||||
myZSpin->setRange( -10000, 10000 );
|
||||
myZSpin->setSingleStep( 1 );
|
||||
myZSpin->setValue( 0 );
|
||||
connect(myZSpin, SIGNAL(valueChanged (double)), SLOT(onPositionChanged()));
|
||||
|
||||
|
||||
pBox->addStretch( 2 );
|
||||
pBox->addWidget( lX );
|
||||
pBox->addWidget( myXSpin );
|
||||
pBox->addStretch( 2 );
|
||||
pBox->addWidget( lY );
|
||||
pBox->addWidget( myYSpin );
|
||||
pBox->addStretch( 2 );
|
||||
pBox->addWidget( lZ );
|
||||
pBox->addWidget( myZSpin );
|
||||
pBox->addStretch( 2 );
|
||||
|
||||
// sphere aspect frame
|
||||
QFrame* aFrame = new QFrame( this );
|
||||
QHBoxLayout* aBox = new QHBoxLayout( aFrame );
|
||||
aBox->setMargin( 5 );
|
||||
|
||||
aFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
|
||||
topLayout->addWidget( aFrame );
|
||||
topLayout->addSpacing( 10 );
|
||||
|
||||
myVNormal = new QCheckBox( aFrame );
|
||||
myVNormal->setText( tr( "MEN_BTN_VNORMAL" ) );
|
||||
myVNormal->setChecked( true );
|
||||
//verify( connect( myVNormal, SIGNAL( toggled( bool ) ), SLOT( onShowEdges( bool ) ) ) );
|
||||
|
||||
myVColor = new QCheckBox( aFrame );
|
||||
myVColor->setText( tr( "MEN_BTN_VCOLOR" ) );
|
||||
//verify( connect( myVColor, SIGNAL( toggled( bool ) ), SLOT( onShowEdges( bool ) ) ) );
|
||||
|
||||
myVTexel = new QCheckBox( aFrame );
|
||||
myVTexel->setText( tr( "MEN_BTN_VTEXEL" ) );
|
||||
//verify( connect( myVTexel, SIGNAL( toggled( bool ) ), SLOT( onShowEdges( bool ) ) ) );
|
||||
|
||||
myText = new QCheckBox( aFrame );
|
||||
myText->setText( tr( "MEN_BTN_TEXT" ) );
|
||||
verify( connect( myText, SIGNAL( clicked() ), SLOT( onText() ) ) );
|
||||
|
||||
aBox->addStretch( 2 );
|
||||
aBox->addWidget( myVNormal );
|
||||
aBox->addStretch( 2 );
|
||||
aBox->addWidget( myVColor );
|
||||
aBox->addStretch( 2 );
|
||||
aBox->addWidget( myVTexel );
|
||||
aBox->addStretch( 2 );
|
||||
aBox->addWidget( myText );
|
||||
aBox->addStretch( 2 );
|
||||
|
||||
// tesselation frame
|
||||
QFrame* tFrame = new QFrame( this );
|
||||
QHBoxLayout* tBox = new QHBoxLayout( tFrame );
|
||||
tBox->setMargin( 5 );
|
||||
|
||||
tFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
|
||||
topLayout->addWidget( tFrame );
|
||||
topLayout->addSpacing( 10 );
|
||||
|
||||
QLabel *defl, *panes, *items;
|
||||
|
||||
defl = new QLabel( tr( "MEN_DLG_DEFLECTION" ), tFrame );
|
||||
panes = new QLabel( tr( "MEN_DLG_PANES" ), tFrame );
|
||||
items = new QLabel( tr( "MEN_DLG_ITEMS" ), tFrame );
|
||||
|
||||
myDefSpin = new QDoubleSpinBox( tFrame );
|
||||
myDefSpin->setRange( 0.1, 13 );
|
||||
myDefSpin->setSingleStep( 0.1 );
|
||||
myDefSpin->setValue( 1 );
|
||||
verify( connect( myDefSpin, SIGNAL( valueChanged( double ) ), SLOT( onDeflectionChanged( double ) ) ) );
|
||||
myPanesSpin = new QSpinBox( tFrame );
|
||||
myPanesSpin->setRange( 8, 10000 );
|
||||
myPanesSpin->setSingleStep( 1 );
|
||||
verify( connect( myPanesSpin, SIGNAL( valueChanged( int ) ), SLOT( onPanesChanged( int ) ) ) );
|
||||
myItemsSpin = new QSpinBox( tFrame );
|
||||
myItemsSpin->setRange( 25, 10000000 );
|
||||
myItemsSpin->setSingleStep( 1 );
|
||||
verify( connect( myItemsSpin, SIGNAL( valueChanged( int ) ), SLOT( onItemsChanged( int ) ) ) );
|
||||
|
||||
tBox->addWidget( defl );
|
||||
tBox->addWidget( myDefSpin );
|
||||
tBox->addWidget( panes );
|
||||
tBox->addWidget( myPanesSpin );
|
||||
tBox->addWidget( items );
|
||||
tBox->addWidget( myItemsSpin );
|
||||
|
||||
// control buttons
|
||||
QPushButton *bOk, *bCancel/*, *bHelp*/;
|
||||
bOk = new QPushButton( tr( "BTN_OK" ), this );
|
||||
bOk->setDefault(true);
|
||||
verify( connect( bOk, SIGNAL( clicked() ), SLOT( onOk() ) ) );
|
||||
bCancel = new QPushButton( tr( "BTN_CANCEL" ), this );
|
||||
verify( connect( bCancel, SIGNAL( clicked() ), SLOT( onCancel() ) ) );
|
||||
verify( connect( this, SIGNAL( destroyed() ), SLOT( onCancel() ) ) );
|
||||
// bHelp = new QPushButton( tr( "BTN_HELP" ), this );
|
||||
// verify( connect( bHelp, SIGNAL( clicked() ), SLOT( onHelp() ) ) );
|
||||
|
||||
QHBoxLayout* btnLayout = new QHBoxLayout();
|
||||
btnLayout->setSpacing( 5 );
|
||||
btnLayout->addStretch( 10 );
|
||||
btnLayout->addWidget( bOk );
|
||||
btnLayout->addWidget( bCancel );
|
||||
btnLayout->addStretch( 10 );
|
||||
// btnLayout->addWidget( bHelp );
|
||||
topLayout->addLayout( btnLayout );
|
||||
|
||||
QSize s = topLayout->totalMinimumSize();
|
||||
s.setWidth( s.width() + topLayout->margin() + 10 );
|
||||
s.setHeight( s.height() + topLayout->margin() + 10 );
|
||||
setFixedSize( s );
|
||||
}
|
||||
|
||||
ShapeDlg::~ShapeDlg()
|
||||
{
|
||||
}
|
||||
|
||||
void ShapeDlg::showEvent ( QShowEvent* e )
|
||||
{
|
||||
QWidget::showEvent( e );
|
||||
// myXSpin->setValueDouble( 0 );
|
||||
// myYSpin->setValueDouble( 0 );
|
||||
// myZSpin->setValueDouble( 0 );
|
||||
myXSpin->setValue( 0 );
|
||||
myYSpin->setValue( 0 );
|
||||
myZSpin->setValue( 0 );
|
||||
onRadiusChanged( myRadius );
|
||||
}
|
||||
|
||||
void ShapeDlg::onOk()
|
||||
{
|
||||
hide();
|
||||
updateSphere();
|
||||
myShape.Nullify();
|
||||
}
|
||||
|
||||
void ShapeDlg::onCancel()
|
||||
{
|
||||
hide();
|
||||
myContext->Remove( myShape );
|
||||
myShape.Nullify();
|
||||
}
|
||||
|
||||
void ShapeDlg::onHelp()
|
||||
{
|
||||
}
|
||||
|
||||
void ShapeDlg::onRadiusChanged( double value )
|
||||
{
|
||||
myRadius = value;
|
||||
|
||||
myNbPanes = Sphere_Sphere::NbPanes( myRadius, myDeflection );
|
||||
myNbItems = Sphere_Sphere::NbItems( myNbPanes );
|
||||
|
||||
myPanesSpin->blockSignals( true );
|
||||
myItemsSpin->blockSignals( true );
|
||||
|
||||
myPanesSpin->setValue( myNbPanes );
|
||||
myItemsSpin->setValue( myNbItems );
|
||||
|
||||
myPanesSpin->blockSignals( false );
|
||||
myItemsSpin->blockSignals( false );
|
||||
|
||||
updateSphere();
|
||||
}
|
||||
|
||||
void ShapeDlg::onItemsChanged( int value )
|
||||
{
|
||||
myNbItems = value;
|
||||
myNbPanes = Sphere_Sphere::NbPanes( myNbItems );
|
||||
myDeflection = Sphere_Sphere::Deflection( myRadius, myNbPanes );
|
||||
|
||||
myDefSpin->blockSignals( true );
|
||||
myPanesSpin->blockSignals( true );
|
||||
|
||||
// myDefSpin->setValueDouble( myDeflection );
|
||||
myDefSpin->setValue( myDeflection );
|
||||
myPanesSpin->setValue( myNbPanes );
|
||||
|
||||
myDefSpin->blockSignals( false );
|
||||
myPanesSpin->blockSignals( false );
|
||||
|
||||
updateSphere();
|
||||
}
|
||||
|
||||
void ShapeDlg::onPanesChanged( int value )
|
||||
{
|
||||
myNbPanes = value;
|
||||
myNbItems = Sphere_Sphere::NbItems( myNbPanes );
|
||||
myDeflection = Sphere_Sphere::Deflection( myRadius, myNbPanes );
|
||||
|
||||
myDefSpin->blockSignals( true );
|
||||
myItemsSpin->blockSignals( true );
|
||||
|
||||
// myDefSpin->setValueDouble( myDeflection );
|
||||
myDefSpin->setValue( myDeflection );
|
||||
myItemsSpin->setValue( myNbItems );
|
||||
|
||||
myDefSpin->blockSignals( false );
|
||||
myItemsSpin->blockSignals( false );
|
||||
|
||||
updateSphere();
|
||||
}
|
||||
|
||||
void ShapeDlg::onDeflectionChanged( double value )
|
||||
{
|
||||
myDeflection = value;
|
||||
myNbPanes = Sphere_Sphere::NbPanes( myRadius, myDeflection );
|
||||
myNbItems = Sphere_Sphere::NbItems( myNbPanes );
|
||||
|
||||
myPanesSpin->blockSignals( true );
|
||||
myItemsSpin->blockSignals( true );
|
||||
|
||||
myPanesSpin->setValue( myNbPanes );
|
||||
myItemsSpin->setValue( myNbItems );
|
||||
|
||||
myPanesSpin->blockSignals( false );
|
||||
myItemsSpin->blockSignals( false );
|
||||
|
||||
updateSphere();
|
||||
}
|
||||
|
||||
void ShapeDlg::onText()
|
||||
{
|
||||
updateSphere();
|
||||
}
|
||||
|
||||
|
||||
void ShapeDlg::updateSphere()
|
||||
{
|
||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||
bool visible = isVisible();
|
||||
gp_Pnt myPosition( myXSpin->value(), myYSpin->value(), myZSpin->value() );
|
||||
if ( !myShape.IsNull() ) {
|
||||
myContext->Remove( myShape, false );
|
||||
myShape.Nullify();
|
||||
}
|
||||
|
||||
myShape =
|
||||
new Sphere_Sphere( myPosition, myRadius, myDeflection, 1/*myVNormalsFlag*/,
|
||||
0/*myVColorsFlag*/, 0/*myVTexelsFlag*/, myText->isChecked(), Graphic3d_ArrayOfPrimitives::IsEnable());
|
||||
myContext->SetDisplayMode( myShape, Application::getApplication()->getActiveMDI()->getDisplayMode(), false );
|
||||
Application::startTimer();
|
||||
myContext->Display( myShape, false );
|
||||
Application::stopTimer( 0, "Display Sphere::Sphere", !visible );
|
||||
Application::startTimer();
|
||||
myView->Update();
|
||||
Application::stopTimer( 0, "UPDATE", !visible );
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
void ShapeDlg::onPositionChanged()
|
||||
{
|
||||
updateSphere();
|
||||
}
|
||||
|
||||
void ShapeDlg::closeEvent ( QCloseEvent* e )
|
||||
{
|
||||
onCancel();
|
||||
}
|
71
samples/qt/Graphic3dDemo/src/Sphere_BasicShape.cxx
Executable file
71
samples/qt/Graphic3dDemo/src/Sphere_BasicShape.cxx
Executable file
@@ -0,0 +1,71 @@
|
||||
#define xG005
|
||||
|
||||
#include <Sphere_BasicShape.ixx>
|
||||
#include <TopLoc_Location.hxx>
|
||||
#include <gp_Trsf.hxx>
|
||||
#include <gp_XYZ.hxx>
|
||||
|
||||
//==================================================
|
||||
// Function:
|
||||
// Purpose :
|
||||
//==================================================
|
||||
|
||||
Sphere_BasicShape::Sphere_BasicShape(const TopoDS_Shape& aShape,
|
||||
const Standard_Real aDeflection,
|
||||
const Standard_Boolean hasVNormals,
|
||||
const Standard_Boolean hasVColors,
|
||||
const Standard_Boolean hasVTexels
|
||||
) :
|
||||
AIS_Shape(aShape),
|
||||
myDeflection(aDeflection),
|
||||
myVNormalsFlag(hasVNormals),
|
||||
myVColorsFlag(hasVColors),
|
||||
myVTexelsFlag(hasVTexels)
|
||||
{
|
||||
}
|
||||
|
||||
void Sphere_BasicShape::SetPosition(const gp_Pnt& aPosition) {
|
||||
gp_Trsf trsf;
|
||||
trsf.SetTranslationPart(gp_Vec(aPosition.XYZ()));
|
||||
TopLoc_Location location(trsf);
|
||||
myshape.Location(location);
|
||||
}
|
||||
|
||||
gp_Pnt Sphere_BasicShape::Position() const {
|
||||
TopLoc_Location location = myshape.Location();
|
||||
gp_Trsf trsf = location.Transformation();
|
||||
gp_XYZ xyz = trsf.TranslationPart();
|
||||
return gp_Pnt(xyz.X(),xyz.Y(),xyz.Z());
|
||||
}
|
||||
|
||||
void Sphere_BasicShape::SetVNormals(const Standard_Boolean aFlag) {
|
||||
myVNormalsFlag = aFlag;
|
||||
}
|
||||
|
||||
Standard_Boolean Sphere_BasicShape::VNormalsFlag() const {
|
||||
return myVNormalsFlag;
|
||||
}
|
||||
|
||||
void Sphere_BasicShape::SetVColors(const Standard_Boolean aFlag) {
|
||||
myVColorsFlag = aFlag;
|
||||
}
|
||||
|
||||
Standard_Boolean Sphere_BasicShape::VColorsFlag() const {
|
||||
return myVColorsFlag;
|
||||
}
|
||||
|
||||
void Sphere_BasicShape::SetVTexels(const Standard_Boolean aFlag) {
|
||||
myVTexelsFlag = aFlag;
|
||||
}
|
||||
|
||||
Standard_Boolean Sphere_BasicShape::VTexelsFlag() const {
|
||||
return myVTexelsFlag;
|
||||
}
|
||||
|
||||
void Sphere_BasicShape::SetDeflection(const Standard_Real aValue) {
|
||||
myDeflection = aValue;
|
||||
}
|
||||
|
||||
Standard_Real Sphere_BasicShape::Deflection() const {
|
||||
return myDeflection;
|
||||
}
|
1137
samples/qt/Graphic3dDemo/src/Sphere_Sphere.cxx
Executable file
1137
samples/qt/Graphic3dDemo/src/Sphere_Sphere.cxx
Executable file
File diff suppressed because it is too large
Load Diff
172
samples/qt/Graphic3dDemo/src/Translate.cxx
Executable file
172
samples/qt/Graphic3dDemo/src/Translate.cxx
Executable file
@@ -0,0 +1,172 @@
|
||||
#include <qfiledialog.h>
|
||||
#include <qmessagebox.h>
|
||||
#include <qapplication.h>
|
||||
|
||||
#include "Translate.h"
|
||||
#include "Application.h"
|
||||
#include "Document.h"
|
||||
#include "MDIWindow.h"
|
||||
#include "global.h"
|
||||
|
||||
#include <StlAPI_Writer.hxx>
|
||||
#include <AIS_InteractiveObject.hxx>
|
||||
#include <AIS_Shape.hxx>
|
||||
#include <TopoDS_Shape.hxx>
|
||||
#include <BRep_Builder.hxx>
|
||||
#include <BRepTools.hxx>
|
||||
#include <TopExp_Explorer.hxx>
|
||||
#include <BRep_Tool.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <Geom_Surface.hxx>
|
||||
#include <Geom_Plane.hxx>
|
||||
#include <Geom_Line.hxx>
|
||||
#include <PTColStd_TransientPersistentMap.hxx>
|
||||
#include <TopoDS_Compound.hxx>
|
||||
#include <AIS_ListOfInteractive.hxx>
|
||||
#include <AIS_ListIteratorOfListOfInteractive.hxx>
|
||||
|
||||
|
||||
// STL
|
||||
//#include <Mesh_InteractiveObject.hxx>
|
||||
//#include <Mesh_STLRead.hxx>
|
||||
//#include <Mesh_Drawer.hxx>
|
||||
//#include <Mesh_Model.hxx>
|
||||
|
||||
#ifdef a
|
||||
#include "OSD_Timer.hxx"
|
||||
#include <FSD_File.hxx>
|
||||
#include <ShapeSchema.hxx>
|
||||
#include <Storage_Data.hxx>
|
||||
#include <PTopoDS_HShape.hxx>
|
||||
#include <Storage_HSeqOfRoot.hxx>
|
||||
#include <Storage_Root.hxx>
|
||||
#include <PTColStd_PersistentTransientMap.hxx>
|
||||
#include <MgtBRep.hxx>
|
||||
#include <TCollection_ExtendedString.hxx>
|
||||
#include <IGESControl_Reader.hxx>
|
||||
#include <IGESControl_Controller.hxx>
|
||||
#include <IGESControl_Writer.hxx>
|
||||
#include <Interface_Static.hxx>
|
||||
#include <STEPControl_Reader.hxx>
|
||||
#include <Interface_TraceFile.hxx>
|
||||
#include <STEPControl_Writer.hxx>
|
||||
#include <TColStd_SequenceOfAsciiString.hxx>
|
||||
#include <TColStd_SequenceOfExtendedString.hxx>
|
||||
#include <VrmlAPI_Writer.hxx>
|
||||
#endif
|
||||
|
||||
Translate::Translate( QObject* parent ):
|
||||
QObject( parent )
|
||||
{
|
||||
}
|
||||
|
||||
Translate::~Translate()
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
Selects a file from standard dialog acoording to selection
|
||||
'filter'
|
||||
*/
|
||||
QString Translate::selectFileName( const QString& filter, bool isImport ) const
|
||||
{
|
||||
return isImport ?
|
||||
QFileDialog::getOpenFileName( QApplication::activeWindow(), tr("INF_APP_IMPORT"), QString::null, filter ) :
|
||||
QFileDialog::getSaveFileName( QApplication::activeWindow(), tr("INF_APP_EXPORT"), QString::null, filter );
|
||||
/*
|
||||
QFileDialog fd ( 0, 0, true );
|
||||
fd.setFilters( filter );
|
||||
if(isImport)
|
||||
fd.setCaption ( tr("INF_APP_IMPORT") );
|
||||
int ret = fd.exec();
|
||||
|
||||
qApp->processEvents();
|
||||
|
||||
return ( ret == QDialog::Accepted ? fd.selectedFile() : QString::null );
|
||||
*/
|
||||
}
|
||||
|
||||
Handle(TopTools_HSequenceOfShape)
|
||||
Translate::BuildSequenceFromContext(const Handle(AIS_InteractiveContext)& cxt)
|
||||
{
|
||||
Handle(TopTools_HSequenceOfShape) sequence = new TopTools_HSequenceOfShape();
|
||||
Handle(AIS_InteractiveObject) object;
|
||||
AIS_ListOfInteractive displayed;
|
||||
cxt->DisplayedObjects( displayed );
|
||||
|
||||
AIS_ListIteratorOfListOfInteractive it( displayed );
|
||||
for ( ; it.More(); it.Next() ) {
|
||||
object = it.Value();
|
||||
if ( object->IsKind( STANDARD_TYPE( AIS_Shape ) ) ) {
|
||||
TopoDS_Shape shape = Handle(AIS_Shape)::DownCast( object )->Shape();
|
||||
sequence->Append( shape );
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef OLD_CODE
|
||||
for(anInteractiveContext->InitCurrent();anInteractiveContext->MoreCurrent();anInteractiveContext->NextCurrent())
|
||||
{
|
||||
picked = anInteractiveContext->Current();
|
||||
if (anInteractiveContext->Current()->IsKind(STANDARD_TYPE(AIS_Shape)))
|
||||
{
|
||||
TopoDS_Shape aShape = Handle(AIS_Shape)::DownCast(picked)->Shape();
|
||||
aSequence->Append(aShape);
|
||||
}
|
||||
}
|
||||
#endif //OLD_CODE
|
||||
return sequence;
|
||||
}
|
||||
|
||||
void Translate::importBREP(const Handle(AIS_InteractiveContext) theContext)
|
||||
{
|
||||
static QString filter = "BREP Files (*.brep )";
|
||||
importBREP(theContext,filter);
|
||||
}
|
||||
|
||||
void Translate::importBREP(const Handle(AIS_InteractiveContext) theContext, const QString& filter)
|
||||
{
|
||||
QString file = selectFileName( filter, true );
|
||||
if ( !file.isNull() ) {
|
||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||
if(!importBREP(theContext, (const Standard_CString) file.toLatin1().constData())) {
|
||||
QApplication::restoreOverrideCursor();
|
||||
QMessageBox::information ( QApplication::activeWindow(),tr("TIT_ERROR"), tr("INF_TRANSLATE_ERROR"), tr("BTN_OK"),
|
||||
QString::null, QString::null, 0, 0);
|
||||
qApp->processEvents(); /* update desktop */
|
||||
} else
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
}
|
||||
|
||||
bool Translate::importBREP(const Handle(AIS_InteractiveContext) theContext, const Standard_CString theFileName)
|
||||
{
|
||||
Handle(TopTools_HSequenceOfShape) aSequence = new TopTools_HSequenceOfShape();
|
||||
TopoDS_Shape aShape;
|
||||
BRep_Builder aBuilder;
|
||||
|
||||
Application::startTimer();
|
||||
Standard_Boolean result = BRepTools::Read(aShape,theFileName,aBuilder);
|
||||
Application::stopTimer( 0, "Loading BREP file" );
|
||||
|
||||
if(result)
|
||||
aSequence->Append(aShape);
|
||||
|
||||
int curMode =
|
||||
( (MDIWindow*)Application::getApplication()->getActiveMDI() )->getDisplayMode();
|
||||
|
||||
for(int i=1;i<= aSequence->Length();i++) {
|
||||
|
||||
Application::startTimer();
|
||||
Handle(AIS_Shape) shape = new AIS_Shape( aSequence->Value( i ) );
|
||||
Application::stopTimer( 0, "Build shape" );
|
||||
Application::startTimer();
|
||||
theContext->Display( shape, curMode, 0, false );
|
||||
Application::stopTimer( 0, "Display" );
|
||||
}
|
||||
Application::startTimer();
|
||||
theContext->UpdateCurrentViewer();
|
||||
Application::stopTimer( 0, "Update" );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
883
samples/qt/Graphic3dDemo/src/View.cxx
Executable file
883
samples/qt/Graphic3dDemo/src/View.cxx
Executable file
@@ -0,0 +1,883 @@
|
||||
#if !defined WNT
|
||||
#define QT_CLEAN_NAMESPACE /* avoid definition of INT32 and INT8 */
|
||||
#endif
|
||||
|
||||
#include <qapplication.h>
|
||||
#include <qpainter.h>
|
||||
#include <qmenu.h>
|
||||
#include <qcolordialog.h>
|
||||
#include <qcursor.h>
|
||||
#include <qevent.h>
|
||||
#include <qrubberband.h>
|
||||
|
||||
#include "View.h"
|
||||
#include "global.h"
|
||||
#include "Application.h"
|
||||
#include "ViewOperations.h"
|
||||
|
||||
|
||||
#include <V3d_PerspectiveView.hxx>
|
||||
#include <Visual3d_View.hxx>
|
||||
#include <Graphic3d_NameOfMaterial.hxx>
|
||||
#include <BRepPrimAPI_MakeBox.hxx>
|
||||
#include <BRepPrimAPI_MakeSphere.hxx>
|
||||
#include <BRepPrimAPI_MakeTorus.hxx>
|
||||
#include <gp_Pnt.hxx>
|
||||
#include <gp.hxx>
|
||||
#include <Geom_Axis2Placement.hxx>
|
||||
#include <AIS_Shape.hxx>
|
||||
#include <AIS_Line.hxx>
|
||||
#include <Geom_Line.hxx>
|
||||
#include <AIS_Trihedron.hxx>
|
||||
//#include <TopAbs_ShapeEnum.hxx>
|
||||
|
||||
#ifdef WNT
|
||||
#include <WNT_Window.hxx>
|
||||
#include <Graphic3d_WNTGraphicDevice.hxx>
|
||||
#else
|
||||
#include <GL/glx.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xmu/StdCmap.h>
|
||||
#undef QT_CLEAN_NAMESPACE
|
||||
#include <Xw_Window.hxx>
|
||||
#include <Graphic3d_GraphicDevice.hxx>
|
||||
#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
|
||||
|
||||
View::View( Handle(AIS_InteractiveContext) theContext, QWidget* parent, MDIWindow* mdi )
|
||||
: QWidget( parent ), myMDI( mdi ), myRubberBand( 0 )
|
||||
{
|
||||
setBackgroundRole( QPalette::NoRole );//NoBackground );
|
||||
// set focus policy to threat QContextMenuEvent from keyboard
|
||||
setFocusPolicy( Qt::StrongFocus );
|
||||
setAttribute( Qt::WA_PaintOnScreen );
|
||||
setAttribute( Qt::WA_NoSystemBackground );
|
||||
|
||||
#ifndef WNT
|
||||
XSynchronize( x11Display(), true ); // it is possible to use QApplication::syncX();
|
||||
#endif
|
||||
|
||||
myObjDlg = NULL;
|
||||
myShapeDlg = NULL;
|
||||
myFirst = true;
|
||||
myContext = theContext;
|
||||
|
||||
myCycleCounter = -1;
|
||||
|
||||
myXmin=0;
|
||||
myYmin=0;
|
||||
myXmax=0;
|
||||
myYmax=0;
|
||||
myCurZoom=0;
|
||||
|
||||
#if !defined WNT
|
||||
XVisualInfo* pVisualInfo;
|
||||
if ( x11Display() ) {
|
||||
/* Initialization with the default VisualID
|
||||
*/
|
||||
Visual *v = DefaultVisual( x11Display(), DefaultScreen( x11Display() ) );
|
||||
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 (x11Display(), DefaultScreen(x11Display()), visualAttr);
|
||||
|
||||
if ( isVisible() )
|
||||
hide();
|
||||
|
||||
XSetWindowAttributes a;
|
||||
|
||||
Window p = RootWindow( x11Display(), DefaultScreen(x11Display()) );
|
||||
a.colormap = XCreateColormap( x11Display(), RootWindow(x11Display(),
|
||||
pVisualInfo->screen), pVisualInfo->visual, AllocNone );
|
||||
a.background_pixel = backgroundColor().pixel();
|
||||
a.border_pixel = black.pixel();
|
||||
if ( parentWidget() )
|
||||
p = parentWidget()->winId();
|
||||
|
||||
Window w = XCreateWindow( x11Display(), p, x(), y(), width(), height(),
|
||||
0, pVisualInfo->depth, InputOutput, pVisualInfo->visual,
|
||||
CWBackPixel | CWBorderPixel | CWColormap, &a );
|
||||
Window *cmw;
|
||||
Window *cmwret;
|
||||
int count;
|
||||
if ( XGetWMColormapWindows( x11Display(), 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( x11Display(), topLevelWidget()->winId(), cmw, count );
|
||||
delete [] cmw;
|
||||
|
||||
if ( isVisible() )
|
||||
show();
|
||||
if ( pVisualInfo ) {
|
||||
XFree( (char *)pVisualInfo );
|
||||
}
|
||||
XFlush( x11Display() );
|
||||
}
|
||||
#endif // !defined WNT
|
||||
|
||||
// will be set in OnInitial update, but, for more security :
|
||||
myCurrentMode = CurAction3d_Nothing;
|
||||
setMouseTracking( true );
|
||||
myView = NULL;
|
||||
}
|
||||
|
||||
View::~View()
|
||||
{
|
||||
}
|
||||
|
||||
void View::init()
|
||||
{
|
||||
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, Quantity_NOC_BLACK );
|
||||
#endif // WNT
|
||||
myView->SetWindow( hWnd );
|
||||
if ( !hWnd->IsMapped() )
|
||||
hWnd->Map();
|
||||
myView->SetBackgroundColor(Quantity_NOC_GRAY40);
|
||||
myView->MustBeResized();
|
||||
|
||||
Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement( gp::XOY() );
|
||||
myTrihedron = new AIS_Trihedron( anAxis );
|
||||
myContext->Display( myTrihedron );
|
||||
|
||||
//myView->SetAntialiasingOn();
|
||||
myComputedModeIsOn = true;
|
||||
myView->SetScale(3.0316);
|
||||
|
||||
// This is to update View properties dialog
|
||||
emit ViewInitialized();
|
||||
}
|
||||
|
||||
void View::paintEvent ( QPaintEvent * e)
|
||||
{
|
||||
if(myFirst) {
|
||||
init();
|
||||
myFirst = false;
|
||||
}
|
||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||
Application::startTimer();
|
||||
myView->Redraw();
|
||||
Application::stopTimer( 0, "View REDRAW", false );
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
void View::resizeEvent ( QResizeEvent * e)
|
||||
{
|
||||
// QApplication::syncX();
|
||||
if(!myView.IsNull()) {
|
||||
myView->MustBeResized();
|
||||
}
|
||||
}
|
||||
|
||||
void View::mousePressEvent(QMouseEvent* e)
|
||||
{
|
||||
if ( e->button() == Qt::LeftButton ) {
|
||||
onLButtonDown(e->modifiers(),e->pos());
|
||||
} else if(e->button() == Qt::RightButton ) {
|
||||
onRButtonDown(e->modifiers(),e->pos());
|
||||
}
|
||||
}
|
||||
|
||||
void View::mouseReleaseEvent(QMouseEvent* e)
|
||||
{
|
||||
if ( e->button() == Qt::LeftButton ) {
|
||||
onLButtonUp(e->modifiers(),e->pos());
|
||||
} else if(e->button() == Qt::RightButton ) {
|
||||
onRButtonUp(e->modifiers(),e->pos());
|
||||
}
|
||||
}
|
||||
|
||||
void View::mouseMoveEvent(QMouseEvent* e)
|
||||
{
|
||||
onMouseMove(e->buttons(),e->modifiers(),e->pos());
|
||||
}
|
||||
|
||||
void View::onLButtonDown( Qt::KeyboardModifiers 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 ) {
|
||||
// Button MB1 down Control :start zomming
|
||||
// SetCursor(AfxGetApp()->LoadStandardCursor());
|
||||
}
|
||||
else { // if ( Ctrl )
|
||||
switch (myCurrentMode) {
|
||||
|
||||
case CurAction3d_Nothing : // start a drag
|
||||
if (nFlags == MULTISELECTIONKEY)
|
||||
MultiDragEvent(myXmax,myYmax,-1);
|
||||
else
|
||||
DragEvent(myXmax,myYmax,-1);
|
||||
break;
|
||||
case CurAction3d_DynamicZooming : // noting
|
||||
break;
|
||||
case CurAction3d_WindowZooming :
|
||||
case CurAction3d_MagnifyView :
|
||||
break;
|
||||
case CurAction3d_DynamicPanning :// noting
|
||||
break;
|
||||
case CurAction3d_GlobalPanning :// noting
|
||||
break;
|
||||
case CurAction3d_DynamicRotation :
|
||||
if (!myComputedModeIsOn){
|
||||
myView->SetComputedMode(false);
|
||||
}
|
||||
myView->SetAnimationModeOn();
|
||||
myView->StartRotation(point.x(),point.y());
|
||||
break;
|
||||
default :
|
||||
Standard_Failure::Raise(" incompatible Current Mode ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void View::onRButtonDown( Qt::KeyboardModifiers nFlags, const QPoint point )
|
||||
{
|
||||
if ( nFlags == CASCADESHORTCUTKEY ) {
|
||||
if ( !myComputedModeIsOn )
|
||||
myView->SetComputedMode(false);
|
||||
// Standard_Boolean anim, deg;
|
||||
// anim = myView->AnimationMode( deg );
|
||||
// if ( anim /*&& deg*/ ) {
|
||||
myCycleCounter = 0;
|
||||
Application::startTimer();
|
||||
myView->SetAnimationModeOn();
|
||||
// myView->SetAnimationMode(true,true);
|
||||
// myContext->DeactivateStandardMode( TopAbs_SHAPE );
|
||||
// }
|
||||
myView->StartRotation( point.x(),point.y() );
|
||||
}
|
||||
else
|
||||
Popup();
|
||||
}
|
||||
|
||||
void View::onLButtonUp(Qt::KeyboardModifiers nFlags, const QPoint point)
|
||||
{
|
||||
if ( nFlags == CASCADESHORTCUTKEY )
|
||||
{
|
||||
return;
|
||||
}
|
||||
else // if ( Ctrl )
|
||||
{
|
||||
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 :
|
||||
// SetCursor(AfxGetApp()->LoadStandardCursor());
|
||||
myCurrentMode = CurAction3d_Nothing;
|
||||
emit noActiveActions();
|
||||
break;
|
||||
|
||||
case CurAction3d_WindowZooming :
|
||||
case CurAction3d_MagnifyView :
|
||||
|
||||
DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );
|
||||
myXmax = point.x();
|
||||
myYmax = point.y();
|
||||
|
||||
if ( ( abs( myXmin - myXmax ) > ValZWMin ) ||
|
||||
( abs( myYmin - myYmax ) > ValZWMin ) ) {
|
||||
|
||||
if ( myCurrentMode == CurAction3d_MagnifyView )
|
||||
myMDI->getDocument()->createMagView( myXmin, myYmin, myXmax, myYmax );
|
||||
else
|
||||
myView->WindowFitAll( myXmin, myYmin, myXmax, myYmax );
|
||||
}
|
||||
myCurrentMode = CurAction3d_Nothing;
|
||||
emit noActiveActions();
|
||||
break;
|
||||
|
||||
case CurAction3d_DynamicPanning :
|
||||
myCurrentMode = CurAction3d_Nothing;
|
||||
emit noActiveActions();
|
||||
break;
|
||||
case CurAction3d_GlobalPanning :
|
||||
myView->Place(point.x(),point.y(),myCurZoom);
|
||||
myCurrentMode = CurAction3d_Nothing;
|
||||
emit noActiveActions();
|
||||
break;
|
||||
case CurAction3d_DynamicRotation :
|
||||
myCurrentMode = CurAction3d_Nothing;
|
||||
myView->SetAnimationModeOff();
|
||||
emit noActiveActions();
|
||||
break;
|
||||
default :
|
||||
Standard_Failure::Raise(" incompatible Current Mode ");
|
||||
break;
|
||||
} //switch (myCurrentMode)
|
||||
} // else // if ( Ctrl )
|
||||
}
|
||||
|
||||
void View::onRButtonUp(Qt::KeyboardModifiers nFlags, const QPoint point)
|
||||
{
|
||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||
// reset computed mode according to the stored one
|
||||
// --> dynamic rotation may have change it
|
||||
|
||||
if (!myComputedModeIsOn)
|
||||
{
|
||||
myView->SetComputedMode(false);
|
||||
myComputedModeIsOn = Standard_False;
|
||||
} else
|
||||
{
|
||||
myView->SetComputedMode(false);
|
||||
myComputedModeIsOn = Standard_True;
|
||||
}
|
||||
|
||||
//if ( myView->AnimationModeIsOn() ) {
|
||||
myView->SetAnimationModeOff();
|
||||
Application::stopTimer( myCycleCounter, "Animation next UPDATE", false );
|
||||
//}
|
||||
myCycleCounter = -1;
|
||||
|
||||
myView->Update();
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
void View::onMouseMove(Qt::MouseButtons btns, Qt::KeyboardModifiers nFlags, const QPoint point)
|
||||
{
|
||||
// ============================ LEFT BUTTON =======================
|
||||
if ( btns == Qt::LeftButton ) {
|
||||
if ( nFlags == CASCADESHORTCUTKEY )
|
||||
{
|
||||
// move with MB1 and Control : on the dynamic zooming
|
||||
// Do the zoom in function of mouse's coordinates
|
||||
myView->Zoom(myXmax,myYmax,point.x(),point.y());
|
||||
// save the current mouse coordinate in min
|
||||
myXmax = point.x();
|
||||
myYmax = point.y();
|
||||
}
|
||||
else // if ( Ctrl )
|
||||
{
|
||||
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());
|
||||
// save the current mouse coordinate in min \n";
|
||||
myXmax=point.x(); myYmax=point.y();
|
||||
break;
|
||||
case CurAction3d_WindowZooming :
|
||||
case CurAction3d_MagnifyView :
|
||||
myXmax = point.x(); myYmax = point.y();
|
||||
DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);//,LongDash);
|
||||
DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True);//,LongDash);
|
||||
break;
|
||||
case CurAction3d_DynamicPanning :
|
||||
myView->Pan(point.x()-myXmax,myYmax-point.y()); // Realize the panning
|
||||
myXmax = point.x();
|
||||
myYmax = point.y();
|
||||
break;
|
||||
case CurAction3d_GlobalPanning : // nothing
|
||||
break;
|
||||
case CurAction3d_DynamicRotation :
|
||||
myView->Rotation(point.x(),point.y());
|
||||
// myView->Redraw();
|
||||
break;
|
||||
default :
|
||||
Standard_Failure::Raise(" incompatible Current Mode ");
|
||||
break;
|
||||
}// switch (myCurrentMode)
|
||||
}// if ( nFlags == CASCADESHORTCUTKEY ) else
|
||||
} else // if ( btns == MK_LBUTTON)
|
||||
// ============================ MIDDLE BUTTON =======================
|
||||
if ( btns == Qt::MidButton ) {
|
||||
if ( nFlags == CASCADESHORTCUTKEY )
|
||||
{
|
||||
myView->Pan(point.x()-myXmax,myYmax-point.y()); // Realize the panning
|
||||
myXmax = point.x();
|
||||
myYmax = point.y();
|
||||
|
||||
}
|
||||
} else // if ( btns == MK_MBUTTON)
|
||||
// ============================ RIGHT BUTTON =======================
|
||||
if ( btns == Qt::RightButton ) {
|
||||
if ( nFlags == CASCADESHORTCUTKEY )
|
||||
{
|
||||
myView->Rotation(point.x(),point.y());
|
||||
}
|
||||
}else //if ( btns == MK_RBUTTON)
|
||||
// ============================ NO BUTTON =======================
|
||||
{ // No buttons
|
||||
myXmax = point.x(); myYmax = point.y();
|
||||
if (nFlags == MULTISELECTIONKEY)
|
||||
MultiMoveEvent(point.x(),point.y());
|
||||
else
|
||||
MoveEvent(point.x(),point.y());
|
||||
}
|
||||
//Standard_Boolean anim, deg;
|
||||
//anim = myView->AnimationMode( deg );
|
||||
//if ( anim /*&& deg*/ ) {
|
||||
if ( myCycleCounter != -1 ) {
|
||||
if ( myCycleCounter == 0 )
|
||||
Application::showTimer( "Animation first UPDATE" );
|
||||
myCycleCounter++;
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
void View::DragEvent( int x, int y, int TheState )
|
||||
{
|
||||
// TheState == -1 button down
|
||||
// TheState == 0 move
|
||||
// TheState == 1 button up
|
||||
|
||||
static int theButtonDownX=0;
|
||||
static int theButtonDownY=0;
|
||||
|
||||
if (TheState == -1)
|
||||
{
|
||||
theButtonDownX=x;
|
||||
theButtonDownY=y;
|
||||
}
|
||||
|
||||
if (TheState == 0) {
|
||||
myContext->Select(theButtonDownX,theButtonDownY,x,y,myView);
|
||||
}
|
||||
}
|
||||
|
||||
void View::InputEvent( int x, int y )
|
||||
{
|
||||
Application::startTimer();
|
||||
myContext->Select();
|
||||
Application::stopTimer( 0, "Single selection", false );
|
||||
}
|
||||
|
||||
void View::MoveEvent( int x, int y )
|
||||
{
|
||||
myContext->MoveTo(x,y,myView);
|
||||
}
|
||||
|
||||
void View::MultiMoveEvent( int x, int y )
|
||||
{
|
||||
myContext->MoveTo(x,y,myView);
|
||||
}
|
||||
|
||||
void View::MultiDragEvent( int x, int y, int TheState )
|
||||
{
|
||||
static int theButtonDownX=0;
|
||||
static int theButtonDownY=0;
|
||||
|
||||
if (TheState == -1)
|
||||
{ theButtonDownX=x; theButtonDownY=y;}
|
||||
|
||||
if (TheState == 0) {
|
||||
myContext->ShiftSelect(theButtonDownX,theButtonDownY,x,y,myView);
|
||||
emit selectionChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void View::MultiInputEvent( int x, int y )
|
||||
{
|
||||
myContext->ShiftSelect();
|
||||
emit selectionChanged();
|
||||
}
|
||||
|
||||
void View::Popup()
|
||||
{
|
||||
QMenu* popMenu = new QMenu( this );
|
||||
|
||||
if( myContext->NbCurrents()) {
|
||||
QAction* a;
|
||||
myContext->InitCurrent();
|
||||
if (! myContext->Current()->IsKind(STANDARD_TYPE(AIS_Trihedron)))
|
||||
{
|
||||
a = new QAction( tr( "MEN_POP_OBJPROP" ), this );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onEditObjectProperties() ) ) );
|
||||
popMenu->addAction( a );
|
||||
|
||||
QMenu* dMode = popMenu->addMenu( tr( "MEN_POP_DISPLAYMODE" ) );
|
||||
|
||||
a = new QAction( tr( "MEN_POP_WIREFRAME" ), this );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onWireframeMode() ) ) );
|
||||
dMode->addAction( a );
|
||||
|
||||
a = new QAction( tr( "MEN_POP_SHADING" ), this );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onShadingMode() ) ) );
|
||||
dMode->addAction( a );
|
||||
}
|
||||
a = new QAction( tr( "MEN_POP_REMOVEOBJECT" ), this );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onRemoveObject() ) ) );
|
||||
popMenu->addAction( a );
|
||||
}
|
||||
else {
|
||||
QAction* a = new QAction( tr( "MEN_POP_VIEWPROP" ), this );
|
||||
verify( connect( a, SIGNAL( activated() ), Application::getApplication(), SLOT( onEditViewProperties() ) ) );
|
||||
popMenu->addAction( a );
|
||||
|
||||
a = new QAction( tr( "MEN_POP_IMPORT" ), this );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onImportObject() ) ) );
|
||||
popMenu->addAction( a );
|
||||
|
||||
popMenu->addSeparator();
|
||||
if ( myContext->IsDisplayed( myTrihedron ) ) {
|
||||
a = new QAction( tr( "MEN_POP_ERASETRIHEDRON" ), this );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onEraseTrihedron() ) ) );
|
||||
popMenu->addAction( a );
|
||||
}
|
||||
else {
|
||||
a = new QAction( tr( "MEN_POP_DISPLAYTRIHEDRON" ), this );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onDisplayTrihedron() ) ) );
|
||||
popMenu->addAction( a );
|
||||
}
|
||||
|
||||
popMenu->addSeparator();
|
||||
a = new QAction( tr( "MEN_POP_CREATESHAPE" ), this );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onCreateShape() ) ) );
|
||||
popMenu->addAction( a );
|
||||
|
||||
QMenu* loadObj = popMenu->addMenu( tr( "MEN_POP_LOADOBJECT" ) );
|
||||
|
||||
a = new QAction( tr( "MEN_POP_BOX" ), this );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onLoadBox() ) ) );
|
||||
loadObj->addAction( a );
|
||||
|
||||
a = new QAction( tr( "MEN_POP_SPHERE" ), this );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onLoadSphere() ) ) );
|
||||
loadObj->addAction( a );
|
||||
|
||||
a = new QAction( tr( "MEN_POP_TORUS" ), this );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onLoadTorus() ) ) );
|
||||
loadObj->addAction( a );
|
||||
|
||||
// a = new QAction( tr( "MEN_POP_LINE" ), this );
|
||||
// verify( connect( a, SIGNAL( activated() ), SLOT( onLoadLine() ) ) );
|
||||
// loadObj->addAction( a );
|
||||
}
|
||||
popMenu->exec( QCursor::pos() );
|
||||
}
|
||||
|
||||
void View::DrawRectangle( int MinX, int MinY, int MaxX, int MaxY, bool Draw )
|
||||
{
|
||||
if ( !myRubberBand )
|
||||
myRubberBand = new QRubberBand( QRubberBand::Rectangle, this );
|
||||
|
||||
myRubberBand->setGeometry( QRect( QPoint( MinX, MinY ), QPoint( MaxX, MaxY ) ).normalized() );
|
||||
myRubberBand->setVisible( Draw );
|
||||
/*
|
||||
QPainter thePainter(this);
|
||||
thePainter.setRasterOp(Qt::XorROP);
|
||||
thePainter.setPen(Qt::white);
|
||||
static int StoredMinX, StoredMaxX, StoredMinY, StoredMaxY;
|
||||
static bool m_IsVisible;
|
||||
|
||||
QRect aRect;
|
||||
if ( m_IsVisible && !Draw) // move or up : erase at the old position
|
||||
{
|
||||
aRect.setRect( StoredMinX, StoredMinY, abs(StoredMaxX-StoredMinX), abs(StoredMaxY-StoredMinY));
|
||||
thePainter.drawRect(aRect);
|
||||
m_IsVisible = false;
|
||||
}
|
||||
|
||||
StoredMinX = (MinX < MaxX) ? MinX: MaxX ;
|
||||
StoredMinY = (MinY < MaxY) ? MinY: MaxY ;
|
||||
StoredMaxX = (MinX > MaxX) ? MinX: MaxX ;
|
||||
StoredMaxY = (MinY > MaxY) ? MinY: MaxY ;
|
||||
|
||||
if (Draw) // move : draw
|
||||
{
|
||||
aRect.setRect( StoredMinX, StoredMinY, abs(StoredMaxX-StoredMinX), abs(StoredMaxY-StoredMinY));
|
||||
thePainter.drawRect(aRect);
|
||||
m_IsVisible = true;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void View::onImportObject()
|
||||
{
|
||||
Application::getApplication()->importBREP();
|
||||
}
|
||||
|
||||
void View::setCurrentAction()
|
||||
{
|
||||
myCurrentMode = CurAction3d_MagnifyView;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
Handle(V3d_View)& View::getView()
|
||||
{
|
||||
return myView;
|
||||
}
|
||||
|
||||
void View::startAction( ViewOperations::Action action )
|
||||
{
|
||||
switch( action ) {
|
||||
case ViewOperations::ViewFitAllId :
|
||||
myView->FitAll();
|
||||
break;
|
||||
case ViewOperations::ViewFitAreaId :
|
||||
myCurrentMode = CurAction3d_WindowZooming;
|
||||
break;
|
||||
case ViewOperations::ViewZoomId :
|
||||
myCurrentMode = CurAction3d_DynamicZooming;
|
||||
break;
|
||||
case ViewOperations::ViewPanId :
|
||||
myCurrentMode = CurAction3d_DynamicPanning;
|
||||
break;
|
||||
case ViewOperations::ViewGlobalPanId :
|
||||
myCurZoom = myView->Scale();
|
||||
// Do a Global Zoom
|
||||
myView->FitAll();
|
||||
// Set the mode
|
||||
myCurrentMode = CurAction3d_GlobalPanning;
|
||||
break;
|
||||
case ViewOperations::ViewFrontId :
|
||||
myView->SetProj( V3d_Xpos );
|
||||
myView->FitAll();
|
||||
break;
|
||||
case ViewOperations::ViewBackId :
|
||||
myView->SetProj( V3d_Xneg );
|
||||
myView->FitAll();
|
||||
break;
|
||||
case ViewOperations::ViewTopId :
|
||||
myView->SetProj( V3d_Zpos );
|
||||
myView->FitAll();
|
||||
break;
|
||||
case ViewOperations::ViewBottomId :
|
||||
myView->SetProj( V3d_Zneg );
|
||||
myView->FitAll();
|
||||
break;
|
||||
case ViewOperations::ViewLeftId :
|
||||
myView->SetProj( V3d_Ypos );
|
||||
myView->FitAll();
|
||||
break;
|
||||
case ViewOperations::ViewRightId :
|
||||
myView->SetProj( V3d_Yneg );
|
||||
myView->FitAll();
|
||||
break;
|
||||
case ViewOperations::ViewAxoId :
|
||||
myView->SetProj( V3d_XposYnegZpos );
|
||||
myView->FitAll();
|
||||
break;
|
||||
case ViewOperations::ViewRotationId :
|
||||
myCurrentMode = CurAction3d_DynamicRotation;
|
||||
break;
|
||||
case ViewOperations::ViewResetId :
|
||||
myView->Reset();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void View::onCreateShape()
|
||||
{
|
||||
myView->SetScale(3.0316);
|
||||
if ( !myShapeDlg )
|
||||
myShapeDlg = new ShapeDlg( Application::getApplication(), myView, myContext );
|
||||
myShapeDlg->show();
|
||||
}
|
||||
|
||||
void View::onLoadBox()
|
||||
{
|
||||
myView->SetScale(1.0);
|
||||
Standard_Real size = myContext->CurrentViewer()->DefaultViewSize() / 4.;
|
||||
gp_Pnt origin( -size / 2., -size / 2., -size / 2. );
|
||||
//myContext->DefaultDrawer()->ShadingAspect()->SetColor(Quantity_NOC_RED);
|
||||
Handle(AIS_Shape) box =
|
||||
new AIS_Shape( BRepPrimAPI_MakeBox( origin, size, size, size ).Shape() );
|
||||
myContext->SetDisplayMode( box, myMDI->getDisplayMode(), false );
|
||||
|
||||
Application::startTimer();
|
||||
myContext->Display( box, false );
|
||||
Application::stopTimer( 0, "Display Box" );
|
||||
|
||||
Application::startTimer();
|
||||
myView->Update();
|
||||
Application::stopTimer( 0, "UPDATE" );
|
||||
}
|
||||
|
||||
void View::onLoadSphere()
|
||||
{
|
||||
myView->SetScale(1.0);
|
||||
Standard_Real radius = myContext->CurrentViewer()->DefaultViewSize() / 4.;
|
||||
Handle(AIS_Shape) sphere =
|
||||
new AIS_Shape( BRepPrimAPI_MakeSphere( radius ).Shape() );
|
||||
myContext->SetDisplayMode( sphere, myMDI->getDisplayMode(), false );
|
||||
|
||||
Application::startTimer();
|
||||
myContext->Display( sphere, false );
|
||||
Application::stopTimer( 0, "Display Sphere" );
|
||||
|
||||
Application::startTimer();
|
||||
//myContext->UpdateCurrentViewer();
|
||||
myView->Update();
|
||||
Application::stopTimer( 0, "UPDATE" );
|
||||
}
|
||||
|
||||
void View::onLoadTorus()
|
||||
{
|
||||
myView->SetScale(1.0);
|
||||
Handle(V3d_Viewer) viewer = myContext->CurrentViewer();
|
||||
Standard_Real r1 = viewer->DefaultViewSize() / 3.;
|
||||
Standard_Real r2 = viewer->DefaultViewSize() / 6.;
|
||||
Handle(AIS_Shape) torus = new AIS_Shape( BRepPrimAPI_MakeTorus( r1,r2 ).Shape() );
|
||||
myContext->SetDisplayMode( torus, myMDI->getDisplayMode(), false );
|
||||
|
||||
Application::startTimer();
|
||||
myContext->Display( torus, false );
|
||||
Application::stopTimer( 0, "Display Torus" );
|
||||
|
||||
Application::startTimer();
|
||||
//myContext->UpdateCurrentViewer();
|
||||
myView->Update();
|
||||
Application::stopTimer( 0, "UPDATE" );
|
||||
}
|
||||
|
||||
void View::onLoadLine()
|
||||
{
|
||||
myView->SetScale(1.0);
|
||||
Handle(AIS_Line) line =
|
||||
new AIS_Line( new Geom_Line( gp_Pnt( 0, 0, 0), gp_Dir( 0, 0, 1) ) );
|
||||
myContext->Display( line );
|
||||
myContext->UpdateCurrentViewer();
|
||||
}
|
||||
|
||||
void View::onEditObjectProperties()
|
||||
{
|
||||
if ( !myObjDlg )
|
||||
myObjDlg = new ObjectDlg( Application::getApplication(), myView, myContext );
|
||||
myObjDlg->show();
|
||||
}
|
||||
|
||||
void View::onRemoveObject()
|
||||
{
|
||||
myContext->InitSelected();
|
||||
for( ; myContext->MoreSelected(); myContext->InitSelected() )
|
||||
myContext->Remove( myContext->SelectedInteractive(), false );
|
||||
myContext->UpdateCurrentViewer();
|
||||
}
|
||||
|
||||
void View::onWireframeMode()
|
||||
{
|
||||
myContext->InitSelected();
|
||||
for( ; myContext->MoreSelected(); myContext->NextSelected() ) {
|
||||
Handle(AIS_InteractiveObject) obj = myContext->SelectedInteractive();
|
||||
//myContext->Erase( obj, false );
|
||||
//myContext->Display( obj, /*0, 0,*/ false );
|
||||
//myContext->Activate( obj, 0 );
|
||||
myContext->SetDisplayMode( obj, 0 );
|
||||
}
|
||||
myContext->UpdateCurrentViewer();
|
||||
}
|
||||
|
||||
void View::onShadingMode()
|
||||
{
|
||||
|
||||
myContext->InitSelected();
|
||||
for( ; myContext->MoreSelected(); myContext->NextSelected() ) {
|
||||
Handle(AIS_InteractiveObject) obj = myContext->SelectedInteractive();
|
||||
//myContext->Erase( obj, false );
|
||||
//myContext->Display( obj /*, 1, 0*/, false );
|
||||
//myContext->Activate( obj, 0 );
|
||||
myContext->SetDisplayMode( obj, 1 );
|
||||
}
|
||||
myContext->UpdateCurrentViewer();
|
||||
|
||||
}
|
||||
|
||||
void View::onDisplayTrihedron()
|
||||
{
|
||||
myContext->Display( myTrihedron );
|
||||
}
|
||||
|
||||
void View::onEraseTrihedron()
|
||||
{
|
||||
myContext->Erase( myTrihedron );
|
||||
}
|
||||
|
248
samples/qt/Graphic3dDemo/src/ViewDlg.cxx
Executable file
248
samples/qt/Graphic3dDemo/src/ViewDlg.cxx
Executable file
@@ -0,0 +1,248 @@
|
||||
// ViewDlg.cpp: implementation of the ViewDlg class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <qlayout.h>
|
||||
#include <qpushbutton.h>
|
||||
#include <qframe.h>
|
||||
#include <qcheckbox.h>
|
||||
#include <qlabel.h>
|
||||
#include <qcombobox.h>
|
||||
|
||||
#include <V3d_TypeOfVisualization.hxx>
|
||||
|
||||
#include "Application.h"
|
||||
#include "ViewDlg.h"
|
||||
#include "global.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
ViewDlg::ViewDlg( QWidget* parent/*, Handle(V3d_View)& view*/ )
|
||||
:QDialog( parent ),
|
||||
myAutoApply( true ), /*myView( view ),*/ myApplyAllViews(false)
|
||||
{
|
||||
setModal( false );
|
||||
setWindowTitle( tr( "TITLE_VIEW_DLG" ) );
|
||||
|
||||
QVBoxLayout* topLayout = new QVBoxLayout( this );
|
||||
topLayout->setMargin( 5 );
|
||||
|
||||
QFrame* mainFrame = new QFrame( this );
|
||||
mainFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
|
||||
topLayout->addWidget( mainFrame );
|
||||
topLayout->addSpacing( 10 );
|
||||
|
||||
// view properties
|
||||
QGridLayout* pLayout = new QGridLayout( mainFrame );
|
||||
pLayout->setMargin( 5 );
|
||||
myZBufferBox = new QCheckBox( mainFrame );;
|
||||
myZBufferBox->setText( tr( "BTN_ZBUFFER" ) );
|
||||
verify( connect( myZBufferBox, SIGNAL( toggled( bool ) ), SLOT( onZBuffer( bool ) ) ) );
|
||||
|
||||
myAnimBox = new QCheckBox( mainFrame );
|
||||
myAnimBox->setText( tr( "BTN_ANIMATION" ) );
|
||||
verify( connect( myAnimBox, SIGNAL( toggled( bool ) ), SLOT( onAnimation( bool ) ) ) );
|
||||
|
||||
myDegBox = new QCheckBox( mainFrame );
|
||||
myDegBox->setText( tr( "BTN_DEGENERATION" ) );
|
||||
verify( connect( myDegBox, SIGNAL( toggled( bool ) ), SLOT( onDegeneration( bool ) ) ) );
|
||||
|
||||
pLayout->addWidget( myZBufferBox, 0, 0 );
|
||||
pLayout->addWidget( myAnimBox, 1, 0 );
|
||||
pLayout->addWidget( myDegBox, 2, 0 );
|
||||
pLayout->setRowStretch( 3, 10 );
|
||||
pLayout->setColumnStretch( 1, 10 );
|
||||
|
||||
// apply controls
|
||||
QCheckBox *autoApply, *applyAllViews;
|
||||
autoApply = new QCheckBox( this );
|
||||
autoApply->setText( tr( "BTN_AUTOAPPLY" ) );
|
||||
autoApply->setChecked( true );
|
||||
verify( connect( autoApply, SIGNAL( toggled( bool ) ), SLOT( onAutoApply( bool ) ) ) );
|
||||
applyAllViews = new QCheckBox( this );
|
||||
applyAllViews->setText( tr( "BTN_APPLYALLVIEWS" ) );
|
||||
verify( connect( applyAllViews, SIGNAL( toggled( bool ) ),
|
||||
SLOT( onApplyAllViews( bool ) ) ) );
|
||||
|
||||
QHBoxLayout* applyLayout = new QHBoxLayout();
|
||||
applyLayout->addWidget( autoApply );
|
||||
applyLayout->addStretch( 10 );
|
||||
applyLayout->addWidget( applyAllViews );
|
||||
topLayout->addLayout( applyLayout );
|
||||
topLayout->addSpacing( 10 );
|
||||
|
||||
// control buttons
|
||||
QPushButton *bOk, *bCancel/*, *bHelp*/;
|
||||
|
||||
bOk = new QPushButton( tr( "BTN_OK" ), this );
|
||||
verify( connect( bOk, SIGNAL( clicked() ), SLOT( onOk() ) ) );
|
||||
bOk->setDefault(true);
|
||||
bCancel = new QPushButton( tr( "BTN_CANCEL" ), this );
|
||||
verify( connect( bCancel, SIGNAL( clicked() ), SLOT( onCancel() ) ) );
|
||||
|
||||
|
||||
// bHelp = new QPushButton( tr( "BTN_HELP" ), this );
|
||||
// verify( connect( bHelp, SIGNAL( clicked() ), SLOT( onHelp() ) ) );
|
||||
|
||||
QHBoxLayout* btnLayout = new QHBoxLayout();
|
||||
btnLayout->setSpacing( 5 );
|
||||
btnLayout->addStretch( 10 );
|
||||
btnLayout->addWidget( bOk );
|
||||
btnLayout->addWidget( bCancel );
|
||||
btnLayout->addStretch( 10 );
|
||||
// btnLayout->addWidget( bHelp );
|
||||
topLayout->addLayout( btnLayout );
|
||||
|
||||
QSize s = topLayout->totalMinimumSize();
|
||||
s.setWidth( s.width() + topLayout->margin() + 10 );
|
||||
s.setHeight( s.height() + topLayout->margin() + 10 );
|
||||
setFixedSize( s );
|
||||
|
||||
Handle(V3d_View) aView = Application::getApplication()->getActiveMDI()->getView();
|
||||
myIsAnim = aView->AnimationMode(myIsDeg);
|
||||
}
|
||||
|
||||
ViewDlg::~ViewDlg()
|
||||
{
|
||||
}
|
||||
|
||||
void ViewDlg::showEvent ( QShowEvent* e )
|
||||
{
|
||||
Update();
|
||||
QWidget::showEvent( e );
|
||||
}
|
||||
|
||||
void ViewDlg::onOk()
|
||||
{
|
||||
hide();
|
||||
bool Auto = myAutoApply;
|
||||
|
||||
myAutoApply = true;
|
||||
onZBuffer(myZBufferBox->isChecked());
|
||||
onAnimation(myAnimBox->isChecked());
|
||||
onDegeneration(myDegBox->isChecked());
|
||||
myAutoApply = Auto;
|
||||
}
|
||||
|
||||
void ViewDlg::onCancel()
|
||||
{
|
||||
hide();
|
||||
}
|
||||
|
||||
void ViewDlg::onHelp()
|
||||
{
|
||||
}
|
||||
|
||||
void ViewDlg::onZBuffer( bool on )
|
||||
{
|
||||
QWidgetList aWidgetList;
|
||||
Handle(V3d_View) aView;
|
||||
QWidget* aWidget;
|
||||
|
||||
if (!myApplyAllViews)
|
||||
aWidgetList.append(Application::getApplication()->getActiveMDI());
|
||||
else
|
||||
aWidgetList = Application::getWorkspace()->windowList();
|
||||
|
||||
if ( myAutoApply ){
|
||||
foreach(aWidget, aWidgetList){
|
||||
if ( !aWidget ) continue;
|
||||
MDIWindow* aMDIWindow = (MDIWindow*)aWidget;
|
||||
aView = aMDIWindow->getView();
|
||||
if ( on )
|
||||
aView->SetVisualization( V3d_ZBUFFER );
|
||||
else
|
||||
aView->SetVisualization( V3d_WIREFRAME );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ViewDlg::onAnimation( bool on )
|
||||
{
|
||||
QWidgetList aWidgetList;
|
||||
Handle(V3d_View) aView;
|
||||
|
||||
myIsAnim = on;
|
||||
myDegBox->setEnabled( myIsAnim );
|
||||
if (!myIsAnim) myDegBox->setChecked(false);
|
||||
|
||||
if (!myApplyAllViews)
|
||||
aWidgetList.append(Application::getApplication()->getActiveMDI());
|
||||
else
|
||||
aWidgetList = Application::getWorkspace()->windowList();
|
||||
|
||||
if ( myAutoApply ){
|
||||
QWidget* aWidget;
|
||||
foreach(aWidget, aWidgetList){
|
||||
if ( !aWidget ) continue;
|
||||
MDIWindow* aMDIWindow = (MDIWindow*)aWidget;
|
||||
aView = aMDIWindow->getView();
|
||||
aView->SetAnimationMode( myIsAnim, myIsDeg );
|
||||
aView->Redraw();
|
||||
aView->SetImmediateUpdate(true);
|
||||
aView->Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ViewDlg::onDegeneration( bool on )
|
||||
{
|
||||
QWidgetList aWidgetList;
|
||||
Handle(V3d_View) aView;
|
||||
QWidget* aWidget;
|
||||
|
||||
if (!myApplyAllViews)
|
||||
aWidgetList.append(Application::getApplication()->getActiveMDI());
|
||||
else
|
||||
aWidgetList = Application::getWorkspace()->windowList();
|
||||
|
||||
|
||||
myIsDeg = on;
|
||||
if ( myAutoApply ){
|
||||
foreach(aWidget, aWidgetList){
|
||||
if ( !aWidget ) continue;
|
||||
MDIWindow* aMDIWindow = (MDIWindow*)aWidget;
|
||||
aView = aMDIWindow->getView();
|
||||
aView->SetAnimationMode( myIsAnim, myIsDeg );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ViewDlg::onAutoApply( bool on )
|
||||
{
|
||||
myAutoApply = on;
|
||||
}
|
||||
|
||||
void ViewDlg::onApplyAllViews( bool on )
|
||||
{
|
||||
myApplyAllViews = on;
|
||||
}
|
||||
|
||||
void ViewDlg::Update()
|
||||
{
|
||||
MDIWindow* anActiveMDIWindow = Application::getApplication()->getActiveMDI();
|
||||
if (anActiveMDIWindow){
|
||||
Handle(V3d_View) aView = anActiveMDIWindow->getView();
|
||||
if(!aView.IsNull()){
|
||||
|
||||
myIsAnim = aView->AnimationMode( myIsDeg );
|
||||
myAnimBox->blockSignals( true );
|
||||
myDegBox->blockSignals( true );
|
||||
myAnimBox->setChecked( myIsAnim );
|
||||
myDegBox->setChecked( myIsDeg );
|
||||
myDegBox->setEnabled( myIsAnim );
|
||||
myAnimBox->blockSignals( false );
|
||||
myDegBox->blockSignals( false );
|
||||
|
||||
myZBufferBox->blockSignals(true);
|
||||
V3d_TypeOfVisualization aVisuType = aView->Visualization();
|
||||
if(aVisuType == V3d_WIREFRAME)
|
||||
myZBufferBox -> setChecked(false);
|
||||
else
|
||||
myZBufferBox -> setChecked(true);
|
||||
myZBufferBox->blockSignals(false);
|
||||
}
|
||||
}
|
||||
}
|
328
samples/qt/Graphic3dDemo/src/ViewOperations.cxx
Executable file
328
samples/qt/Graphic3dDemo/src/ViewOperations.cxx
Executable file
@@ -0,0 +1,328 @@
|
||||
#include "ViewOperations.h"
|
||||
#include "global.h"
|
||||
//#include "Material.h"
|
||||
//#include "Transparency.h"
|
||||
#include "Application.h"
|
||||
#include "Document.h"
|
||||
|
||||
#include <qcolordialog.h>
|
||||
#include <qapplication.h>
|
||||
#include <qsignalmapper.h>
|
||||
#include <qworkspace.h>
|
||||
#include <qpixmap.h>
|
||||
#include <qcursor.h>
|
||||
#include <qaction.h>
|
||||
|
||||
#include <V3d_TypeOfView.hxx>
|
||||
#include <AIS_InteractiveObject.hxx>
|
||||
#include <AIS_ListOfInteractive.hxx>
|
||||
#include <AIS_ListIteratorOfListOfInteractive.hxx>
|
||||
|
||||
#include <Quantity_Color.hxx>
|
||||
|
||||
|
||||
static QCursor* defCursor = NULL;
|
||||
static QCursor* handCursor = NULL;
|
||||
static QCursor* panCursor = NULL;
|
||||
static QCursor* zoomCursor = NULL;
|
||||
static QCursor* rotCursor = NULL;
|
||||
|
||||
ViewOperations::ViewOperations( QObject* parent)
|
||||
: QObject( parent )
|
||||
{
|
||||
myContext = NULL;
|
||||
}
|
||||
|
||||
ViewOperations::ViewOperations( Handle(AIS_InteractiveContext) theContext,
|
||||
QObject* parent)
|
||||
: QObject( parent )
|
||||
{
|
||||
myContext = theContext;
|
||||
initActions();
|
||||
initViewActions();
|
||||
}
|
||||
|
||||
ViewOperations::~ViewOperations()
|
||||
{
|
||||
myContext = NULL;
|
||||
}
|
||||
|
||||
void ViewOperations::onWireframe()
|
||||
{
|
||||
AIS_ListOfInteractive displayed;
|
||||
myContext->DisplayedObjects( displayed );
|
||||
AIS_ListIteratorOfListOfInteractive it( displayed );
|
||||
for ( ; it.More(); it.Next() )
|
||||
myContext->SetDisplayMode( it.Value(), 0 );
|
||||
#ifdef a
|
||||
for(myContext->InitCurrent();myContext->MoreCurrent();myContext->NextCurrent())
|
||||
myContext->SetDisplayMode(myContext->Current(),0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ViewOperations::onShading()
|
||||
{
|
||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||
|
||||
AIS_ListOfInteractive displayed;
|
||||
myContext->DisplayedObjects( displayed );
|
||||
AIS_ListIteratorOfListOfInteractive it( displayed );
|
||||
for ( ; it.More(); it.Next() )
|
||||
myContext->SetDisplayMode( it.Value(), 1 );
|
||||
|
||||
#ifdef a
|
||||
for(myContext->InitCurrent();myContext->MoreCurrent();myContext->NextCurrent())
|
||||
myContext->SetDisplayMode(myContext->Current(),1);
|
||||
#endif
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
void ViewOperations::initActions()
|
||||
{
|
||||
initCursors();
|
||||
initToolActions();
|
||||
}
|
||||
|
||||
void ViewOperations::initCursors()
|
||||
{
|
||||
if( !defCursor )
|
||||
defCursor = new QCursor( Qt::ArrowCursor );
|
||||
if( !handCursor )
|
||||
handCursor = new QCursor( Qt::PointingHandCursor );
|
||||
if( !panCursor )
|
||||
panCursor = new QCursor( Qt::SizeAllCursor );
|
||||
|
||||
QString dir( Application::getResourceDir() );
|
||||
if( !zoomCursor )
|
||||
zoomCursor = new QCursor( QPixmap( dir + tr( "ICON_CURSOR_ZOOM" ) ) );
|
||||
if( !rotCursor )
|
||||
rotCursor = new QCursor( QPixmap( dir + tr( "ICON_CURSOR_ROTATE" ) ) );
|
||||
}
|
||||
|
||||
QList<QAction*> ViewOperations::getViewActions()
|
||||
{
|
||||
return myViewActions;
|
||||
}
|
||||
|
||||
void ViewOperations::initViewActions()
|
||||
{
|
||||
if ( myViewActions.count() )
|
||||
return;
|
||||
|
||||
QString dir = Application::getResourceDir();
|
||||
|
||||
QAction* a;
|
||||
|
||||
a = new QAction( QPixmap( dir + tr( "ICON_VIEW_FITALL" ) ), "", this );
|
||||
a->setToolTip( tr( "TBR_FITALL" ) );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
|
||||
myViewActions.insert( ViewFitAllId, a );
|
||||
|
||||
a = new QAction( QPixmap( dir + tr( "ICON_VIEW_FITAREA" ) ), "", this );
|
||||
a->setToolTip( tr( "TBR_FITAREA" ) );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
|
||||
a->setCheckable( true );
|
||||
verify( connect( a, SIGNAL( toggled( bool ) ), SLOT( updateToggled( bool ) ) ) );
|
||||
myViewActions.insert( ViewFitAreaId, a );
|
||||
|
||||
a = new QAction( QPixmap( dir + tr( "ICON_VIEW_ZOOM" ) ), "", this );
|
||||
a->setToolTip( tr( "TBR_ZOOM" ) );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
|
||||
a->setCheckable( true );
|
||||
verify( connect( a, SIGNAL( toggled( bool ) ), SLOT( updateToggled( bool ) ) ) );
|
||||
myViewActions.insert( ViewZoomId, a );
|
||||
|
||||
a = new QAction( QPixmap( dir + tr( "ICON_VIEW_PAN" ) ), "", this );
|
||||
a->setToolTip( tr( "TBR_PAN" ) );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
|
||||
a->setCheckable( true );
|
||||
verify( connect( a, SIGNAL( toggled( bool ) ), SLOT( updateToggled( bool ) ) ) );
|
||||
myViewActions.insert( ViewPanId, a );
|
||||
|
||||
a = new QAction( QPixmap( dir + tr( "ICON_VIEW_GLOBALPAN" ) ), "", this );
|
||||
a->setToolTip( tr( "TBR_GLOBALPAN" ) );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
|
||||
a->setCheckable( true );
|
||||
verify( connect( a, SIGNAL( toggled( bool ) ), SLOT( updateToggled( bool ) ) ) );
|
||||
myViewActions.insert( ViewGlobalPanId, a );
|
||||
|
||||
a = new QAction( QPixmap( dir + tr( "ICON_VIEW_FRONT" ) ), "", this );
|
||||
a->setToolTip( tr( "TBR_FRONT" ) );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
|
||||
myViewActions.insert( ViewFrontId, a );
|
||||
|
||||
a = new QAction( QPixmap( dir + tr( "ICON_VIEW_BACK" ) ), "", this );
|
||||
a->setToolTip( tr( "TBR_BACK" ) );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
|
||||
myViewActions.insert( ViewBackId, a );
|
||||
|
||||
a = new QAction( QPixmap( dir + tr( "ICON_VIEW_TOP" ) ), "", this );
|
||||
a->setToolTip( tr( "TBR_TOP" ) );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
|
||||
myViewActions.insert( ViewTopId, a );
|
||||
|
||||
a = new QAction( QPixmap( dir + tr( "ICON_VIEW_BOTTOM" ) ), "", this );
|
||||
a->setToolTip( tr( "TBR_BOTTOM" ) );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
|
||||
myViewActions.insert( ViewBottomId, a );
|
||||
|
||||
a = new QAction( QPixmap( dir + tr( "ICON_VIEW_LEFT" ) ), "", this );
|
||||
a->setToolTip( tr( "TBR_LEFT" ) );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
|
||||
myViewActions.insert( ViewLeftId, a );
|
||||
|
||||
a = new QAction( QPixmap( dir + tr( "ICON_VIEW_RIGHT" ) ), "", this );
|
||||
a->setToolTip( tr( "TBR_RIGHT" ) );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
|
||||
myViewActions.insert( ViewRightId, a );
|
||||
|
||||
a = new QAction( QPixmap( dir + tr( "ICON_VIEW_AXO" ) ), "", this );
|
||||
a->setToolTip( tr( "TBR_AXO" ) );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
|
||||
myViewActions.insert( ViewAxoId, a );
|
||||
|
||||
a = new QAction( QPixmap( dir + tr( "ICON_VIEW_ROTATION" ) ), "", this );
|
||||
a->setToolTip( tr( "TBR_ROTATION" ) );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
|
||||
a->setCheckable( true );
|
||||
verify( connect( a, SIGNAL( toggled( bool ) ), SLOT( updateToggled( bool ) ) ) );
|
||||
myViewActions.insert( ViewRotationId, a );
|
||||
|
||||
a = new QAction( QPixmap( dir + tr( "ICON_VIEW_RESET" ) ), "", this );
|
||||
a->setToolTip( tr( "TBR_RESET" ) );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
|
||||
myViewActions.insert( ViewResetId, a );
|
||||
}
|
||||
|
||||
void ViewOperations::updateToggled( bool isOn )
|
||||
{
|
||||
if( !isOn )
|
||||
return;
|
||||
|
||||
QAction* sentBy = (QAction*) sender();
|
||||
|
||||
for ( int i = ViewFitAllId;i <= ViewResetId ; 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))
|
||||
emit setCursor(*handCursor);
|
||||
else if (sentBy == myViewActions.at(ViewZoomId))
|
||||
emit setCursor(*zoomCursor);
|
||||
else if (sentBy == myViewActions.at(ViewPanId))
|
||||
emit setCursor(*panCursor);
|
||||
else if (sentBy == myViewActions.at(ViewGlobalPanId))
|
||||
emit setCursor(*defCursor);
|
||||
else if (sentBy == myViewActions.at(ViewRotationId))
|
||||
emit setCursor(*rotCursor);
|
||||
sentBy->setCheckable(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QList<QAction*> ViewOperations::getToolActions()
|
||||
{
|
||||
initToolActions();
|
||||
return myToolActions;
|
||||
}
|
||||
|
||||
void ViewOperations::initToolActions()
|
||||
{
|
||||
if( myToolActions.count() )
|
||||
return;
|
||||
|
||||
QString dir = Application::getResourceDir();
|
||||
|
||||
//QAction* a = new QAction( tr( "TBR_TOOL_MAGVIEW" ), QPixmap( dir + tr( "ICON_TOOL_WIRE" ) ),
|
||||
// "", 0, this );
|
||||
//verify( connect( a, SIGNAL( activated() ), SLOT( onToolAction() ) ) );
|
||||
//myToolActions->insert( MagViewId, a );
|
||||
|
||||
// QAction* a = new QAction( tr( "TBR_TOOL_AXOVIEW" ), QPixmap( dir + tr( "ICON_TOOL_WIRE" ) ),
|
||||
// "", 0, this );
|
||||
// verify( connect( a, SIGNAL( activated() ), SLOT( onToolAction() ) ) );
|
||||
// myToolActions->insert( AxoViewId, a );
|
||||
|
||||
// a = new QAction( tr( "TBR_TOOL_PERVIEW" ), QPixmap( dir + tr( "ICON_TOOL_WIRE" ) ),
|
||||
// "", 0, this );
|
||||
// verify( connect( a, SIGNAL( activated() ), SLOT( onToolAction() ) ) );
|
||||
// myToolActions->insert( PerViewId, a );
|
||||
|
||||
QAction* a = new QAction( QPixmap( dir + tr( "ICON_TOOL_WIRE" ) ), "", this );
|
||||
a->setToolTip( tr( "TBR_TOOL_WIRE" ) );
|
||||
a->setCheckable( true );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onToolAction() ) ) );
|
||||
myToolActions.insert( ToolWireframeId, a );
|
||||
|
||||
a = new QAction( QPixmap( dir + tr( "ICON_TOOL_SHAD") ), "", this );
|
||||
a->setToolTip( tr( "TBR_TOOL_SHAD" ) );
|
||||
a->setCheckable( true );
|
||||
a->setChecked( true );
|
||||
verify( connect( a, SIGNAL( activated() ), SLOT( onToolAction() ) ) );
|
||||
myToolActions.insert( ToolShadingId, a );
|
||||
}
|
||||
|
||||
void ViewOperations::onToolAction()
|
||||
{
|
||||
QAction* sentBy = (QAction*) sender();
|
||||
//MDIWindow* win = (MDIWindow*) Application::getWorkspace()->activeWindow();
|
||||
MDIWindow* win = (MDIWindow*)Application::getApplication()->getActiveMDI();
|
||||
Document* doc = win->getDocument();
|
||||
|
||||
// if( sentBy == myToolActions->at( MagViewId ) )
|
||||
// win->defineMagView();
|
||||
|
||||
// if( sentBy == myToolActions->at( PerViewId ) )
|
||||
// doc->createNewView( V3d_PERSPECTIVE );
|
||||
|
||||
// if( sentBy == myToolActions->at( AxoViewId ) )
|
||||
// doc->createNewView();
|
||||
|
||||
if( sentBy == myToolActions.at( ToolWireframeId ) )
|
||||
doc->onWireframe();
|
||||
|
||||
if( sentBy == myToolActions.at( ToolShadingId ) )
|
||||
doc->onShading();
|
||||
}
|
||||
|
||||
int ViewOperations::getDisplayMode()
|
||||
{
|
||||
bool on = myToolActions.at( ToolWireframeId )->isChecked();
|
||||
return on ? 0 : 1;
|
||||
}
|
||||
|
||||
void ViewOperations::onNoActiveActions()
|
||||
{
|
||||
for ( int i = ViewFitAllId;i <= ViewResetId ; 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 ) ) ) {
|
||||
|
||||
emit setCursor( *defCursor );
|
||||
anAction->setCheckable( true );
|
||||
anAction->setChecked( false );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ViewOperations::onActionActivated()
|
||||
{
|
||||
QAction* a = (QAction*) sender();
|
||||
//MDIWindow* win = (MDIWindow*) Application::getWorkspace()->activeWindow();
|
||||
MDIWindow* win = (MDIWindow*) Application::getApplication()->getActiveMDI();
|
||||
int index = myViewActions.indexOf( a );
|
||||
if ( index != -1 )
|
||||
win->activateAction( (Action)index );
|
||||
}
|
Reference in New Issue
Block a user