diff --git a/src/core/hydraulicNetwork/reoshydraulicnetwork.cpp b/src/core/hydraulicNetwork/reoshydraulicnetwork.cpp index 9bb51e7de..372cba5b3 100644 --- a/src/core/hydraulicNetwork/reoshydraulicnetwork.cpp +++ b/src/core/hydraulicNetwork/reoshydraulicnetwork.cpp @@ -25,7 +25,7 @@ ReosHydraulicNetworkElement::ReosHydraulicNetworkElement( ReosHydraulicNetwork *parent ): ReosDataObject( parent ) - , mNetWork( parent ) + , mNetwork( parent ) , mNameParameter( new ReosParameterString( tr( "Name" ), false, this ) ) { mConstantTimeStepInTable = new ReosParameterDuration( tr( "Constant time step" ) ); @@ -36,7 +36,7 @@ ReosHydraulicNetworkElement::ReosHydraulicNetworkElement( ReosHydraulicNetwork * ReosHydraulicNetworkElement::ReosHydraulicNetworkElement( const ReosEncodedElement &encodedElement, ReosHydraulicNetwork *parent ) : ReosDataObject( parent ) - , mNetWork( parent ) + , mNetwork( parent ) , mNameParameter( ReosParameterString::decode( encodedElement.getEncodedData( QStringLiteral( "name-parameter" ) ), false, tr( "Name" ), this ) ) { ReosDataObject::decode( encodedElement ); @@ -73,15 +73,15 @@ ReosHydraulicNetworkElement::~ReosHydraulicNetworkElement() void ReosHydraulicNetworkElement::destroy() { - if ( !mNetWork.isNull() ) - mNetWork->mElements.remove( id() ); + if ( !mNetwork.isNull() ) + mNetwork->mElements.remove( id() ); deleteLater(); } void ReosHydraulicNetworkElement::positionChanged() { - if ( mNetWork ) - mNetWork->elemPositionChangedPrivate( this ); + if ( mNetwork ) + mNetwork->elemPositionChangedPrivate( this ); } ReosParameterString *ReosHydraulicNetworkElement::elementName() const @@ -120,8 +120,8 @@ void ReosHydraulicNetworkElement::notify( const ReosModule::Message &messageObje { ReosModule::Message sendedMessage = messageObject; sendedMessage.prefixMessage( tr( "Routing %1: " ).arg( elementName()->value() ) ); - if ( mNetWork ) - mNetWork->message( sendedMessage ); + if ( mNetwork ) + mNetwork->message( sendedMessage ); } } @@ -139,6 +139,11 @@ ReosDuration ReosHydraulicNetworkElement::currentElementTimeStep() const return ReosDuration( qint64( 0 ) ); } +ReosHydraulicNetwork *ReosHydraulicNetworkElement::network() const +{ + return mNetwork; +} + ReosHydraulicNetwork::ReosHydraulicNetwork( ReosModule *parent, ReosGisEngine *gisEngine, ReosWatershedModule *watershedModule ) : ReosModule( parent ) , mGisEngine( gisEngine ) diff --git a/src/core/hydraulicNetwork/reoshydraulicnetwork.h b/src/core/hydraulicNetwork/reoshydraulicnetwork.h index e5e422dde..3e91dbdc4 100644 --- a/src/core/hydraulicNetwork/reoshydraulicnetwork.h +++ b/src/core/hydraulicNetwork/reoshydraulicnetwork.h @@ -86,11 +86,13 @@ class REOSCORE_EXPORT ReosHydraulicNetworkElement : public ReosDataObject virtual ReosDuration currentElementTimeStep() const; + ReosHydraulicNetwork *network() const; + public slots: virtual void updateCalculationContext( const ReosCalculationContext &context ) = 0; protected: - QPointer mNetWork = nullptr; + QPointer mNetwork = nullptr; void calculationUpdated() { diff --git a/src/core/hydraulicNetwork/reoshydraulicscheme.cpp b/src/core/hydraulicNetwork/reoshydraulicscheme.cpp index 8719b0c50..2ee1dce50 100644 --- a/src/core/hydraulicNetwork/reoshydraulicscheme.cpp +++ b/src/core/hydraulicNetwork/reoshydraulicscheme.cpp @@ -26,6 +26,7 @@ ReosHydraulicScheme::ReosHydraulicScheme( ReosHydraulicSchemeCollection *collect , mStartTime( new ReosParameterDateTime( tr( "Start time" ), this ) ) , mEndTime( new ReosParameterDateTime( tr( "End time" ), this ) ) { + mEndTime->setValue( mEndTime->value().addSecs( 3600 ) ); init(); } diff --git a/src/core/hydraulicNetwork/reoshydraulicstructure2d.cpp b/src/core/hydraulicNetwork/reoshydraulicstructure2d.cpp index 975daaf91..1627e6e96 100644 --- a/src/core/hydraulicNetwork/reoshydraulicstructure2d.cpp +++ b/src/core/hydraulicNetwork/reoshydraulicstructure2d.cpp @@ -36,7 +36,6 @@ ReosHydraulicStructure2D::ReosHydraulicStructure2D( const QPolygonF &domain, con , mTopographyCollection( ReosTopographyCollection::createTopographyCollection( context.network()->gisEngine(), this ) ) , mMesh( ReosMesh::createMeshFrame( crs ) ) , mRoughnessStructure( new ReosRoughnessStructure( crs ) ) - , mHydraulicNetworkContext( context ) { init(); } @@ -50,7 +49,6 @@ ReosHydraulicStructure2D::ReosHydraulicStructure2D( , mTopographyCollection( ReosTopographyCollection::createTopographyCollection( encodedElement.getEncodedData( QStringLiteral( "topography-collection" ) ), context.network()->gisEngine(), this ) ) , mRoughnessStructure( new ReosRoughnessStructure( encodedElement.getEncodedData( QStringLiteral( "roughness-structure" ) ) ) ) , m3dMapSettings( encodedElement.getEncodedData( "3d-map-setings" ) ) - , mHydraulicNetworkContext( context ) { if ( encodedElement.hasEncodedData( QStringLiteral( "mesh-resolution-controller" ) ) ) mMeshResolutionController = new ReosMeshResolutionController( encodedElement.getEncodedData( QStringLiteral( "mesh-resolution-controller" ) ), this ); @@ -75,7 +73,7 @@ ReosHydraulicStructure2D::ReosHydraulicStructure2D( if ( bc ) bc->attachStructure( this ); else - mNetWork->addElement( new ReosHydraulicStructureBoundaryCondition( this, bcId, mHydraulicNetworkContext ) ); + mNetwork->addElement( new ReosHydraulicStructureBoundaryCondition( this, bcId, network()->context() ) ); } const QList encodedSimulations = encodedElement.getListEncodedData( QStringLiteral( "simulations" ) ); @@ -106,27 +104,25 @@ ReosHydraulicStructure2D::ReosHydraulicStructure2D( QString currentActivatedVectorMeshDataset; encodedElement.getData( QStringLiteral( "current-mesh-vector-dataset-id" ), currentActivatedVectorMeshDataset ); mMesh->activateVectorDataset( currentActivatedVectorMeshDataset ); -} -ReosHydraulicNetworkContext ReosHydraulicStructure2D::hydraulicNetworkContext() const -{ - return mHydraulicNetworkContext; + if ( !encodedElement.getData( QStringLiteral( "mesh-need-to-be-generated" ), mMeshNeedToBeGenerated ) ) + mMeshNeedToBeGenerated = true; } void ReosHydraulicStructure2D::exportResultAsMesh( const QString &fileName ) const { mMesh->exportAsMesh( fileName ); - mMesh->exportSimulationResults( mSimulationResults.value( mHydraulicNetworkContext.network()->currentScheme()->id() ), fileName ); + mMesh->exportSimulationResults( mSimulationResults.value( network()->currentScheme()->id() ), fileName ); } void ReosHydraulicStructure2D::exportResultAsMeshInGisProject( const QString &fileName, bool keepLayers ) { const QFileInfo fileInfo( fileName ); - const QString meshName = elementName()->value() + '-' + mHydraulicNetworkContext.network()->currentScheme()->schemeName()->value(); + const QString meshName = elementName()->value() + '-' + network()->currentScheme()->schemeName()->value(); QString meshFileName = fileInfo.dir().filePath( meshName ); meshFileName = mMesh->exportAsMesh( meshFileName ); - mMesh->exportSimulationResults( mSimulationResults.value( mHydraulicNetworkContext.network()->currentScheme()->id() ), meshFileName ); + mMesh->exportSimulationResults( mSimulationResults.value( network()->currentScheme()->id() ), meshFileName ); QMap scalarSymbologies; QMap vectorSymbologies; @@ -147,11 +143,11 @@ void ReosHydraulicStructure2D::exportResultAsMeshInGisProject( const QString &fi vectorSymbologies.insert( groupName, symbology ); } - ReosDuration timeStep = simulation( mHydraulicNetworkContext.network()->currentScheme() )->representative2DTimeStep(); + ReosDuration timeStep = simulation( mNetwork->currentScheme() )->representative2DTimeStep(); timeStep.setAdaptedUnit(); - mHydraulicNetworkContext.network()->gisEngine()->createProjectFile( fileName, keepLayers ); - mHydraulicNetworkContext.network()->gisEngine()->addMeshLayerToExistingProject( + mNetwork->gisEngine()->createProjectFile( fileName, keepLayers ); + mNetwork->gisEngine()->addMeshLayerToExistingProject( fileName, meshName, meshFileName, @@ -237,7 +233,9 @@ void ReosHydraulicStructure2D::encodeData( ReosEncodedElement &element, const Re element.addData( QStringLiteral( "wire-frame-color" ), wireframeSettings.color ); element.addData( QStringLiteral( "wire-frame-width" ), wireframeSettings.width ); - element.addEncodedData( "3d-map-setings", m3dMapSettings.encode() ); + element.addEncodedData( QStringLiteral( "3d-map-setings" ), m3dMapSettings.encode() ); + + element.addData( QStringLiteral( "mesh-need-to-be-generated" ), mMeshNeedToBeGenerated ); } ReosRoughnessStructure *ReosHydraulicStructure2D::roughnessStructure() const @@ -247,7 +245,7 @@ ReosRoughnessStructure *ReosHydraulicStructure2D::roughnessStructure() const QDir ReosHydraulicStructure2D::structureDirectory() const { - return QDir( mHydraulicNetworkContext.projectPath() + '/' + mHydraulicNetworkContext.projectName() + QStringLiteral( "-hydr-struct" ) + '/' + directory() ); + return QDir( mNetwork->context().projectPath() + '/' + mNetwork->context().projectName() + QStringLiteral( "-hydr-struct" ) + '/' + directory() ); } QList ReosHydraulicStructure2D::boundaryConditions() const @@ -375,13 +373,13 @@ void ReosHydraulicStructure2D::setTerrain3DSettings( const Reos3DTerrainSettings void ReosHydraulicStructure2D::onBoundaryConditionAdded( const QString &bid ) { - mNetWork->addElement( new ReosHydraulicStructureBoundaryCondition( this, bid, mNetWork->context() ) ); + mNetwork->addElement( new ReosHydraulicStructureBoundaryCondition( this, bid, mNetwork->context() ) ); emit boundaryChanged(); } void ReosHydraulicStructure2D::onBoundaryConditionRemoved( const QString &bid ) { - mNetWork->removeElement( boundaryConditionNetWorkElement( bid ) ); + mNetwork->removeElement( boundaryConditionNetWorkElement( bid ) ); emit boundaryChanged(); } @@ -442,33 +440,57 @@ QString ReosHydraulicStructure2D::meshDatasetName( const QString &id ) const return mMesh->datasetName( id ); } -ReosProcess *ReosHydraulicStructure2D::getPreparationProcessSimulation( const ReosCalculationContext &context ) +ReosSimulationPreparationProcess *ReosHydraulicStructure2D::getPreparationProcessSimulation( const ReosCalculationContext &context, QString &error ) { + if ( mMeshNeedToBeGenerated ) + { + error = tr( "The mesh need to be regenerated" ); + return nullptr; + } + if ( !currentSimulation() ) + { + error = tr( "Current simulation not defined" ); return nullptr; + } + + if ( mNetwork->projectFileName().isEmpty() ) + { + error = tr( "Project must be saved at least one time." ); + return nullptr; + } return new ReosSimulationPreparationProcess( this, currentSimulation(), context ); } -ReosProcess *ReosHydraulicStructure2D::getPreparationProcessSimulation( const ReosCalculationContext &context, const QDir &directory ) +ReosSimulationPreparationProcess *ReosHydraulicStructure2D::getPreparationProcessSimulation( const ReosCalculationContext &context, QString &error, const QDir &directory ) { - if ( !currentSimulation() ) - return nullptr; - - std::unique_ptr ret( new ReosSimulationPreparationProcess( this, currentSimulation(), context ) ); + std::unique_ptr ret( getPreparationProcessSimulation( context, error ) ); ret->setDestination( directory ); return ret.release(); } -ReosSimulationProcess *ReosHydraulicStructure2D::startSimulation( const ReosCalculationContext &context ) +ReosSimulationProcess *ReosHydraulicStructure2D::startSimulation( const ReosCalculationContext &context, QString &error ) { + if ( mMeshNeedToBeGenerated ) + { + error = tr( "The mesh need to be regenerated" ); + return nullptr; + } + if ( !currentSimulation() ) + { + error = tr( "Current simulation not defined" ); return nullptr; + } QString schemeId = context.schemeId(); if ( processFromScheme( context.schemeId() ) ) + { + error = tr( "A simulation with the current hydraulic scheme is currently running." ); return nullptr; + } QPointer sim = currentSimulation(); @@ -519,7 +541,7 @@ bool ReosHydraulicStructure2D::hasSimulationRunning() const bool ReosHydraulicStructure2D::hasResults() const { - ReosHydraulicSchemeCollection *schemesCollection = mHydraulicNetworkContext.network()->hydraulicSchemeCollection(); + ReosHydraulicSchemeCollection *schemesCollection = mNetwork->hydraulicSchemeCollection(); int schemeCount = schemesCollection->schemeCount(); for ( int i = 0; i < schemeCount; ++i ) { @@ -605,7 +627,7 @@ void ReosHydraulicStructure2D::removeAllResults() qDeleteAll( mSimulationResults ); mSimulationResults.clear(); - ReosHydraulicSchemeCollection *schemesColection = mHydraulicNetworkContext.network()->hydraulicSchemeCollection(); + ReosHydraulicSchemeCollection *schemesColection = network()->hydraulicSchemeCollection(); int schemeCount = schemesColection->schemeCount(); for ( int i = 0; i < schemeCount; ++i ) { @@ -634,10 +656,10 @@ void ReosHydraulicStructure2D::removeResults( const ReosCalculationContext &cont if ( mSimulationResults.contains( schemeId ) ) { - delete mSimulationResults.value( schemeId ); + delete mSimulationResults.value( schemeId ); // replace be deleteLater() ? mSimulationResults.remove( schemeId ); - ReosHydraulicScheme *scheme = mNetWork->hydraulicSchemeCollection()->scheme( schemeId ); + ReosHydraulicScheme *scheme = mNetwork->hydraulicSchemeCollection()->scheme( schemeId ); if ( scheme ) { ReosHydraulicSimulation *sim = simulation( scheme ); @@ -653,6 +675,7 @@ void ReosHydraulicStructure2D::init() connect( mPolylinesStructures.get(), &ReosDataObject::dataChanged, this, [this] { + mMeshNeedToBeGenerated = true; if ( mMeshGenerator->autoUpdateParameter()->value() ) generateMeshInPlace(); } ); @@ -662,6 +685,7 @@ void ReosHydraulicStructure2D::init() connect( mMeshResolutionController, &ReosDataObject::dataChanged, this, [this] { + mMeshNeedToBeGenerated = true; if ( mMeshGenerator->autoUpdateParameter()->value() ) generateMeshInPlace(); } ); @@ -692,7 +716,7 @@ QString ReosHydraulicStructure2D::directory() const ReosHydraulicStructureBoundaryCondition *ReosHydraulicStructure2D::boundaryConditionNetWorkElement( const QString boundaryId ) const { - const QList hydrElems = mNetWork->getElements( ReosHydraulicStructureBoundaryCondition::staticType() ); + const QList hydrElems = mNetwork->getElements( ReosHydraulicStructureBoundaryCondition::staticType() ); for ( ReosHydraulicNetworkElement *hydrElem : hydrElems ) { ReosHydraulicStructureBoundaryCondition *bcElem = qobject_cast( hydrElem ); @@ -774,6 +798,7 @@ void ReosHydraulicStructure2D::onMeshGenerated( const ReosMeshFrameData &meshDat mBoundaryVertices = meshData.boundaryVertices; mHolesVertices = meshData.holesVertices; + mMeshNeedToBeGenerated = false; emit meshGenerated(); emit dataChanged(); @@ -782,9 +807,8 @@ void ReosHydraulicStructure2D::onMeshGenerated( const ReosMeshFrameData &meshDat void ReosHydraulicStructure2D::onSimulationFinished( ReosHydraulicSimulation *simulation, const QString &schemeId, ReosSimulationProcess *process, bool success ) { if ( !simulation ) - { return; - } + simulation->saveSimulationResult( this, schemeId, process, success ); //! Now we can remove the old one if still presents @@ -878,7 +902,7 @@ void ReosHydraulicStructure2D::setResultsOnStructure( ReosHydraulicSimulationRes void ReosHydraulicStructure2D::updateResults( const QString &schemeId ) { - if ( mNetWork->calculationContext().schemeId() != schemeId ) + if ( mNetwork->calculationContext().schemeId() != schemeId ) return; if ( currentSimulation() && currentSimulation()->hasResult( this, schemeId ) ) diff --git a/src/core/hydraulicNetwork/reoshydraulicstructure2d.h b/src/core/hydraulicNetwork/reoshydraulicstructure2d.h index fcd28f390..059c93038 100644 --- a/src/core/hydraulicNetwork/reoshydraulicstructure2d.h +++ b/src/core/hydraulicNetwork/reoshydraulicstructure2d.h @@ -116,13 +116,13 @@ class REOSCORE_EXPORT ReosHydraulicStructure2D : public ReosHydraulicNetworkElem QStringList simulationNames() const; //! Returns a process that prepare the current simulation, caller take ownership - ReosProcess *getPreparationProcessSimulation( const ReosCalculationContext &context ); + ReosSimulationPreparationProcess *getPreparationProcessSimulation( const ReosCalculationContext &context, QString &error ); //! Returns a process that prepare the current simulation files in a specific \a diectory, caller take ownership - ReosProcess *getPreparationProcessSimulation( const ReosCalculationContext &context, const QDir &directory ); + ReosSimulationPreparationProcess *getPreparationProcessSimulation( const ReosCalculationContext &context, QString &error, const QDir &directory ); - //! Starts the current simulation, return true if the calculation is effectivly started and returns a pointer to the process - ReosSimulationProcess *startSimulation( const ReosCalculationContext &context ); + //! Starts the current simulation, returns a pointer to the process + ReosSimulationProcess *startSimulation( const ReosCalculationContext &context, QString &error ); //! Returns a pointer to the current simulation process ReosSimulationProcess *simulationProcess( const ReosCalculationContext &context ) const; @@ -214,8 +214,6 @@ class REOSCORE_EXPORT ReosHydraulicStructure2D : public ReosHydraulicNetworkElem //! Return the name of the current dataset QString currentDatasetName() const; - ReosHydraulicNetworkContext hydraulicNetworkContext() const; - void exportResultAsMesh( const QString &fileName ) const; void exportResultAsMeshInGisProject( const QString &fileName, bool keepLayers ); @@ -251,6 +249,7 @@ class REOSCORE_EXPORT ReosHydraulicStructure2D : public ReosHydraulicNetworkElem std::unique_ptr mRoughnessStructure; QVector> mBoundaryVertices; QVector>> mHolesVertices; + bool mMeshNeedToBeGenerated = true; QList mSimulations; @@ -264,8 +263,6 @@ class REOSCORE_EXPORT ReosHydraulicStructure2D : public ReosHydraulicNetworkElem Reos3DMapSettings m3dMapSettings; Reos3DTerrainSettings m3dTerrainSettings; - ReosHydraulicNetworkContext mHydraulicNetworkContext; - void init(); void generateMeshInPlace(); QString directory() const; diff --git a/src/core/hydraulicNetwork/simulation/reoshydraulicsimulation.cpp b/src/core/hydraulicNetwork/simulation/reoshydraulicsimulation.cpp index 41b99416f..9ada3784a 100644 --- a/src/core/hydraulicNetwork/simulation/reoshydraulicsimulation.cpp +++ b/src/core/hydraulicNetwork/simulation/reoshydraulicsimulation.cpp @@ -34,20 +34,20 @@ ReosHydraulicSimulation::ReosHydraulicSimulation( QObject *parent ): ReosDataObj QDir ReosHydraulicSimulation::simulationDir( const ReosHydraulicStructure2D *hydraulicStructure, const QString &schemeId ) const { - if (!hydraulicStructure) - return QDir(); + if ( !hydraulicStructure ) + return QDir(); - if (schemeId.isEmpty()) - return QDir(); + if ( schemeId.isEmpty() ) + return QDir(); QDir dir = hydraulicStructure->structureDirectory(); - - QString schemeDirName = schemeId.split(':').last(); - if ( !dir.cd(schemeDirName) ) + QString schemeDirName = schemeId.split( ':' ).last(); + + if ( !dir.cd( schemeDirName ) ) { - dir.mkdir(schemeDirName); - if ( !dir.cd(schemeDirName) ) + dir.mkdir( schemeDirName ); + if ( !dir.cd( schemeDirName ) ) return QDir(); } @@ -70,11 +70,11 @@ ReosSimulationEngineRegistery::ReosSimulationEngineRegistery() void ReosSimulationEngineRegistery::registerEngineFactory( ReosSimulationEngineFactory *factory ) { - if (factory) - { - mFactories[factory->key()] = std::unique_ptr( factory ); - mFactories[factory->key()]->initializeSettings(); - } + if ( factory ) + { + mFactories[factory->key()] = std::unique_ptr( factory ); + mFactories[factory->key()]->initializeSettings(); + } } ReosHydraulicSimulation *ReosSimulationEngineRegistery::createSimulation( const QString &key, QObject *parent ) const @@ -157,6 +157,8 @@ void ReosSimulationEngineRegistery::loadDynamicLibrary() registerEngineFactory( engineSimulationFactory ); } } + else + qDebug() << library.errorString(); } } @@ -262,7 +264,7 @@ ReosSimulationProcess::ReosSimulationProcess( const ReosCalculationContext &cont } } - qRegisterMetaType< QList >("QList"); + qRegisterMetaType< QList >( "QList" ); connect( this, &ReosSimulationProcess::sendBoundaryFlow, this, &ReosSimulationProcess::onReceiveFlow ); } diff --git a/src/core/hydrograph/reoshydrographsource.cpp b/src/core/hydrograph/reoshydrographsource.cpp index 34d197f57..f9117e91c 100644 --- a/src/core/hydrograph/reoshydrographsource.cpp +++ b/src/core/hydrograph/reoshydrographsource.cpp @@ -215,7 +215,7 @@ ReosHydrograph *ReosHydrographJunction::outputHydrograph() const QPointF ReosHydrographJunction::position( const QString &destinationCrs ) const { - return mNetWork->gisEngine()->transformToCoordinates( mPosition, destinationCrs ); + return mNetwork->gisEngine()->transformToCoordinates( mPosition, destinationCrs ); } void ReosHydrographJunction::setPosition( const ReosSpatialPosition &pos ) diff --git a/src/core/mesh/reosmeshdatasetsource.h b/src/core/mesh/reosmeshdatasetsource.h index 7600d7a4a..e3fdde279 100644 --- a/src/core/mesh/reosmeshdatasetsource.h +++ b/src/core/mesh/reosmeshdatasetsource.h @@ -25,6 +25,7 @@ class ReosMeshDatasetSource : public QObject { Q_OBJECT public: + ReosMeshDatasetSource( QObject *parent = nullptr ); virtual int groupCount() const = 0; diff --git a/src/core/reosmodule.cpp b/src/core/reosmodule.cpp index ae5af3a64..fe498b9e6 100644 --- a/src/core/reosmodule.cpp +++ b/src/core/reosmodule.cpp @@ -104,8 +104,21 @@ void ReosModule::sendMessage( QString mes, MessageType type, bool messageBox ) c emit emitMessage( {type, mes}, messageBox ); } +void ReosModule::setProjectFileName( const QString &projectFileName ) +{ + mProjectFileName = projectFileName; +} + QList ReosModule::actions() const {return mGroupAction->actions();} +const QString ReosModule::projectFileName() +{ + if ( mReosParent ) + return mReosParent->projectFileName(); + + return mProjectFileName; +} + void ReosModule::redo() { if ( mUndoStack ) diff --git a/src/core/reosmodule.h b/src/core/reosmodule.h index 78d538b6d..5a69ffb20 100644 --- a/src/core/reosmodule.h +++ b/src/core/reosmodule.h @@ -52,6 +52,10 @@ class REOSCORE_EXPORT ReosModule : public QObject QList actions() const; + const QString projectFileName(); + + void setProjectFileName( const QString &projectFileName ); + signals: void newCommandToUndoStack( QUndoCommand *command ); void activeUndoStack( QUndoStack *undoStack ); @@ -90,6 +94,7 @@ class REOSCORE_EXPORT ReosModule : public QObject private: ReosModule *mReosParent = nullptr; QList mReosChildren; + QString mProjectFileName; }; #endif // REOSMODULE_H diff --git a/src/gui/hydraulicNetwork/structure2d/reoshydraulicstructure2dproperties.cpp b/src/gui/hydraulicNetwork/structure2d/reoshydraulicstructure2dproperties.cpp index c8d931ebb..e88548401 100644 --- a/src/gui/hydraulicNetwork/structure2d/reoshydraulicstructure2dproperties.cpp +++ b/src/gui/hydraulicNetwork/structure2d/reoshydraulicstructure2dproperties.cpp @@ -373,19 +373,35 @@ void ReosHydraulicStructure2DProperties::onLaunchCalculation() if ( !mStructure2D->currentSimulation() ) { - QMessageBox::information( this, tr( "Run Simulation" ), "No simulation selected." ); + QMessageBox::information( this, tr( "Run Simulation" ), tr( "No simulation selected." ) ); return; } + QString error; + mStructure2D->removeResults( mCalculationContext ); mStructure2D->updateResults( mCalculationContext.schemeId() ); - mActionEditStructure->setEnabled( false ); - std::unique_ptr preparationProcess( mStructure2D->getPreparationProcessSimulation( mCalculationContext ) ); + std::unique_ptr preparationProcess( mStructure2D->getPreparationProcessSimulation( mCalculationContext, error ) ); + if ( !preparationProcess ) + { + QMessageBox::warning( this, tr( "Run Simulation" ), tr( "Simulation did not start for following reason:\n\n%1" ).arg( error ) ); + return; + } + ReosProcessControler *controler = new ReosProcessControler( preparationProcess.get(), this ); controler->exec(); - setCurrentSimulationProcess( mStructure2D->startSimulation( mCalculationContext ), mCalculationContext ); + ReosSimulationProcess *process = mStructure2D->startSimulation( mCalculationContext, error ); + if ( process ) + setCurrentSimulationProcess( process, mCalculationContext ); + else + { + QMessageBox::warning( this, tr( "Run Simulation" ), tr( "Simulation did not start for following reason:\n\n%1" ).arg( error ) ); + return; + } + + mActionEditStructure->setEnabled( false ); } ReosHydraulicSimulationConsole *console = new ReosHydraulicSimulationConsole( mStructure2D->simulationProcess( mCalculationContext ), mGuiContext ); @@ -400,7 +416,13 @@ void ReosHydraulicStructure2DProperties::onExportSimulation() const QDir dir( dirPath ); - std::unique_ptr preparationProcess( mStructure2D->getPreparationProcessSimulation( mCalculationContext, dir ) ); + QString error; + std::unique_ptr preparationProcess( mStructure2D->getPreparationProcessSimulation( mCalculationContext, error, dir ) ); + if ( !preparationProcess ) + { + QMessageBox::warning( this, tr( "Export Simulation" ), tr( "Simulation can't be exported for following reason:\n\n%1" ).arg( error ) ); + return; + } ReosProcessControler *controler = new ReosProcessControler( preparationProcess.get(), this ); controler->exec(); diff --git a/src/gui/hydraulicNetwork/structure2d/reoshydraulicstructureresultexport.cpp b/src/gui/hydraulicNetwork/structure2d/reoshydraulicstructureresultexport.cpp index e2c065e83..05002c0c9 100644 --- a/src/gui/hydraulicNetwork/structure2d/reoshydraulicstructureresultexport.cpp +++ b/src/gui/hydraulicNetwork/structure2d/reoshydraulicstructureresultexport.cpp @@ -12,12 +12,12 @@ ReosHydraulicStructureResultExport::ReosHydraulicStructureResultExport( ReosHydr : QDialog( parent ), ui( new Ui::ReosHydraulicStructureResultExport ) , mStructure( structure ) - , mNetwork( structure ? structure->hydraulicNetworkContext().network() : nullptr ) + , mNetwork( structure ? structure->network() : nullptr ) { ui->setupUi( this ); if ( structure ) { - ui->mSchemeListView->setSchemeCollection( structure->hydraulicNetworkContext().network()->hydraulicSchemeCollection() ); + ui->mSchemeListView->setSchemeCollection( structure->network()->hydraulicSchemeCollection() ); ui->mSchemeListView->setCurrentScheme( currentSchemeId ); onCurrentSchemeChange(); } diff --git a/src/gui/reosmainwindow.cpp b/src/gui/reosmainwindow.cpp index e4014575d..843b760d4 100644 --- a/src/gui/reosmainwindow.cpp +++ b/src/gui/reosmainwindow.cpp @@ -187,13 +187,16 @@ bool ReosMainWindow::openFile() return false; mCurrentProjectFileInfo = QFileInfo( fileName ); - + rootModule()->setProjectFileName( fileName ); settings.setValue( QStringLiteral( "Path/Project" ), mCurrentProjectFileInfo.path() ); bool result = openProject(); if ( !result ) + { mCurrentProjectFileInfo = QFileInfo(); + rootModule()->setProjectFileName( QString() ); + } mProjectIsDirty = false; @@ -227,7 +230,7 @@ bool ReosMainWindow::saveAs() filePath.append( '.' + projectFileSuffix() ); mCurrentProjectFileInfo = QFileInfo( filePath ); } - + rootModule()->setProjectFileName( filePath ); settings.setValue( QStringLiteral( "Path/Project" ), mCurrentProjectFileInfo.path() ); bool saved = saveProject(); @@ -251,6 +254,7 @@ void ReosMainWindow::newProject() } mCurrentProjectFileInfo = QFileInfo(); + rootModule()->setProjectFileName( QString() ); clearProject(); mProjectIsDirty = false; @@ -311,7 +315,7 @@ void ReosMainWindow::about() about->addLibrary( "Qt", qVersion(), "www.qt.io" ); about->addLibrary( ReosGisEngine::gisEngineName(), ReosGisEngine::gisEngineVersion(), ReosGisEngine::gisEngineLink() ); about->addLibrary( ReosPlotWidget::plotEngineName(), ReosPlotWidget::plotEngineVersion(), ReosPlotWidget::plotEngineLink() ); - about->addLibrary(QStringLiteral("Gmsh"), ReosGmshGenerator::version(), QStringLiteral("gmsh.info/")); + about->addLibrary( QStringLiteral( "Gmsh" ), ReosGmshGenerator::version(), QStringLiteral( "gmsh.info/" ) ); QString licenceTxt; QDir dir( QCoreApplication::applicationDirPath() ); diff --git a/src/simulationEngines/telemac/reostelemac2dsimulation.cpp b/src/simulationEngines/telemac/reostelemac2dsimulation.cpp index 68309cbac..d26d0663e 100644 --- a/src/simulationEngines/telemac/reostelemac2dsimulation.cpp +++ b/src/simulationEngines/telemac/reostelemac2dsimulation.cpp @@ -238,7 +238,24 @@ bool ReosTelemac2DSimulation::hasResult( const ReosHydraulicStructure2D *hydraul const QFileInfo fileInfo( dir.filePath( mResultFileName ) ); - return fileInfo.exists(); + if ( !fileInfo.exists() ) + return false; + + // check compatibilty of results with the current mesh + QByteArray curi = fileInfo.filePath().toUtf8(); + MDAL_MeshH meshH = MDAL_LoadMesh( curi.constData() ); + + if ( !meshH ) + return false; + + bool isCompatible = false; + + isCompatible = ( MDAL_M_vertexCount( meshH ) == hydraulicStructure->mesh()->vertexCount() ) && + ( MDAL_M_faceCount( meshH ) == hydraulicStructure->mesh()->faceCount() ); + + MDAL_CloseMesh( meshH ); + + return isCompatible; } void ReosTelemac2DSimulation::saveSimulationResult( const ReosHydraulicStructure2D *hydraulicStructure, const QString &shemeId, ReosSimulationProcess *process, bool success ) const diff --git a/src/simulationEngines/telemac/reostelemacsimulationeditwidget.cpp b/src/simulationEngines/telemac/reostelemacsimulationeditwidget.cpp index 207f18c8a..017fb9542 100644 --- a/src/simulationEngines/telemac/reostelemacsimulationeditwidget.cpp +++ b/src/simulationEngines/telemac/reostelemacsimulationeditwidget.cpp @@ -220,7 +220,7 @@ ReosTelemac2DInititalConditionFromOtherSimulationWidget::ReosTelemac2DInititalCo , mInitialCondition( initialCondition ) , mStructure( structure ) { - ReosHydraulicNetwork *network = structure->hydraulicNetworkContext().network(); + ReosHydraulicNetwork *network = structure->network(); QGridLayout *gridLayout = new QGridLayout( this ); setLayout( gridLayout ); @@ -252,7 +252,7 @@ void ReosTelemac2DInititalConditionFromOtherSimulationWidget::onSchemeChange() { mTimeStepCombo->clear(); - ReosHydraulicNetwork *network = mStructure->hydraulicNetworkContext().network(); + ReosHydraulicNetwork *network = mStructure->network(); ReosHydraulicScheme *otherScheme = network->hydraulicSchemeCollection()->scheme( mSchemeCombo->currentIndex() ); ReosHydraulicSimulation *sim = nullptr;