From c8e41e80a3d27b5ea9531ecdc977f3a465a43a88 Mon Sep 17 00:00:00 2001 From: jfa Date: Fri, 17 Aug 2007 10:15:40 +0000 Subject: [PATCH] Join modifications from V3_2_0_maintainance (V3_2_6pre4 - T32x_16Aug2007_16h00m) --- src/LightApp/LightApp_Selection.cxx | 5 +- src/PythonConsole/PythonConsole_PyEditor.cxx | 113 +++++++++++++++---- src/PythonConsole/PythonConsole_PyEditor.h | 8 +- src/SUIT/SUIT_Application.cxx | 11 +- src/SUIT/SUIT_Application.h | 6 + src/SUIT/SUIT_Session.cxx | 4 +- src/SUIT/SUIT_Study.cxx | 14 +-- src/SUIT/SUIT_Study.h | 1 - src/SalomeApp/SalomeApp_Application.cxx | 11 +- src/SalomeApp/SalomeApp_Application.h | 2 + src/SalomeApp/SalomeApp_Study.cxx | 9 ++ src/SalomeApp/SalomeApp_Study.h | 2 + src/VTKViewer/VTKViewer_ConvexTool.cxx | 71 +++++++++++- src/VTKViewer/VTKViewer_ConvexTool.h | 8 +- 14 files changed, 217 insertions(+), 48 deletions(-) diff --git a/src/LightApp/LightApp_Selection.cxx b/src/LightApp/LightApp_Selection.cxx index fe0a15207..4b7e58ae5 100644 --- a/src/LightApp/LightApp_Selection.cxx +++ b/src/LightApp/LightApp_Selection.cxx @@ -67,9 +67,10 @@ void LightApp_Selection::init( const QString& client, LightApp_SelectionMgr* mgr for( SUIT_Selector* selector = aSelectors.first(); selector; selector = aSelectors.next() ) { qDebug( selector->type() ); - if( selector->type()!=client ) + if( selector->type() != client && selector->isEnabled() ) { - mgr->selected( cur_sel, selector->type() ); + //mgr->selected( cur_sel, selector->type() ); + selector->selected( cur_sel ); SUIT_DataOwnerPtrList::const_iterator aLIt = cur_sel.begin(), aLLast = cur_sel.end(); for( ; aLIt!=aLLast; aLIt++ ) sel.append( *aLIt ); //check entry and don't append if such entry is in list already diff --git a/src/PythonConsole/PythonConsole_PyEditor.cxx b/src/PythonConsole/PythonConsole_PyEditor.cxx index 30291e0c4..21e2566f4 100755 --- a/src/PythonConsole/PythonConsole_PyEditor.cxx +++ b/src/PythonConsole/PythonConsole_PyEditor.cxx @@ -37,6 +37,7 @@ #include #include #include +#include using namespace std; @@ -138,7 +139,43 @@ void PythonConsole_PyEditor::setText(QString s) { int para=paragraphs()-1; int col=paragraphLength(para); - insertAt(s,para,col); + + // Limit length of the string because exception may occur if string too long (NPAL16033) + // Exception occurs if one of paragraphs of the input string "s" is too long. Now long + // paragraph is limited with threshold numbers of characters and finished by " ..." string. + // Note that first paragraph of the string is checked only because it is enough for bug fixing. + // If it will be insufficient for other cases then more complicated check should be implemented. + // At present it is not done because of possible performance problem. + + static int threshold = 50000; + long strLength = s.length(); + if ( col + strLength <= threshold || s.find( '\n' ) < threshold ) + insertAt(s,para,col); + else + { + if ( col >= threshold ) + { + if ( text( para ).right( 5 ) != QString( " ...\n" ) ) + insertAt(" ...\n",para,col); + } + else + { + long n = threshold - col; + s.truncate( n ); + if ( n >= 5 ) + { + s.at( n - 5 ) = QChar( ' ' ); + s.at( n - 4 ) = QChar( '.' ); + s.at( n - 3 ) = QChar( '.' ); + s.at( n - 2 ) = QChar( '.' ); + s.at( n - 1 ) = QChar( '\n' ); + } + else + s = " ...\n"; + insertAt(s,para,col); + } + } + int n = paragraphs()-1; setCursorPosition( n, paragraphLength(n)); } @@ -159,9 +196,12 @@ void PythonConsole_PyEditor::exec( const QString& command ) _currentPrompt = READY_PROMPT; _buf.truncate(0); _isInHistory = false; - setText( "\n" + _currentPrompt); - setText( command + "\n" ); - handleReturn(); + setText( "\n" + _currentPrompt); + // PAL15963 (Problem with option -u (--execute) of runSalome). + // Let events creating a study end before script execution starts + setText( command /*+ "\n"*/ ); + //handleReturn(); + qApp->postEvent( this, new QKeyEvent(QEvent::KeyPress,Key_Return,13,Qt::NoButton )); } void PythonConsole_PyEditor::execAndWait( const QString& command ) @@ -377,21 +417,22 @@ void PythonConsole_PyEditor::keyPressEvent( QKeyEvent* e ) else if ( ctrlPressed ) { moveCursor( QTextEdit::MoveUp, false ); } - else { - QString histLine = _currentPrompt; - if ( ! _isInHistory ) { - _isInHistory = true; - _currentCommand = text( endLine ).remove( 0, PROMPT_SIZE ); - _currentCommand.truncate( _currentCommand.length() - 1 ); - } - QString previousCommand = myInterp->getPrevious(); - if ( previousCommand.compare( BEGIN_HISTORY_PY ) != 0 ) - { - removeParagraph( endLine ); - histLine.append( previousCommand ); - append( histLine ); - } - moveCursor( QTextEdit::MoveEnd, false ); + else { + QString histLine = _currentPrompt; + if ( ! _isInHistory ) { + _isInHistory = true; + _currentCommand = text( endLine ).remove( 0, PROMPT_SIZE ); + _currentCommand.truncate( _currentCommand.length() - 1 ); + } + QString previousCommand = myInterp->getPrevious(); + if ( previousCommand.compare( BEGIN_HISTORY_PY ) != 0 ) + { + removeParagraph( endLine ); + histLine.append( previousCommand ); + append( histLine ); + } + moveCursor( QTextEdit::MoveEnd, false ); + scrollViewAfterHistoryUsing( previousCommand ); // NPAL16035 } break; } @@ -429,6 +470,7 @@ void PythonConsole_PyEditor::keyPressEvent( QKeyEvent* e ) } } moveCursor( QTextEdit::MoveEnd, false ); + scrollViewAfterHistoryUsing( nextCommand ); // NPAL16035 } break; } @@ -762,3 +804,36 @@ QPopupMenu* PythonConsole_PyEditor::createPopupMenu( const QPoint& pos ) return popup; } + +/*! + Scrolls view after use of history (Up/Down keys)to the left position if length + of command less than visible width of the view +*/ +void PythonConsole_PyEditor::scrollViewAfterHistoryUsing( const QString& command ) +{ + if ( !command.isEmpty() ) + { + if ( command == QString( BEGIN_HISTORY_PY ) ) + { + ensureCursorVisible(); + return; + } + + QFontMetrics aFM( currentFont() ); + int aCommandLength = aFM.width( command ) + aFM.width( READY_PROMPT ) + 5; + int aVisibleWidth = visibleWidth(); + QScrollBar* aBar = horizontalScrollBar(); + if ( aBar ) + { + if ( aCommandLength <= aVisibleWidth ) + aBar->setValue( aBar->minValue() ); + else if ( aVisibleWidth > 0 ) + { + double aRatio = aCommandLength / contentsWidth(); + double aPos = ( aBar->maxValue() - aBar->minValue() ) * aRatio; + aBar->setValue( (int)aPos ); + ensureCursorVisible(); + } + } + } +} diff --git a/src/PythonConsole/PythonConsole_PyEditor.h b/src/PythonConsole/PythonConsole_PyEditor.h index b353ee4da..d8a2acb30 100755 --- a/src/PythonConsole/PythonConsole_PyEditor.h +++ b/src/PythonConsole/PythonConsole_PyEditor.h @@ -55,13 +55,17 @@ protected: virtual void keyPressEvent (QKeyEvent* event); virtual void mousePressEvent (QMouseEvent* event); virtual void customEvent (QCustomEvent* event); - + public slots: void handleReturn(); void onPyInterpChanged( PyInterp_base* ); virtual QPopupMenu* createPopupMenu( const QPoint& ); - + +private: + + void scrollViewAfterHistoryUsing( const QString& command ); + private: QString _buf; QString _currentCommand; diff --git a/src/SUIT/SUIT_Application.cxx b/src/SUIT/SUIT_Application.cxx index bbe68030d..13821608c 100755 --- a/src/SUIT/SUIT_Application.cxx +++ b/src/SUIT/SUIT_Application.cxx @@ -34,11 +34,12 @@ Default constructor */ SUIT_Application::SUIT_Application() -: QObject( 0 ), -myStudy( 0 ), -myDesktop( 0 ), -myStatusLabel( 0 ) -{ + : QObject( 0 ), + myStudy( 0 ), + myDesktop( 0 ), + myStatusLabel( 0 ), + myIsInitiallyRegistered( false ) +{ } /*! diff --git a/src/SUIT/SUIT_Application.h b/src/SUIT/SUIT_Application.h index 0bf48847e..2bf9da355 100755 --- a/src/SUIT/SUIT_Application.h +++ b/src/SUIT/SUIT_Application.h @@ -109,6 +109,9 @@ public: //! Invokes application-specific "Select Directory" dialog and returns the selected directory name. virtual QString getDirectory( const QString& initial, const QString& caption, QWidget* parent ) = 0; + //! Perform required actions on the application, just registed in the session + virtual void Registered() { myIsInitiallyRegistered = true; }; + signals: void applicationClosed( SUIT_Application* ); void activated( SUIT_Application* ); @@ -163,6 +166,9 @@ protected: protected slots: virtual void onDesktopActivated(); +protected: + bool myIsInitiallyRegistered; //Registered(); } /*! diff --git a/src/SUIT/SUIT_Study.cxx b/src/SUIT/SUIT_Study.cxx index a3baef3ce..19dabb03b 100755 --- a/src/SUIT/SUIT_Study.cxx +++ b/src/SUIT/SUIT_Study.cxx @@ -511,18 +511,12 @@ bool SUIT_Study::hasTransaction() const { return false; } - -/*! - * \brief Stores the study state -*/ -int SUIT_Study::storeState() -{ - return -1; -} /*! - * \brief Restores the study state -*/ + * \brief Restores the study state. + */ void SUIT_Study::restoreState(int savePoint) { + // Redefined in SalomeApp_Study. + // Called from SALOME_Session_i::restoreVisualState(CORBA::Long theSavePoint) } diff --git a/src/SUIT/SUIT_Study.h b/src/SUIT/SUIT_Study.h index 156c6bc74..fc6c35f0c 100755 --- a/src/SUIT/SUIT_Study.h +++ b/src/SUIT/SUIT_Study.h @@ -75,7 +75,6 @@ public: bool suspend( SUIT_Operation* ); bool resume( SUIT_Operation* ); - virtual int storeState(); virtual void restoreState(int savePoint); signals: diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 93f1e10aa..4df0a4fab 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -154,11 +154,16 @@ void SalomeApp_Application::start() LightApp_Application::start(); SalomeApp_EventFilter::Init(); +} - static bool isFirst = true; - if ( isFirst ) { - isFirst = false; +/*!Just registered in the session*/ +void SalomeApp_Application::Registered() +{ + if (!myIsInitiallyRegistered) + { + myIsInitiallyRegistered = true; + // execute python scripts QString hdffile; QStringList pyfiles; diff --git a/src/SalomeApp/SalomeApp_Application.h b/src/SalomeApp/SalomeApp_Application.h index 09ece677d..893d53c1d 100644 --- a/src/SalomeApp/SalomeApp_Application.h +++ b/src/SalomeApp/SalomeApp_Application.h @@ -94,6 +94,8 @@ public: SUIT_ViewManager* newViewManager(const QString&); void updateSavePointDataObjects( SalomeApp_Study* ); + virtual void Registered(); + public slots: virtual bool onOpenDoc( const QString& ); virtual void onLoadDoc(); diff --git a/src/SalomeApp/SalomeApp_Study.cxx b/src/SalomeApp/SalomeApp_Study.cxx index 1fb4d0bdd..503438d4a 100644 --- a/src/SalomeApp/SalomeApp_Study.cxx +++ b/src/SalomeApp/SalomeApp_Study.cxx @@ -727,6 +727,15 @@ std::string SalomeApp_Study::getVisualComponentName() return "Interface Applicative"; } +/*! + * \brief Restores the study state + */ +void SalomeApp_Study::restoreState(int savePoint) +{ + SalomeApp_VisualState((SalomeApp_Application*)application()).restoreState(savePoint); +} + + /*! Slot: called on change of a root of a data model. Redefined from CAM_Study */ diff --git a/src/SalomeApp/SalomeApp_Study.h b/src/SalomeApp/SalomeApp_Study.h index ef5c127fd..707518a37 100644 --- a/src/SalomeApp/SalomeApp_Study.h +++ b/src/SalomeApp/SalomeApp_Study.h @@ -73,6 +73,8 @@ public: void setNameOfSavePoint(int savePoint, const QString& nameOfSavePoint); virtual std::string getVisualComponentName(); + virtual void restoreState(int savePoint); + protected: virtual void saveModuleData ( QString theModuleName, QStringList theListOfFiles ); virtual void openModuleData ( QString theModuleName, QStringList& theListOfFiles ); diff --git a/src/VTKViewer/VTKViewer_ConvexTool.cxx b/src/VTKViewer/VTKViewer_ConvexTool.cxx index 1ecabea6e..3a8680a40 100644 --- a/src/VTKViewer/VTKViewer_ConvexTool.cxx +++ b/src/VTKViewer/VTKViewer_ConvexTool.cxx @@ -47,6 +47,9 @@ #include #include #include +#include +#include +#include #ifdef _DEBUG_ static int DEBUG_TRIA_EXECUTE = 0; @@ -517,8 +520,15 @@ VTKViewer_Triangulator */ VTKViewer_OrderedTriangulator ::VTKViewer_OrderedTriangulator(): - myCell(vtkGenericCell::New()) -{} + myCell(vtkGenericCell::New()), + myBoundaryTris(vtkCellArray::New()), + myTriangle(vtkTriangle::New()), + myTriangulator(vtkOrderedTriangulator::New()) +{ + myBoundaryTris->Allocate(100); + myTriangulator->PreSortedOff(); + //myTriangulator->UseTemplatesOn(); +} /*! Destructor @@ -527,6 +537,9 @@ VTKViewer_OrderedTriangulator ::~VTKViewer_OrderedTriangulator() { myCell->Delete(); + myBoundaryTris->Delete(); + myTriangle->Delete(); + myTriangulator->Delete(); } vtkPoints* @@ -534,6 +547,39 @@ VTKViewer_OrderedTriangulator ::InitPoints() { myInput->GetCell(myCellId,myCell); + + int numPts = myCell->GetNumberOfPoints(); + if ( numPts > 0 ) + { + myTriangulator->InitTriangulation(0.0,1.0, 0.0,1.0, 0.0,1.0, numPts); + + vtkFloatingPointType x[3], p[3]; + vtkIdType ptId; + vtkFloatingPointType *bounds = myCell->GetBounds(); + + // Inject cell points into triangulation + for (int i=0; iPoints->GetPoint(i, x); + for (int j=0; j<3; j++) + p[j] = (x[j] - bounds[2*j]) / (bounds[2*j+1] - bounds[2*j]); + ptId = myCell->PointIds->GetId(i); + // myTriangulator->InsertPoint(ptId, x, x, 0); + myTriangulator->InsertPoint(ptId, x, p, 0); + }//for all points + + +// if ( myCell->IsPrimaryCell() ) //use templates if topology is fixed +// { +// int numEdges=myCell->GetNumberOfEdges(); +// myTriangulator->TemplateTriangulate(myCell->GetCellType(), +// numPts,numEdges); +// } +// else //use ordered triangulator + { + myTriangulator->Triangulate(); + } + } return myInput->GetPoints(); } @@ -562,14 +608,31 @@ vtkIdType VTKViewer_OrderedTriangulator ::GetNumFaces() { - return myCell->GetNumberOfFaces(); + myBoundaryTris->Reset(); + myTriangulator->AddTriangles(myBoundaryTris); + return myBoundaryTris->GetNumberOfCells(); + //return myCell->GetNumberOfFaces(); } vtkCell* VTKViewer_OrderedTriangulator ::GetFace(vtkIdType theFaceId) { - return myCell->GetFace(theFaceId); + int numCells = myBoundaryTris->GetNumberOfCells(); + if ( theFaceId < 0 || theFaceId >=numCells ) {return NULL;} + + vtkIdType *cells = myBoundaryTris->GetPointer(); + + // Each triangle has three points plus number of points + vtkIdType *cptr = cells + 4*theFaceId; + for (int i=0; i<3; i++) + { + myTriangle->PointIds->SetId(i,cptr[i+1]); + myTriangle->Points->SetPoint(i,myCell->Points->GetPoint(cptr[i+1])); + } + + return myTriangle; + //return myCell->GetFace(theFaceId); } void diff --git a/src/VTKViewer/VTKViewer_ConvexTool.h b/src/VTKViewer/VTKViewer_ConvexTool.h index 2bf024d5e..46f5cdf6e 100644 --- a/src/VTKViewer/VTKViewer_ConvexTool.h +++ b/src/VTKViewer/VTKViewer_ConvexTool.h @@ -36,6 +36,9 @@ class vtkCellData; class vtkPoints; class vtkIdList; class vtkCell; +class vtkCellArray; +class vtkTriangle; +class vtkOrderedTriangulator; class VTKVIEWER_EXPORT VTKViewer_Triangulator { @@ -111,7 +114,10 @@ class VTKVIEWER_EXPORT VTKViewer_OrderedTriangulator : public VTKViewer_Triangul ~VTKViewer_OrderedTriangulator(); protected: - vtkGenericCell *myCell; + vtkGenericCell *myCell; + vtkCellArray *myBoundaryTris; + vtkTriangle *myTriangle; + vtkOrderedTriangulator *myTriangulator; virtual vtkPoints* -- 2.39.2