]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Final version of "Profile interpolation".
authorstv <stv@opencascade.com>
Mon, 30 Mar 2015 06:40:13 +0000 (09:40 +0300)
committerstv <stv@opencascade.com>
Mon, 30 Mar 2015 06:40:13 +0000 (09:40 +0300)
src/HYDROData/HYDROData_Document.h
src/HYDROData/HYDROData_IProfilesInterpolator.h
src/HYDROData/HYDROData_InterpolatorsFactory.h
src/HYDROGUI/HYDROGUI_ProfileInterpolateDlg.cxx
src/HYDROGUI/HYDROGUI_ProfileInterpolateOp.cxx
src/HYDROGUI/HYDROGUI_ProfileInterpolateOp.h
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index bfe81778a026093ea6dbdb4f94d9fee6efa10257..ae33d54e79dc378669854559529702b2772e7c31 100644 (file)
@@ -213,7 +213,7 @@ public:
 public:
   
   //! Returns interpolator factory instance
-  HYDROData_InterpolatorsFactory* GetInterpolatorsFactory();
+  HYDRODATA_EXPORT HYDROData_InterpolatorsFactory* GetInterpolatorsFactory();
 
 protected:
 
index da91b2da7c56f094c6cc0e9590fbbe7a0dcde235..220997b1b982ce544e25106c3cdb37a9e4643c8b 100644 (file)
@@ -113,7 +113,7 @@ public:
    * \param theProfileIndex the profile index [0, <number of profiles to compute>]
    * \return the profile with the given index or empty vector if the index is out of range
    */
-  std::vector<double> GetResultProfile( const int theProfileIndex ) const;
+  HYDRODATA_EXPORT std::vector<double> GetResultProfile( const int theProfileIndex ) const;
 
 protected:
   /**
index 865faea658aa50217caa085171063214d2165fa1..84cdd995b0fcabdd3b48c0218ffa0f69f783e116 100644 (file)
@@ -50,7 +50,7 @@ public:
    * Registers the interpolator of a certain type with the given name.
    * \param theName the interpolator name used as identifier
    */
-  template <class T> HYDRODATA_EXPORT void Register( const std::string& theName )
+  template <class T> /*HYDRODATA_EXPORT */void Register( const std::string& theName )
   {
     myInterpolators[theName] = new T();
   }
@@ -66,7 +66,7 @@ public:
    * Get list of registered interpolator names.
    * \return the list of unique names
    */
-  std::vector<std::string> GetInterpolatorNames() const;
+  HYDRODATA_EXPORT std::vector<std::string> GetInterpolatorNames() const;
   
 private:
   //! Map that stores all interpolators, identified by interpolator name (string)
index 622a18af6772a7b667e6dd39ebe55c0ad2e89008..a66a718347ef8f0bfffb633bdb4ee48edb338805 100644 (file)
@@ -91,7 +91,7 @@ HYDROGUI_ProfileInterpolateDlg::HYDROGUI_ProfileInterpolateDlg( HYDROGUI_Module*
     connect( myProfileFinish, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( profileFinishChanged( const QString& ) ) );
 
     connect( myProfileNumber, SIGNAL( valueChanged( int ) ), this, SIGNAL( profileNumberChanged( int ) ) );
-    connect( myParams, SIGNAL( myParams->textChanged( const QString& ) ), this, SIGNAL( interpolatorParametersChanged( const QString& ) ) );
+    connect( myParams, SIGNAL( textChanged( const QString& ) ), this, SIGNAL( interpolatorParametersChanged( const QString& ) ) );
 
     new HYDROGUI_OCCSelector( module(), viewer(), selectionMgr() );
 
@@ -216,8 +216,8 @@ void HYDROGUI_ProfileInterpolateDlg::reset()
     myRiver->reset();
     myProfileStart->reset();
     myProfileFinish->reset();
-
-    myDescr->setText( QString::null );
+    myParams->clear();
+    myDescr->clear();
 }
 
 void HYDROGUI_ProfileInterpolateDlg::onRiverChanged( const QString& theName )
index 6578a86de6d1468a74934aba827c7b1dedf75508..dab1a59e4f123294089f5b96f0098d605960e4bc 100644 (file)
 
 #include <HYDROData_Stream.h>
 #include <HYDROData_Profile.h>
+#include <HYDROData_Document.h>
+#include <HYDROData_ProfileUZ.h>
+#include <HYDROData_IPolyline.h>
+#include <HYDROData_PolylineXY.h>
+#include <HYDROData_InterpolatorsFactory.h>
+#include <HYDROData_IProfilesInterpolator.h>
 
 #include <LightApp_Application.h>
 #include <LightApp_SelectionMgr.h>
 #include <AIS_ListOfInteractive.hxx>
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
 
+#include <BRep_Builder.hxx>
+#include <TopoDS_Compound.hxx>
+
+#include <QMessageBox>
+
 HYDROGUI_ProfileInterpolateOp::HYDROGUI_ProfileInterpolateOp( HYDROGUI_Module* theModule )
     : HYDROGUI_Operation( theModule )
 {
@@ -63,65 +74,35 @@ void HYDROGUI_ProfileInterpolateOp::startOperation()
         aPanel->reset();
         aPanel->setInterpolators( interpolators() );
     }
+}
 
-/*
-    if( myIsEdit )
-        myEditedObject = Handle(HYDROData_Profile)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
-
-    QString aProfileName;
-    if( !myEditedObject.IsNull() )
+void HYDROGUI_ProfileInterpolateOp::abortOperation()
+{
+    if ( !myPreview.IsNull() )
     {
-        Handle(HYDROData_ProfileUZ) aProfileUZ = myEditedObject->GetProfileUZ( false );
-        if ( !aProfileUZ.IsNull() )
+        HYDROGUI_ProfileInterpolateDlg* aDlg = new HYDROGUI_ProfileInterpolateDlg( module(), getName() );
+        if ( aDlg && !aDlg->getAISContext().IsNull() )
         {
-            CurveCreator::Coordinates aCurveCoords;
-            CurveCreator::SectionsMap aSectionsMap;
-
-            HYDROData_ProfileUZ::PointsList aSectPointsList = aProfileUZ->GetPoints();
-            CurveCreator::PosPointsList aPoints;
-            for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k )
-            {
-                const HYDROData_ProfileUZ::Point& aSectPoint = aSectPointsList.Value( k );
-                aCurveCoords.clear();
-                aCurveCoords.push_back( aSectPoint.X() );
-                aCurveCoords.push_back( aSectPoint.Y() );
-
-                CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( k, aCurveCoords );
-                aPoints.push_back( aPosPoint );
-            }
-
-            aSectionsMap[0] = aPoints;
-            myProfile->addPointsInternal( aSectionsMap );
-
-            HYDROData_ProfileUZ::SectionType aSectType = aProfileUZ->GetSectionType( 0 );
-
-            CurveCreator::SectionType aCurveType = CurveCreator::Polyline;
-            if( aSectType == HYDROData_ProfileUZ::SECTION_SPLINE )
-                aCurveType = CurveCreator::Spline;
-
-            myProfile->setSectionType( 0, aCurveType );
+            aDlg->getAISContext()->Remove( myPreview, false );
+            myPreview.Nullify();
         }
-
-        aProfileName = myEditedObject->GetName();
-    }
-    else
-    {
-        aProfileName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_PROFILE_NAME" ) );
     }
 
-    aPanel->setProfileName( aProfileName );
-    aPanel->setProfile( myProfile );
-*/
-//    displayPreview();
-}
-
-void HYDROGUI_ProfileInterpolateOp::abortOperation()
-{
     HYDROGUI_Operation::abortOperation();
 }
 
 void HYDROGUI_ProfileInterpolateOp::commitOperation()
 {
+    if ( !myPreview.IsNull() )
+    {
+        HYDROGUI_ProfileInterpolateDlg* aDlg = new HYDROGUI_ProfileInterpolateDlg( module(), getName() );
+        if ( aDlg && !aDlg->getAISContext().IsNull() )
+        {
+            aDlg->getAISContext()->Remove( myPreview, false );
+            myPreview.Nullify();
+        }
+    }
+
     HYDROGUI_Operation::commitOperation();
 }
 
@@ -142,123 +123,197 @@ HYDROGUI_InputPanel* HYDROGUI_ProfileInterpolateOp::createInputPanel() const
 bool HYDROGUI_ProfileInterpolateOp::processApply( int& theUpdateFlags, QString& theErrorMsg,
                                                   QStringList& theBrowseObjectsEntries )
 {
-    HYDROGUI_ProfileInterpolateDlg* aPanel = ::qobject_cast<HYDROGUI_ProfileInterpolateDlg*>( inputPanel() );
-    if ( !aPanel )
-        return false;
-/*
-    QString aProfileName = aPanel->getProfileName().simplified();
-    if ( aProfileName.isEmpty() )
-    {
-        theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
+    HYDROGUI_ProfileInterpolateDlg* aDlg = ::qobject_cast<HYDROGUI_ProfileInterpolateDlg*>( inputPanel() );
+    if ( !aDlg )
         return false;
-    }
 
-    if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != aProfileName ) )
+    QString errMessage;
+    HYDROData_IProfilesInterpolator* anIterp = interpolator( aDlg->interpolator() );
+    if ( anIterp )
     {
-        // check that there are no other objects with the same name in the document
-        Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), aProfileName );
-        if( !anObject.IsNull() )
+        updateInterpolator( anIterp );
+        Handle(HYDROData_Stream) aRiver = Handle(HYDROData_Stream)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), aDlg->river(), KIND_STREAM ) );
+        if ( !aRiver.IsNull() )
         {
-            theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( aProfileName );
-            return false;
+            startDocOperation();
+            //aRiver->Interpolate( anIterp );
+            if ( anIterp->GetErrorCode() == OK )
+                commitDocOperation();
+            else
+            {
+                errMessage = tr( "CALCULATE_ERROR" ), QString( anIterp->GetErrorMessage().c_str() );
+                abortDocOperation();
+            }
         }
-    }
+        else
+            errMessage = tr( "CANT_GET_RIVER_OBJECT" ).arg( aDlg->river() );
 
-    Handle(HYDROData_Profile) aProfileObj;
-    if( myIsEdit ){
-        aProfileObj = myEditedObject;
-    }
-    else{
-        aProfileObj = Handle(HYDROData_Profile)::DownCast( doc()->CreateObject( KIND_PROFILE ) );
+        if ( !errMessage.isEmpty() )
+            QMessageBox::critical( aDlg->topLevelWidget(), tr( "INTERPOLATION_ERROR" ), errMessage, QMessageBox::Ok );
+        else
+            commit();
     }
 
-    if( aProfileObj.IsNull() )
-        return false;
+    return errMessage.isEmpty();
+}
 
-    Handle(HYDROData_ProfileUZ) aProfileUZ = aProfileObj->GetProfileUZ();
-    if ( aProfileUZ.IsNull() )
-        return false;
+void HYDROGUI_ProfileInterpolateOp::updatePreview()
+{
+    HYDROGUI_ProfileInterpolateDlg* aDlg = ::qobject_cast<HYDROGUI_ProfileInterpolateDlg*>( inputPanel() );
+    if ( !aDlg )
+        return;
 
-    aProfileObj->SetName(aProfileName);
+    Handle(AIS_InteractiveContext) aCtx = aDlg->getAISContext();
+    if ( aCtx.IsNull() )
+        return;
+
+    if ( !myPreview.IsNull() )
+        aCtx->Remove( myPreview, false );
 
-    HYDROData_ProfileUZ::PointsList aProfileParamPoints;
+    myPreview.Nullify();
 
-    CurveCreator::Coordinates aCurveCoords = myProfile->getPoints( 0 );
-    if ( aCurveCoords.size() <= 2 )
+    HYDROData_IProfilesInterpolator* anIterp = interpolator( aDlg->interpolator() );
+    if ( anIterp )
     {
-        theErrorMsg = tr( "NUMBER_OF_PROFILE_POINTS_INCORRECT" );
-        return false;
+        updateInterpolator( anIterp );
+        if ( anIterp->Calculate() == OK )
+        {
+            TopoDS_Shape aShape = previewShape( anIterp, aDlg->profileNumber() );
+            if ( !aShape.IsNull() )
+            {
+                myPreview = new AIS_Shape( aShape );
+                myPreview->SetColor( Quantity_NOC_RED );
+                aCtx->Display( myPreview, 0, -1, false );
+            }
+        }
     }
 
-    for ( int k = 0 ; k + 1 < aCurveCoords.size() ; k++ )
-    {
-        HYDROData_ProfileUZ::Point aProfileParamPoint;
+    aCtx->UpdateCurrentViewer();
+}
 
-        aProfileParamPoint.SetX( aCurveCoords.at( k ) );
-        k++;
-        aProfileParamPoint.SetY( aCurveCoords.at( k ) );
+void HYDROGUI_ProfileInterpolateOp::updateInterpolator( HYDROData_IProfilesInterpolator* theInt )
+{
+    HYDROGUI_ProfileInterpolateDlg* aDlg = ::qobject_cast<HYDROGUI_ProfileInterpolateDlg*>( inputPanel() );
+    if ( !aDlg || !theInt )
+        return;
+
+    theInt->Reset();
+    theInt->SetResultProfilesNumber( aDlg->profileNumber() );
+    theInt->SetProfiles( profile( aDlg->profileStart() ), profile( aDlg->profileFinish() ) );
+    ParamsList aParams = parameters( aDlg->interpolatorParameters() );
+    for ( ParamsList::Iterator it = aParams.begin(); it != aParams.end(); ++it )
+        theInt->SetParameter( (*it).first.toStdString(), (*it).second.toStdString() );
+}
 
-        aProfileParamPoints.Append( aProfileParamPoint );
+std::vector<double> HYDROGUI_ProfileInterpolateOp::profile( const QString& theName ) const
+{
+    std::vector<double> aPoints;
+    Handle(HYDROData_Profile) aProf = Handle(HYDROData_Profile)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), theName, KIND_PROFILE ) );
+    if ( !aProf.IsNull() )
+    {
+        HYDROData_Profile::ProfilePoints aPntList = aProf->GetProfilePoints();
+        for ( int i = aPntList.Lower(); i <= aPntList.Upper(); i++ )
+        {
+            HYDROData_Profile::ProfilePoint aPnt = aPntList.Value( i );
+            aPoints.push_back( aPnt.X() );
+            aPoints.push_back( aPnt.Y() );
+            aPoints.push_back( aPnt.Z() );
+        }
     }
-    aProfileObj->SetParametricPoints( aProfileParamPoints );
+    return aPoints;
+}
 
-    HYDROData_ProfileUZ::SectionType aSectType = HYDROData_ProfileUZ::SECTION_POLYLINE;
-    if ( myProfile->getSectionType( 0 ) == CurveCreator::Spline )
-        aSectType = HYDROData_ProfileUZ::SECTION_SPLINE;
+HYDROGUI_ProfileInterpolateOp::ParamsList HYDROGUI_ProfileInterpolateOp::parameters( const QString& theStr ) const
+{
+    // Regular expression for parsing parameters string of kind: <param_name> <param_value> <param_name> <param_value> ..."
+    // QRegExp rx( "([A-Za-z_\\d]+)\\s+([A-Za-z_\\d]+)\\s*" );
 
-    aProfileUZ->SetSectionType( 0, aSectType );
+    // Regular expression for parsing parameters string of kind: <param_name> = <param_value> <param_name> = <param_value> ..."
+    QRegExp rx( "([A-Za-z_\\d]+)\\s*=\\s*([A-Za-z_\\d]+)\\s*" );
 
-    if ( !myIsEdit )
+    ParamsList aParamList;
+    for ( int i = 0; i >= 0; )
     {
-        aProfileObj->SetBorderColor( HYDROData_Profile::DefaultBorderColor() );
+        i = rx.indexIn( theStr, i );
+        if ( i >= 0  )
+        {
+            aParamList.append( QPair<QString, QString>( rx.cap( 1 ), rx.cap( 2 ) ) );
+            i += rx.matchedLength();
+        }
     }
 
-    // At first we update the child u,z profile object
-    aProfileUZ->SetToUpdate( true );
-    aProfileUZ->Update();
+    return aParamList;
+}
+
+QString HYDROGUI_ProfileInterpolateOp::parameters( const ParamsList& theParamList ) const
+{
+    QStringList paramList;
+    for ( ParamsList::const_iterator it = theParamList.begin(); it != theParamList.end(); ++it )
+        paramList.append( QString( "%1 = %2" ).arg( (*it).first ).arg( (*it).second ) );
+    return paramList.join( " " );
+}
 
-    // And now we update our edited object
-    aProfileObj->Update();
-    module()->setIsToUpdate( aProfileObj );
+QStringList HYDROGUI_ProfileInterpolateOp::interpolators() const
+{
+    HYDROData_InterpolatorsFactory* anIFactory = 0;
+    Handle(HYDROData_Document) aDoc = doc();
+    if ( !aDoc.IsNull() )
+        anIFactory = aDoc->GetInterpolatorsFactory();
 
-    theUpdateFlags = UF_Model;
-    if ( myIsEdit )
-        theUpdateFlags |= UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
-    else
+    QStringList aNames;
+    if ( anIFactory )
     {
-        QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aProfileObj );
-        theBrowseObjectsEntries.append( anEntry );
+        std::vector<std::string> iNames = anIFactory->GetInterpolatorNames();
+        for ( std::vector<std::string>::iterator it = iNames.begin(); it != iNames.end(); ++it )
+            aNames.append( (*it).c_str() );
     }
 
-    */
-    return true;
+    return aNames;
 }
 
-void HYDROGUI_ProfileInterpolateOp::updatePreview()
+HYDROData_IProfilesInterpolator* HYDROGUI_ProfileInterpolateOp::interpolator( const QString& theName ) const
 {
-    HYDROGUI_ProfileInterpolateDlg* aDlg = ::qobject_cast<HYDROGUI_ProfileInterpolateDlg*>( inputPanel() );
-    if ( !aDlg )
-        return;
-
-    Handle(AIS_InteractiveContext) aCtx = aDlg->getAISContext();
-    if ( aCtx.IsNull() )
-        return;
-
-    aCtx->UpdateCurrentViewer();
+    HYDROData_InterpolatorsFactory* anIFactory = 0;
+    Handle(HYDROData_Document) aDoc = doc();
+    if ( !aDoc.IsNull() )
+        anIFactory = aDoc->GetInterpolatorsFactory();
+
+    HYDROData_IProfilesInterpolator* aRes = 0;
+    if ( anIFactory )
+        aRes = anIFactory->GetInterpolator( theName.toStdString() );
+    return aRes;
 }
 
-QStringList HYDROGUI_ProfileInterpolateOp::interpolators() const
+TopoDS_Shape HYDROGUI_ProfileInterpolateOp::previewShape( HYDROData_IProfilesInterpolator* theInterp, int theNumber ) const
 {
-    return QStringList() << "Linear interpolator" << "Spline interpolator";
+    TopoDS_Compound aPreviewShape;
+    if ( theInterp )
+    {
+        BRep_Builder aBuilder;
+        aBuilder.MakeCompound( aPreviewShape );
+        for ( int i = 0; i < theNumber; i++ )
+        {
+            NCollection_Sequence<gp_XYZ> pointSeq;
+            std::vector<double> aPoints = theInterp->GetResultProfile( i );
+            for ( int i = 0; i < aPoints.size(); i += 3 )
+                pointSeq.Append( gp_XYZ( aPoints[i], aPoints[i+1], aPoints[i+2] ) );
+            TopoDS_Shape aWire = HYDROData_PolylineXY::BuildWire( HYDROData_IPolyline::SECTION_SPLINE, false, pointSeq );
+            if ( !aWire.IsNull() )
+                aBuilder.Add( aWire, aPreviewShape );
+        }
+    }
+
+    return aPreviewShape;
 }
 
 void HYDROGUI_ProfileInterpolateOp::onInterpolatorChanged( const QString& theInterpName )
 {
     HYDROGUI_ProfileInterpolateDlg* aPanel = dynamic_cast<HYDROGUI_ProfileInterpolateDlg*>( inputPanel() );
-    if ( !aPanel )
+    HYDROData_IProfilesInterpolator* anInterp = interpolator( theInterpName );
+    if ( !aPanel || !anInterp )
         return;
 
-    aPanel->setInterpolatorDescription( QString( "Profile will be calculated used %1" ).arg( theInterpName ) );
+    aPanel->setInterpolatorDescription( QString( anInterp->GetDescription().c_str() ) );
 
     updatePreview();
 }
index 241c0683b4c48eef6888cc43f67ada57f839ea88..dabd86ec18d52008c3ff0edb377038e8835734c0 100644 (file)
 
 #include <AIS_Shape.hxx>
 
+#include <QPair>
+#include <QList>
+
+class HYDROData_IProfilesInterpolator;
+
 class HYDROGUI_ProfileInterpolateOp : public HYDROGUI_Operation
 {
   Q_OBJECT
@@ -37,6 +42,9 @@ public:
   HYDROGUI_ProfileInterpolateOp( HYDROGUI_Module* theModule );
   virtual ~HYDROGUI_ProfileInterpolateOp();
 
+protected:
+  typedef QList< QPair<QString, QString> > ParamsList;
+
 protected:
   virtual void               startOperation();
   virtual void               abortOperation();
@@ -48,6 +56,13 @@ protected:
                                            QStringList& theBrowseObjectsEntries );
 
   QStringList                interpolators() const;
+  HYDROData_IProfilesInterpolator* interpolator( const QString& ) const;
+  void                       updateInterpolator( HYDROData_IProfilesInterpolator* );
+  std::vector<double>        profile( const QString& ) const;
+  ParamsList                 parameters( const QString& ) const;
+  QString                    parameters( const ParamsList& ) const;
+
+  TopoDS_Shape               previewShape( HYDROData_IProfilesInterpolator*, int ) const;
 
 private slots:
   void                       updatePreview();
index ed61ffca7c72b7c4f0ef8a18d2b4b974af494250..6721f63590ef0be2577b546337d7136dbefc111e 100644 (file)
@@ -2314,6 +2314,18 @@ Polyline should consist from one not closed curve.</translation>
       <source>PROFILE_INTERPOLATION</source>
       <translation>Profile interpolation</translation>
     </message>
+    <message>
+      <source>INTERPOLATION_ERROR</source>
+      <translation>Interpolation error</translation>
+    </message>
+    <message>
+      <source>CALCULATE_ERROR</source>
+      <translation>Can't perform calculation: %1</translation>
+    </message>
+    <message>
+      <source>CANT_GET_RIVER_OBJECT</source>
+      <translation>Can't obtain river oject \"%1\"</translation>
+    </message>
   </context>
 
 </TS>