Salome HOME
Bug #141: Stream object.
authormzn <mzn@opencascade.com>
Tue, 3 Dec 2013 14:37:04 +0000 (14:37 +0000)
committermzn <mzn@opencascade.com>
Tue, 3 Dec 2013 14:37:04 +0000 (14:37 +0000)
src/HYDROGUI/HYDROGUI_StreamDlg.cxx
src/HYDROGUI/HYDROGUI_StreamDlg.h
src/HYDROGUI/HYDROGUI_StreamOp.cxx
src/HYDROGUI/HYDROGUI_StreamOp.h
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index cc8ba0f8ec3ac368fab96e1ce35363f9d4d86150..b1a208a88ae35365146341bd62238da0f640de20 100644 (file)
@@ -49,11 +49,11 @@ HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QStrin
   // Stream parameters
   QGroupBox* aParamGroup = new QGroupBox( tr( "STREAM_PARAMETERS" ), mainFrame() );
 
-  myAxises = new QComboBox( aParamGroup );
-  myAxises->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
+  myAxes = new QComboBox( aParamGroup );
+  myAxes->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
   QBoxLayout* anAxisLayout = new QHBoxLayout();
   anAxisLayout->addWidget( new QLabel( tr( "STREAM_HYDRAULIC_AXIS" ) ) );
-  anAxisLayout->addWidget( myAxises );
+  anAxisLayout->addWidget( myAxes );
 
   myProfiles = new QListWidget( aParamGroup );
   myProfiles->setSelectionMode( QListWidget::MultiSelection );
@@ -85,7 +85,7 @@ HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QStrin
   addStretch();
 
   // Connect signals and slots
-  connect( myAxises, SIGNAL( currentIndexChanged( const QString & ) ), 
+  connect( myAxes, SIGNAL( currentIndexChanged( const QString & ) ), 
            this, SIGNAL( AxisChanged( const QString& ) ) );
   connect( myAddButton, SIGNAL( clicked() ), this, SIGNAL( AddProfiles() ) );
   connect( myRemoveButton, SIGNAL( clicked() ), this, SLOT( onRemoveProfiles() ) );
@@ -101,13 +101,12 @@ void HYDROGUI_StreamDlg::reset()
 
   myObjectName->clear();
 
-  myAxises->clear();
+  myAxes->clear();
   myProfiles->clear();
   myAddButton->setEnabled( false );
+  myRemoveButton->setEnabled( false );
 
   blockSignals( isBlocked );
-
-  onStreamDefChanged();
 }
 
 void HYDROGUI_StreamDlg::setObjectName( const QString& theName )
@@ -124,76 +123,47 @@ void HYDROGUI_StreamDlg::setAxisNames( const QStringList& theAxises )
 {
   bool isBlocked = blockSignals( true );
 
-  myAxises->clear();
-  myAxises->addItems( theAxises );
+  myAxes->clear();
+  myAxes->addItems( theAxises );
 
   blockSignals( isBlocked );
 }
 
 void HYDROGUI_StreamDlg::setAxisName( const QString& theName )
 {
-  myAddButton->setEnabled( !myAxises->currentText().isEmpty() );
+  bool isBlocked = blockSignals( true );
 
-  int aNewIdx = myAxises->findText( theName );
-  if ( aNewIdx != myAxises->currentIndex() )
-  {
-    myAxises->setCurrentIndex( aNewIdx );
-  }
-  else
-  {
-    onStreamDefChanged();
+  int aNewId = myAxes->findText( theName );
+  if ( aNewId != myAxes->currentIndex() ) {
+    myAxes->setCurrentIndex( aNewId );
   }
+  myAddButton->setEnabled( myAxes->currentIndex() > -1 );
+
+  blockSignals( isBlocked );
 }
 
 QString HYDROGUI_StreamDlg::getAxisName() const
 {
-  return myAxises->currentText();
+  return myAxes->currentText();
 }
 
-void HYDROGUI_StreamDlg::setSelectedProfiles( const QStringList& theProfiles )
+void HYDROGUI_StreamDlg::setProfiles( const QStringList& theProfiles )
 {
   bool isBlocked = blockSignals( true );
 
   myProfiles->setUpdatesEnabled( false );
   
   myProfiles->clear();
-  for ( int i = 0, n = theProfiles.length(); i < n; ++i )
-  {
-    const QString& aProfileName = theProfiles.at( i );
+  foreach ( const QString& aProfileName, theProfiles ) {
     QListWidgetItem* aListItem = new QListWidgetItem( aProfileName, myProfiles );
     aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
   }
 
+  myRemoveButton->setEnabled( myProfiles->count() > 0 );
+
   myProfiles->setUpdatesEnabled( true );
 
   blockSignals( isBlocked );
-
-  onStreamDefChanged();
-}
-
-QStringList HYDROGUI_StreamDlg::getSelectedProfiles() const
-{
-  QStringList aProfiles;
-
-  for ( int i = 0, n = myProfiles->count(); i < n; ++i )
-  {
-    QListWidgetItem* aListItem = myProfiles->item( i );
-    if ( !aListItem )
-      continue;
-
-    QString aProfileName = aListItem->text();
-    aProfiles << aProfileName;
-  }
-
-  return aProfiles;
-}
-
-void HYDROGUI_StreamDlg::onStreamDefChanged()
-{
-  if ( signalsBlocked() )
-    return;
-
-  emit CreatePreview();
 }
 
 void HYDROGUI_StreamDlg::onRemoveProfiles()
index b78dc7190c35afb983856a5157313ccbef3b06e9..aa5bb80c91701850e3a545a9443a43e6a2087255 100644 (file)
@@ -45,28 +45,25 @@ public:
   QString                    getObjectName() const;
 
   void                       setAxisNames( const QStringList& theAxises );
+
   void                       setAxisName( const QString& thePolyline );
   QString                    getAxisName() const;
 
-  void                       setSelectedProfiles( const QStringList& theProfiles );
-  QStringList                getSelectedProfiles() const;
+  void                       setProfiles( const QStringList& theProfiles );
 
 signals:
-  void                       CreatePreview();
   void                       AddProfiles();
   void                       RemoveProfiles( const QStringList& );
   void                       AxisChanged( const QString& );
 
 private slots:
-  void                       onStreamDefChanged();
   void                       onRemoveProfiles();
 
 private:
-
   QGroupBox*                 myObjectNameGroup;
   QLineEdit*                 myObjectName;
 
-  QComboBox*                 myAxises;
+  QComboBox*                 myAxes;
   QListWidget*               myProfiles;
   QPushButton*               myRemoveButton;
   QPushButton*               myAddButton;
index 103d8bd3247d2e0526bc158f6fa695623d31b07d..a800239dbec50f754fffc06e6e6aed8661766eed 100755 (executable)
@@ -64,33 +64,35 @@ void HYDROGUI_StreamOp::startOperation()
   // We start operation in the document
   startDocOperation();
 
+  // Get panel and reset its state
   HYDROGUI_StreamDlg* aPanel = (HYDROGUI_StreamDlg*)inputPanel();
+  aPanel->reset();
 
-  if( myIsEdit )
+  // Get/create the edited object
+  if( myIsEdit ) {
     myEditedObject = Handle(HYDROData_Stream)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
-  else 
+  } else {
     myEditedObject = Handle(HYDROData_Stream)::DownCast( doc()->CreateObject( KIND_STREAM ) );
+  }
 
-  QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_STREAM_NAME" ) );
-  if ( myIsEdit && !myEditedObject.IsNull() ) {
+  // Get the edited object name
+  QString anObjectName; 
+  if ( !myIsEdit ) {
+    anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_STREAM_NAME" ) );
+  } else if ( !myEditedObject.IsNull() ) {
     anObjectName = myEditedObject->GetName();
   }
 
-  // Update panel data
-  aPanel->blockSignals( true );
-  aPanel->reset();
+  // Update the panel
+  // set the edited object name
   aPanel->setObjectName( anObjectName );
+  // set the existing 2D polylines names to the panel
   aPanel->setAxisNames( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINEXY ) );
-  aPanel->blockSignals( false );
-
-  if ( myIsEdit ) {
-    updatePanel();
-  } else {
-    onAxisChanged( aPanel->getAxisName() );
-  }
+  // synchronize the panel state with the edited object state
+  updatePanelData();
 
   // Create preview
-  onCreatePreview();
+  createPreview();
 }
 
 void HYDROGUI_StreamOp::abortOperation()
@@ -111,12 +113,13 @@ void HYDROGUI_StreamOp::commitOperation()
 HYDROGUI_InputPanel* HYDROGUI_StreamOp::createInputPanel() const
 {
   HYDROGUI_StreamDlg* aPanel = new HYDROGUI_StreamDlg( module(), getName() );
-  //TODO connect( aPanel, SIGNAL( CreatePreview() ), this, SLOT( onCreatePreview() ) );
+
   connect( aPanel, SIGNAL( AddProfiles() ), this, SLOT( onAddProfiles() ) );
   connect( aPanel, SIGNAL( RemoveProfiles( const QStringList& ) ), 
            this, SLOT( onRemoveProfiles( const QStringList& ) ) );
   connect( aPanel, SIGNAL( AxisChanged( const QString& ) ), 
            this, SLOT( onAxisChanged( const QString& ) ) );
+
   return aPanel;
 }
 
@@ -124,30 +127,27 @@ bool HYDROGUI_StreamOp::processApply( int& theUpdateFlags,
                                       QString& theErrorMsg )
 {
   HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
-  if ( !aPanel )
+  if ( !aPanel || myEditedObject.IsNull() ) {
     return false;
+  }
 
+  // Check whether the object name is not empty
   QString anObjectName = aPanel->getObjectName().simplified();
-  if ( anObjectName.isEmpty() )
-  {
+  if ( anObjectName.isEmpty() ) {
     theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
     return false;
   }
 
+  // Check that there are no other objects with the same name in the document
   if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
   {
-    // check that there are no other objects with the same name in the document
     Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
-    if( !anObject.IsNull() )
-    {
+    if( !anObject.IsNull() ) {
       theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
       return false;
     }
   }
 
-  if ( myEditedObject.IsNull() )
-    return false;
-
   // Check if the axis is set
   Handle(HYDROData_PolylineXY) aHydraulicAxis = myEditedObject->GetHydraulicAxis();
   if ( aHydraulicAxis.IsNull() ) {
@@ -155,55 +155,59 @@ bool HYDROGUI_StreamOp::processApply( int& theUpdateFlags,
     return false;
   }
 
-  // Check if the axis is set
+  // Check if at least 2 profiles is set
   HYDROData_SequenceOfObjects aProfiles = myEditedObject->GetProfiles();
   if ( aProfiles.Length() < 2 ) {
     theErrorMsg = tr( "PROFILES_NOT_DEFINED" );
     return false;
   }
 
+  // Set the object name
   myEditedObject->SetName( anObjectName );
 
+  // Erase preview
   erasePreview();
 
-  if( !myIsEdit )
+  // Show the object in case of creation mode of the operation
+  if( !myIsEdit ) {
     module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), myEditedObject, true );
+  }
 
+  // Set update flags
   theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced;
 
   return true;
 }
 
-void HYDROGUI_StreamOp::onCreatePreview()
+void HYDROGUI_StreamOp::createPreview()
 {
-  if ( myEditedObject.IsNull() )
+  if ( myEditedObject.IsNull() ) {
     return;
+  }
 
   LightApp_Application* anApp = module()->getApp();
-  if ( !myViewManager )
+  if ( !myViewManager ) {
     myViewManager = ::qobject_cast<OCCViewer_ViewManager*>( 
       anApp->getViewManager( OCCViewer_Viewer::Type(), true ) );
+  }
 
-  if ( myViewManager && !myPreviewPrs )
-  {
-    if ( OCCViewer_Viewer* aViewer = myViewManager->getOCCViewer() )
-    {
+  if ( myViewManager && !myPreviewPrs ) {
+    if ( OCCViewer_Viewer* aViewer = myViewManager->getOCCViewer() ) {
       Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
-      if ( !aCtx.IsNull() )
+      if ( !aCtx.IsNull() ) {
         myPreviewPrs = new HYDROGUI_Shape( aCtx, myEditedObject );
+      }
     }
   }
 
-  if ( !myViewManager || !myPreviewPrs )
-    return;
-
-  myPreviewPrs->update();
+  if ( myPreviewPrs ) {
+    myPreviewPrs->update();  
+  }
 }
 
 void HYDROGUI_StreamOp::erasePreview()
 {
-  if( myPreviewPrs )
-  {
+  if( myPreviewPrs ) {
     delete myPreviewPrs;
     myPreviewPrs = 0;
   }
@@ -220,9 +224,9 @@ void HYDROGUI_StreamOp::onAddProfiles()
 
   // TODO: to be optimized
   QStringList aCurrentProfiles;
-  for( int anIndex = 1, aLength = aProfiles.Length(); anIndex <= aLength; anIndex++ ) {
+  for( int i = 1, n = aProfiles.Length(); i <= n; i++ ) {
     Handle(HYDROData_Profile) aProfile =
-      Handle(HYDROData_Profile)::DownCast( aProfiles.Value( anIndex ) );
+      Handle(HYDROData_Profile)::DownCast( aProfiles.Value( i ) );
     if ( !aProfile.IsNull() ) {
       aCurrentProfiles << aProfile->GetName();
     }
@@ -231,11 +235,11 @@ void HYDROGUI_StreamOp::onAddProfiles()
   // Get the selected profiles ( in the Object Browser )
   QStringList anInvalidProfiles, anExistingProfiles, aHasNoIntersectionProfiles;
 
-  HYDROData_SequenceOfObjects aSeqOfProfiles;
-  HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() );
-  for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
-    Handle(HYDROData_Profile) aProfile =
-      Handle(HYDROData_Profile)::DownCast( aSeq.Value( anIndex ) );
+  HYDROData_SequenceOfObjects aVerifiedProfiles;
+  HYDROData_SequenceOfObjects aSelectedProfiles = HYDROGUI_Tool::GetSelectedObjects( module() );
+  for( int i = 1, n = aSelectedProfiles.Length(); i <= n; i++ ) {
+    Handle(HYDROData_Profile) aProfile = 
+      Handle(HYDROData_Profile)::DownCast( aSelectedProfiles.Value( i ) );
     if ( !aProfile.IsNull() ) {
       QString aProfileName = aProfile->GetName();
 
@@ -245,34 +249,45 @@ void HYDROGUI_StreamOp::onAddProfiles()
       } else if ( aCurrentProfiles.contains( aProfileName ) ) { // check whether the profile is already added
         anExistingProfiles << aProfileName;
       } else if ( !myEditedObject->HasIntersection( aProfile ) ) {  // check whether the profile has intersection
-        aHasNoIntersectionProfiles << aProfile->GetName();
+        aHasNoIntersectionProfiles << aProfileName;
       } else {
-        aSeqOfProfiles.Append( aProfile );
+        aVerifiedProfiles.Append( aProfile );
       }
     }
   }
  
   // Show message box with the ignored profiles
-  QStringList anIgnoredProfiles;
-  anIgnoredProfiles << anInvalidProfiles << anExistingProfiles << aHasNoIntersectionProfiles;
-  if ( !anIgnoredProfiles.isEmpty() ) {
-    QString aMessage = tr( "IGNORED_PROFILES" ).arg( anIgnoredProfiles.join( "\n" ) );
+  if ( aVerifiedProfiles.Length() < aSelectedProfiles.Length() ) {
+    QString aMessage = tr( "IGNORED_PROFILES" );
+    if ( !anInvalidProfiles.isEmpty() ) {
+      aMessage.append( "\n\n" );
+      aMessage.append( tr("INVALID_PROFILES").arg( anInvalidProfiles.join( "\n" ) ) );
+    }
+    if ( !anExistingProfiles.isEmpty() ) {
+      aMessage.append( "\n\n" );
+      aMessage.append( tr("EXISTING_PROFILES").arg( anExistingProfiles.join( "\n" ) ) );
+    }
+    if ( !aHasNoIntersectionProfiles.isEmpty() ) {
+      aMessage.append( "\n\n" );
+      aMessage.append( tr("NOT_INTERSECTED_PROFILES").arg( aHasNoIntersectionProfiles.join( "\n" ) ) );
+    }
+
     SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "WARNING" ), aMessage );
   }
-  
+
   // Update the stream object
-  for( int anIndex = 1, aLength = aSeqOfProfiles.Length(); anIndex <= aLength; anIndex++ ) {
+  for( int i = 1, n = aVerifiedProfiles.Length(); i <= n; i++ ) {
     Handle(HYDROData_Profile) aProfile =
-      Handle(HYDROData_Profile)::DownCast( aSeqOfProfiles.Value( anIndex ) );
+      Handle(HYDROData_Profile)::DownCast( aVerifiedProfiles.Value( i ) );
     myEditedObject->AddProfile( aProfile );
   }
   myEditedObject->Update();
 
   // Update the panel
-  updatePanel();
+  updatePanelData();
 
   // Update preview
-  onCreatePreview();
+  createPreview();
 }
 
 void HYDROGUI_StreamOp::onRemoveProfiles( const QStringList& theProfilesToRemove )
@@ -290,10 +305,10 @@ void HYDROGUI_StreamOp::onRemoveProfiles( const QStringList& theProfilesToRemove
   myEditedObject->Update();
 
   // Update the panel
-  updatePanel();
+  updatePanelData();
 
   // Update preview
-  onCreatePreview();
+  createPreview();
 }
 
 void HYDROGUI_StreamOp::onAxisChanged( const QString& theNewAxis )
@@ -317,29 +332,38 @@ void HYDROGUI_StreamOp::onAxisChanged( const QString& theNewAxis )
     }
   }
 
-  // Show message box to confirm
+  // If there are profiles which don't intersect the new axis - show confirmation message box
   bool isConfirmed = true;
   if ( !aHasNoIntersectionProfiles.isEmpty() ) {
-    // TODO show message box
+    SUIT_MessageBox::StandardButtons aButtons = 
+      SUIT_MessageBox::Yes | SUIT_MessageBox::No;
+
+    QString aMsg = aHasNoIntersectionProfiles.join( "\n" );
+    isConfirmed = SUIT_MessageBox::question( module()->getApp()->desktop(),
+                                             tr( "CONFIRMATION" ),
+                                             tr( "CONFIRM_AXIS_CHANGE" ).arg( aMsg ),
+                                             aButtons, 
+                                             SUIT_MessageBox::Yes) == SUIT_MessageBox::Yes;
   }
 
   // Check if the user has confirmed axis change
   if ( !isConfirmed ) {
-    updatePanel();
+    // To restore the old axis
+    updatePanelData();
   } else {
     // Set axis
     myEditedObject->SetHydraulicAxis( anAxis );
     myEditedObject->Update();
 
     // Update the panel
-    updatePanel();
+    updatePanelData();
 
     // Update preview
-    onCreatePreview();
+    createPreview();
   }
 }
 
-void HYDROGUI_StreamOp::updatePanel()
+void HYDROGUI_StreamOp::updatePanelData()
 {
   HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
   if ( !aPanel ) {
@@ -350,22 +374,22 @@ void HYDROGUI_StreamOp::updatePanel()
   Handle(HYDROData_PolylineXY) aHydraulicAxis = myEditedObject->GetHydraulicAxis();
   if ( !aHydraulicAxis.IsNull() ) {
     aPanel->setAxisName( aHydraulicAxis->GetName() );
+  } else {
+    aPanel->setAxisName( "" );
   }
 
   // Stream profiles
-  QStringList aSelectedProfiles;
+  QStringList aProfiles;
 
-  HYDROData_SequenceOfObjects aProfiles = myEditedObject->GetProfiles();
-  for ( int i = 1, n = aProfiles.Length(); i <= n; ++i ) {
+  HYDROData_SequenceOfObjects aStreamProfiles = myEditedObject->GetProfiles();
+  for ( int i = 1, n = aStreamProfiles.Length(); i <= n; ++i ) {
     Handle(HYDROData_Profile) aProfile = 
-      Handle(HYDROData_Profile)::DownCast( aProfiles.Value( i ) );
-    if ( aProfile.IsNull() ) {
-      continue;
+      Handle(HYDROData_Profile)::DownCast( aStreamProfiles.Value( i ) );
+    if ( !aProfile.IsNull() ) {
+      QString aProfileName = aProfile->GetName();
+      aProfiles << aProfileName;      
     }
-
-    QString aProfileName = aProfile->GetName();
-    aSelectedProfiles << aProfileName;
   }
 
-  aPanel->setSelectedProfiles( aSelectedProfiles );
+  aPanel->setProfiles( aProfiles );
 }
index 0d35f92e509de4715a9379b647e30a50842fb2be..9e8730c8127fb3deb32a73605c6ec04d2c77f3f7 100755 (executable)
@@ -49,15 +49,14 @@ protected:
   virtual bool                 processApply( int& theUpdateFlags, QString& theErrorMsg );
 
 private slots:
-  void                         onCreatePreview();
-
   void                         onAddProfiles();
   void                         onRemoveProfiles( const QStringList& );
   void                         onAxisChanged( const QString& );
 
 private:
+  void                         createPreview();
   void                         erasePreview();
-  void                         updatePanel();
+  void                         updatePanelData();
 
 private:
   OCCViewer_ViewManager*       myViewManager;
index 9911e68ade6f5294af677b63b6fb07b827e0ddc7..ab30bf095c1a96ccde0294f4bd78de9a73bc4052 100644 (file)
@@ -1593,7 +1593,21 @@ file cannot be correctly imported for an Obstacle definition.</translation>
     </message>
     <message>
       <source>IGNORED_PROFILES</source>
-      <translation>The following profile(s) will be ignored:
+      <translation>The following profile(s) will be ignored:</translation>
+    </message>
+    <message>
+      <source>INVALID_PROFILES</source>
+      <translation>Invalid profiles: 
+%1</translation>
+    </message>
+    <message>
+      <source>EXISTING_PROFILES</source>
+      <translation>Existing profiles: 
+%1</translation>
+    </message>
+    <message>
+      <source>NOT_INTERSECTED_PROFILES</source>
+      <translation>Not intersected with the hydraulic axis: 
 %1</translation>
     </message>
     <message>
@@ -1604,6 +1618,17 @@ file cannot be correctly imported for an Obstacle definition.</translation>
       <source>PROFILES_NOT_DEFINED</source>
       <translation>At least 2 profiles should be defined.</translation>
     </message>
+    <message>
+      <source>CONFIRMATION</source>
+      <translation>Confirmation</translation>
+    </message>
+    <message>
+      <source>CONFIRM_AXIS_CHANGE</source>
+      <translation>The following profiles don't intersect the axis:
+%1
+
+Do you want to remove these profiles and continue?</translation>
+    </message>
   </context>
 
   <context>