diff --git a/ApplicationCode/Adm/RIVersionInfo.h b/ApplicationCode/Adm/RIVersionInfo.h deleted file mode 100644 index e37ff76f6c..0000000000 --- a/ApplicationCode/Adm/RIVersionInfo.h +++ /dev/null @@ -1,28 +0,0 @@ -// -// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS -// -// ResInsight is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. -// -// See the GNU General Public License at -// for more details. -// - -// The one and only version info for the application -// The application should use STRPRODUCTVER to display product version information -// -// The PRODUCTVER define is used in VersionInfo block fields FILEVERSION, PRODUCTVERSION and "FileVersion" -// The STRPRODUCTVER define is used in VersionInfo block fields "ProductVersion" -// See file "*.rc2" -// -// PRODUCTVER define contains : , , , -// -// Externally shipped versions should have even build numbers -#define PRODUCTVER "0,4,0,8" -#define STRPRODUCTVER "0.4.8" diff --git a/ApplicationCode/Application/RIApplication.cpp b/ApplicationCode/Application/RIApplication.cpp index a6bddaba64..56a8e4694d 100644 --- a/ApplicationCode/Application/RIApplication.cpp +++ b/ApplicationCode/Application/RIApplication.cpp @@ -35,17 +35,17 @@ #include "RIProcessMonitor.h" #include "RIPreferences.h" -#include "RimReservoir.h" +#include "RimResultReservoir.h" +#include "RimInputReservoir.h" +#include "RimReservoirView.h" #include "RigReservoir.h" #include "RigCell.h" #include "RigReservoirBuilderMock.h" -#include "RimReservoirView.h" - #include #include "cafPdmDocument.h" -#include "RifReaderInterfaceMock.h" +#include "RifReaderMockModel.h" #include "cafCeetronNavigation.h" #include "cafCadNavigation.h" @@ -149,7 +149,7 @@ void RIApplication::setWindowCaptionFromAppState() #endif { - QString projFileName = m_currentProjectFileName; + QString projFileName = m_project->fileName(); if (projFileName.isEmpty()) projFileName = "Untitled project"; capt = projFileName + QString("[*]") + QString(" - ") + capt; @@ -222,7 +222,6 @@ bool RIApplication::loadProject(const QString& projectFileName) } else { - m_currentProjectFileName = projectFileName; m_preferences->lastUsedProjectFileName = projectFileName; writePreferences(); @@ -263,13 +262,15 @@ bool RIApplication::loadLastUsedProject() //-------------------------------------------------------------------------------------------------- bool RIApplication::saveProject() { - if (!QFile::exists(m_currentProjectFileName)) + CVF_ASSERT(m_project.notNull()); + + if (!QFile::exists(m_project->fileName())) { return saveProjectPromptForFileName(); } else { - return saveProjectAs(m_currentProjectFileName); + return saveProjectAs(m_project->fileName()); } } @@ -282,9 +283,9 @@ bool RIApplication::saveProjectPromptForFileName() //if (m_project.isNull()) return true; QString startPath; - if (!m_currentProjectFileName.isEmpty()) + if (!m_project->fileName().isEmpty()) { - QFileInfo fi(m_currentProjectFileName); + QFileInfo fi(m_project->fileName()); startPath = fi.absolutePath(); } else @@ -316,7 +317,6 @@ bool RIApplication::saveProjectAs(const QString& fileName) m_project->fileName = fileName; m_project->writeFile(); - m_currentProjectFileName = fileName; m_preferences->lastUsedProjectFileName = fileName; writePreferences(); @@ -380,9 +380,9 @@ void RIApplication::onProjectOpenedOrClosed() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -QString RIApplication::lastProjectFileName() const +QString RIApplication::currentProjectFileName() const { - return ""; + return m_project->fileName(); } @@ -395,24 +395,27 @@ bool RIApplication::openEclipseCaseFromFile(const QString& fileName) QFileInfo gridFileName(fileName); QString caseName = gridFileName.completeBaseName(); - QString casePath = gridFileName.absolutePath(); - return openEclipseCase(caseName, casePath); + return openEclipseCase(caseName, fileName); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RIApplication::openEclipseCase(const QString& caseName, const QString& casePath) +bool RIApplication::openEclipseCase(const QString& caseName, const QString& caseFileName) { - RimReservoir* rimReservoir = new RimReservoir(); - rimReservoir->caseName = caseName; - rimReservoir->caseDirectory = casePath; + QFileInfo gridFileName(caseFileName); + QString casePath = gridFileName.absolutePath(); - m_project->reservoirs.push_back(rimReservoir); + RimResultReservoir* rimResultReservoir = new RimResultReservoir(); + rimResultReservoir->caseName = caseName; + rimResultReservoir->caseFileName = caseFileName; + rimResultReservoir->caseDirectory = casePath; - RimReservoirView* riv = rimReservoir->createAndAddReservoirView(); + m_project->reservoirs.push_back(rimResultReservoir); + + RimReservoirView* riv = rimResultReservoir->createAndAddReservoirView(); // Select SOIL as default result variable riv->cellResult()->resultType = RimDefines::DYNAMIC_NATIVE; @@ -423,7 +426,36 @@ bool RIApplication::openEclipseCase(const QString& caseName, const QString& case if (!riv->cellResult()->hasResult()) { - riv->cellResult()->resultVariable = ""; + riv->cellResult()->resultVariable = RimDefines::nonSelectedResultName(); + } + + onProjectOpenedOrClosed(); + + return true; +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RIApplication::openInputEclipseCase(const QString& caseName, const QStringList& caseFileNames) +{ + RimInputReservoir* rimInputReservoir = new RimInputReservoir(); + rimInputReservoir->caseName = caseName; + rimInputReservoir->openDataFileSet(caseFileNames); + + m_project->reservoirs.push_back(rimInputReservoir); + + RimReservoirView* riv = rimInputReservoir->createAndAddReservoirView(); + + riv->cellResult()->resultType = RimDefines::INPUT_PROPERTY; + riv->animationMode = true; + + riv->loadDataAndUpdate(); + + if (!riv->cellResult()->hasResult()) + { + riv->cellResult()->resultVariable = RimDefines::nonSelectedResultName(); } onProjectOpenedOrClosed(); @@ -438,7 +470,7 @@ bool RIApplication::openEclipseCase(const QString& caseName, const QString& case //-------------------------------------------------------------------------------------------------- void RIApplication::createMockModel() { - openEclipseCase("Mock Debug Model Simple", ""); + openEclipseCase("Result Mock Debug Model Simple", "Result Mock Debug Model Simple"); } //-------------------------------------------------------------------------------------------------- @@ -446,7 +478,7 @@ void RIApplication::createMockModel() //-------------------------------------------------------------------------------------------------- void RIApplication::createResultsMockModel() { - openEclipseCase("Mock Debug Model With Results", ""); + openEclipseCase("Result Mock Debug Model With Results", "Result Mock Debug Model With Results"); } @@ -455,9 +487,16 @@ void RIApplication::createResultsMockModel() //-------------------------------------------------------------------------------------------------- void RIApplication::createLargeResultsMockModel() { - openEclipseCase("Mock Debug Model Large With Results", ""); + openEclipseCase("Result Mock Debug Model Large With Results", "Result Mock Debug Model Large With Results"); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RIApplication::createInputMockModel() +{ + openInputEclipseCase("Input Mock Debug Model Simple", QStringList("Input Mock Debug Model Simple")); +} //-------------------------------------------------------------------------------------------------- /// diff --git a/ApplicationCode/Application/RIApplication.h b/ApplicationCode/Application/RIApplication.h index 2dca0574f2..7d14004bdf 100644 --- a/ApplicationCode/Application/RIApplication.h +++ b/ApplicationCode/Application/RIApplication.h @@ -73,11 +73,14 @@ public: void createMockModel(); void createResultsMockModel(); void createLargeResultsMockModel(); + void createInputMockModel(); bool openEclipseCaseFromFile(const QString& fileName); - bool openEclipseCase(const QString& caseName, const QString& casePath); + bool openEclipseCase(const QString& caseName, const QString& caseFileName); + bool openInputEclipseCase(const QString& caseName, const QStringList& caseFileNames); + bool loadLastUsedProject(); - QString lastProjectFileName() const; + QString currentProjectFileName() const; bool loadProject(const QString& fileName); bool saveProject(); bool saveProjectAs(const QString& fileName); @@ -110,6 +113,7 @@ private: void onProjectOpenedOrClosed(); void setWindowCaptionFromAppState(); + private slots: void slotWorkerProcessFinished(int exitCode, QProcess::ExitStatus exitStatus); @@ -119,7 +123,6 @@ private: caf::PdmPointer m_activeReservoirView; caf::PdmPointer m_project; - QString m_currentProjectFileName; RiaSocketServer* m_socketServer; caf::UiProcess* m_workerProcess; diff --git a/ApplicationCode/Application/RIPreferences.cpp b/ApplicationCode/Application/RIPreferences.cpp index 90ad023523..9d609bf8a2 100644 --- a/ApplicationCode/Application/RIPreferences.cpp +++ b/ApplicationCode/Application/RIPreferences.cpp @@ -18,6 +18,7 @@ #include "RIStdInclude.h" #include "RIPreferences.h" +#include "cafPdmUiFilePathEditor.h" CAF_PDM_SOURCE_INIT(RIPreferences, "RIPreferences"); //-------------------------------------------------------------------------------------------------- @@ -28,14 +29,19 @@ RIPreferences::RIPreferences(void) CAF_PDM_InitField(&navigationPolicy, "navigationPolicy", caf::AppEnum(RIApplication::NAVIGATION_POLICY_CAD), "Navigation mode", "", "", ""); CAF_PDM_InitFieldNoDefault(&scriptDirectory, "scriptDirectory", "Shared Script Folder", "", "", ""); + scriptDirectory.setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName()); + CAF_PDM_InitField(&scriptEditorExecutable, "scriptEditorExecutable", QString("kate"), "Script Editor", "", "", ""); + scriptEditorExecutable.setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName()); + CAF_PDM_InitField(&octaveExecutable, "octaveExecutable", QString("octave"), "Octave", "", "", ""); + octaveExecutable.setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName()); CAF_PDM_InitField(&useShaders, "useShaders", true, "Use Shaders", "", "", ""); CAF_PDM_InitField(&showHud, "showHud", true, "Show 3D Information", "", "", ""); CAF_PDM_InitFieldNoDefault(&lastUsedProjectFileName,"lastUsedProjectFileName", "Last Used Project File", "", "", ""); - lastUsedProjectFileName.setHidden(true); + lastUsedProjectFileName.setUiHidden(true); } //-------------------------------------------------------------------------------------------------- @@ -45,3 +51,19 @@ RIPreferences::~RIPreferences(void) { } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RIPreferences::defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute * attribute) +{ + if (field == &scriptDirectory) + { + caf::PdmUiFilePathEditorAttribute* myAttr = static_cast(attribute); + if (myAttr) + { + myAttr->m_selectDirectory = true; + } + } +} + diff --git a/ApplicationCode/Application/RIPreferences.h b/ApplicationCode/Application/RIPreferences.h index 577e59e664..b0844d2829 100644 --- a/ApplicationCode/Application/RIPreferences.h +++ b/ApplicationCode/Application/RIPreferences.h @@ -40,4 +40,7 @@ public: // Pdm Fields caf::PdmField showHud; caf::PdmField lastUsedProjectFileName; + +protected: + virtual void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute); }; diff --git a/ApplicationCode/CMakeLists.txt b/ApplicationCode/CMakeLists.txt index d9c5b31f60..59432827a5 100644 --- a/ApplicationCode/CMakeLists.txt +++ b/ApplicationCode/CMakeLists.txt @@ -2,7 +2,19 @@ cmake_minimum_required (VERSION 2.8) project (ApplicationCode) -CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/ApplicationCode/Adm/RIVersionInfo.h.cmake ${CMAKE_SOURCE_DIR}/ApplicationCode/Adm/RIVersionInfo.h) +# NB: The generated file is written to Cmake binary folder to avoid source tree pollution +# This folder is added to include_directories +CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/ApplicationCode/Adm/RIVersionInfo.h.cmake + ${CMAKE_BINARY_DIR}/Generated/RIVersionInfo.h +) + + +if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") + set ( ERT_ROOT "Ert" ) +elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows") + set ( ERT_ROOT "Ert-windows" ) +endif() + include_directories( ${CMAKE_CURRENT_SOURCE_DIR} @@ -14,10 +26,12 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/UserInterface ${CMAKE_CURRENT_SOURCE_DIR}/ProjectDataModel ${CMAKE_CURRENT_SOURCE_DIR}/ReservoirDataModel - ${CMAKE_CURRENT_SOURCE_DIR}/../ThirdParty/Ert/ecl/include - ${CMAKE_CURRENT_SOURCE_DIR}/../ThirdParty/Ert/util/include - ${CMAKE_CURRENT_SOURCE_DIR}/../ThirdParty/Ert/geometry/include - ${CMAKE_CURRENT_SOURCE_DIR}/../ThirdParty/Ert/well/include + ${CMAKE_CURRENT_SOURCE_DIR}/../ThirdParty/${ERT_ROOT}/ecl/include + ${CMAKE_CURRENT_SOURCE_DIR}/../ThirdParty/${ERT_ROOT}/util/include + ${CMAKE_CURRENT_SOURCE_DIR}/../ThirdParty/${ERT_ROOT}/geometry/include + ${CMAKE_CURRENT_SOURCE_DIR}/../ThirdParty/${ERT_ROOT}/well/include + + ${CMAKE_BINARY_DIR}/Generated ) @@ -46,12 +60,14 @@ list( APPEND CPP_SOURCES ) list( APPEND CPP_SOURCES - FileInterface/RifReaderEclipseFileAccess.cpp - FileInterface/RifReaderEclipseRestartFiles.cpp - FileInterface/RifReaderEclipseResultAccess.cpp - FileInterface/RifReaderEclipseUnifiedRestartFile.cpp - FileInterface/RifReaderInterfaceEcl.cpp - FileInterface/RifReaderInterfaceMock.cpp + FileInterface/RifEclipseInputFileTools.cpp + FileInterface/RifEclipseOutputFileTools.cpp + FileInterface/RifEclipseRestartFilesetAccess.cpp + FileInterface/RifEclipseRestartDataAccess.cpp + FileInterface/RifEclipseUnifiedRestartFileAccess.cpp + FileInterface/RifReaderEclipseInput.cpp + FileInterface/RifReaderEclipseOutput.cpp + FileInterface/RifReaderMockModel.cpp ) list( APPEND CPP_SOURCES @@ -68,15 +84,23 @@ list( APPEND CPP_SOURCES ProjectDataModel/RimLegendConfig.cpp ProjectDataModel/RimProject.cpp ProjectDataModel/RimReservoir.cpp + ProjectDataModel/RimInputProperty.cpp + ProjectDataModel/RimInputPropertyCollection.cpp + ProjectDataModel/RimInputReservoir.cpp + ProjectDataModel/RimResultReservoir.cpp ProjectDataModel/RimReservoirView.cpp ProjectDataModel/RimResultDefinition.cpp ProjectDataModel/RimResultSlot.cpp ProjectDataModel/RimCellEdgeResultSlot.cpp - ProjectDataModel/RimUiTreeModelPdm.cpp ProjectDataModel/RimWell.cpp ProjectDataModel/RimWellCollection.cpp ProjectDataModel/RimScriptCollection.cpp ProjectDataModel/RimCalcScript.cpp + ProjectDataModel/RimExportInputPropertySettings.cpp + ProjectDataModel/RimBinaryExportSettings.cpp + + ProjectDataModel/RimUiTreeModelPdm.cpp + ProjectDataModel/RimUiTreeView.cpp ) list( APPEND CPP_SOURCES @@ -103,7 +127,10 @@ list( APPEND CPP_SOURCES # Define files for MOC-ing set ( QT_MOC_HEADERS Application/RIApplication.h + ProjectDataModel/RimUiTreeModelPdm.h + ProjectDataModel/RimUiTreeView.h + UserInterface/RIMainWindow.h UserInterface/RIPreferencesDialog.h UserInterface/RIResultInfoPanel.h @@ -144,11 +171,13 @@ list( REMOVE_ITEM RAW_SOURCES ModelVisualization/RivWellHeadPartMgr.cpp) list( REMOVE_ITEM RAW_SOURCES - FileInterface/RifReaderEclipseFileAccess.cpp - FileInterface/RifReaderEclipseRestartFiles.cpp - FileInterface/RifReaderEclipseResultAccess.cpp - FileInterface/RifReaderEclipseUnifiedRestartFile.cpp - FileInterface/RifReaderInterfaceEcl.cpp + FileInterface/RifEclipseInputFileTools.cpp + FileInterface/RifEclipseOutputFileTools.cpp + FileInterface/RifEclipseRestartFilesetAccess.cpp + FileInterface/RifEclipseRestartDataAccess.cpp + FileInterface/RifEclipseUnifiedRestartFileAccess.cpp + FileInterface/RifReaderEclipseInput.cpp + FileInterface/RifReaderEclipseOutput.cpp ) include( CustomPCH.cmake ) @@ -183,13 +212,12 @@ add_executable(ResInsight set( LINK_LIBRARIES - cafProjectDataModel cafPdmCvf cafUserInterface - cafViewer - cafAnimControl + cafProjectDataModel + cafViewer + cafAnimControl CommonCode - QtPropertyBrowser LibGuiQt LibViewing LibRender @@ -199,33 +227,54 @@ set( LINK_LIBRARIES ${QT_LIBRARIES} ) -IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - set ( LINUX_LINK_LIBRARIES +if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + set ( EXTERNAL_LINK_LIBRARIES ${CMAKE_CURRENT_SOURCE_DIR}/../ThirdParty/Ert/ecl/lib/libecl.a ${CMAKE_CURRENT_SOURCE_DIR}/../ThirdParty/Ert/util/lib/libutil.a ${CMAKE_CURRENT_SOURCE_DIR}/../ThirdParty/Ert/geometry/lib/libgeometry.a ${CMAKE_CURRENT_SOURCE_DIR}/../ThirdParty/Ert/well/lib/libwell.a lapack ) -ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") +elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + set ( EXTERNAL_LINK_LIBRARIES + ${CMAKE_CURRENT_SOURCE_DIR}/../ThirdParty/Ert-windows/ecl/lib/libecl.lib + ${CMAKE_CURRENT_SOURCE_DIR}/../ThirdParty/Ert-windows/util/lib/libutil.lib + ${CMAKE_CURRENT_SOURCE_DIR}/../ThirdParty/Ert-windows/geometry/lib/libgeometry.lib + ${CMAKE_CURRENT_SOURCE_DIR}/../ThirdParty/Ert-windows/well/lib/libwell.lib + ) +endif() -target_link_libraries( ResInsight ${LINK_LIBRARIES} ${LINUX_LINK_LIBRARIES}) +target_link_libraries( ResInsight ${LINK_LIBRARIES} ${EXTERNAL_LINK_LIBRARIES}) -# Copy Qt Dlls +# Copy Dlls if (MSVC) - set (QTLIBLIST QtCore QtGui QtOpenGl QtNetwork) + + # Qt DLLs + set (QTLIBLIST QtCore QtCored QtGui QtGuid QtOpenGl QtOpenGld QtNetwork QtNetworkd) foreach (qtlib ${QTLIBLIST}) - - # Debug - execute_process(COMMAND cmake -E copy_if_different ${QT_BINARY_DIR}/${qtlib}d4.dll ${CMAKE_CURRENT_BINARY_DIR}/Debug/${qtlib}d4.dll) - - # Release - execute_process(COMMAND cmake -E copy_if_different ${QT_BINARY_DIR}/${qtlib}4.dll ${CMAKE_CURRENT_BINARY_DIR}/Release/${qtlib}4.dll) - - # Release With debug info - execute_process(COMMAND cmake -E copy_if_different ${QT_BINARY_DIR}/${qtlib}4.dll ${CMAKE_CURRENT_BINARY_DIR}/RelWithDebInfo/${qtlib}4.dll) - + add_custom_command(TARGET ResInsight POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${QT_BINARY_DIR}/${qtlib}4.dll" + ${CMAKE_CURRENT_BINARY_DIR}/$) endforeach( qtlib ) + + + # DLLs ERT depends on + add_custom_command(TARGET ResInsight POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + "${PROJECT_SOURCE_DIR}/../ThirdParty/Ert-windows/bin/" + ${CMAKE_CURRENT_BINARY_DIR}/$) + + + # ERT DLLs + set (ERT_MODULES ecl geometry util well) + foreach (ert_module ${ERT_MODULES}) + add_custom_command(TARGET ResInsight POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${CMAKE_CURRENT_SOURCE_DIR}/../ThirdParty/Ert-windows/${ert_module}/lib/lib${ert_module}.dll" + ${CMAKE_CURRENT_BINARY_DIR}/$) + endforeach() + endif(MSVC) ############################################################################# @@ -234,16 +283,15 @@ endif(MSVC) if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") set_target_properties(ResInsight PROPERTIES INSTALL_RPATH "${RESINSIGHT_FINAL_INSTALL_PATH};.") - set (RESINSIGHT_FILES - ${QT_LIBRARY_DIR}/libQtCore.so.4.7.3 - ${QT_LIBRARY_DIR}/libQtGui.so.4.7.3 - ${QT_LIBRARY_DIR}/libQtOpenGL.so.4.7.3 - ${QT_LIBRARY_DIR}/libQtNetwork.so.4.7.3 - ${QT_LIBRARY_DIR}/libQtCore.so.4 - ${QT_LIBRARY_DIR}/libQtGui.so.4 - ${QT_LIBRARY_DIR}/libQtOpenGL.so.4 - ${QT_LIBRARY_DIR}/libQtNetwork.so.4 + + # Find Qt libraries and sym links + file (GLOB RESINSIGHT_FILES + ${QT_LIBRARY_DIR}/libQtCore.so* + ${QT_LIBRARY_DIR}/libQtGui.so* + ${QT_LIBRARY_DIR}/libQtOpenGL.so* + ${QT_LIBRARY_DIR}/libQtNetwork.so* ) + endif() if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") diff --git a/ApplicationCode/FileInterface/FileInterface_UnitTests/CMakeLists.txt b/ApplicationCode/FileInterface/FileInterface_UnitTests/CMakeLists.txt index b83c4da24f..c7d3d373d0 100644 --- a/ApplicationCode/FileInterface/FileInterface_UnitTests/CMakeLists.txt +++ b/ApplicationCode/FileInterface/FileInterface_UnitTests/CMakeLists.txt @@ -7,6 +7,12 @@ project ( ${ProjectName} ) find_package (Qt4 COMPONENTS QtCore QtGui QtMain QtOpenGl REQUIRED) include (${QT_USE_FILE}) +if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") + set ( ERT_ROOT "Ert" ) +elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows") + set ( ERT_ROOT "Ert-windows" ) +endif() + include_directories( ${LibCore_SOURCE_DIR} ${LibGeometry_SOURCE_DIR} @@ -23,19 +29,22 @@ include_directories( ${ResInsight_SOURCE_DIR}/CommonCode - ${ResInsight_SOURCE_DIR}/ThirdParty/Ert/ecl/include - ${ResInsight_SOURCE_DIR}/ThirdParty/Ert/util/include - ${ResInsight_SOURCE_DIR}/ThirdParty/Ert/well/include + ${ResInsight_SOURCE_DIR}/ThirdParty/${ERT_ROOT}/ecl/include + ${ResInsight_SOURCE_DIR}/ThirdParty/${ERT_ROOT}/util/include + ${ResInsight_SOURCE_DIR}/ThirdParty/${ERT_ROOT}/well/include ) + set( FILEINTERFACE_CPP_SOURCES - ../RifReaderEclipseFileAccess.cpp - ../RifReaderEclipseRestartFiles.cpp - ../RifReaderEclipseResultAccess.cpp - ../RifReaderEclipseUnifiedRestartFile.cpp - ../RifReaderInterfaceEcl.cpp - ../RifReaderInterfaceMock.cpp + ../RifEclipseInputFileTools.cpp + ../RifEclipseOutputFileTools.cpp + ../RifEclipseRestartFilesetAccess.cpp + ../RifEclipseRestartDataAccess.cpp + ../RifEclipseUnifiedRestartFileAccess.cpp + ../RifReaderEclipseOutput.cpp + ../RifReaderEclipseInput.cpp + ../RifReaderMockModel.cpp ) set( RESERVOIRDATAMODEL_CPP_SOURCES @@ -47,6 +56,7 @@ set( RESERVOIRDATAMODEL_CPP_SOURCES ${ResInsight_SOURCE_DIR}/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp ${ResInsight_SOURCE_DIR}/ApplicationCode/ReservoirDataModel/RigReservoirCellResults.cpp ${ResInsight_SOURCE_DIR}/ApplicationCode/ReservoirDataModel/RigWellResults.cpp + ${ResInsight_SOURCE_DIR}/cafUserInterface/cafProgressInfo.cpp ) set( CPP_SOURCES @@ -59,7 +69,7 @@ source_group( "ReservoirDataModel" FILES ${RESERVOIRDATAMODEL_CPP_SOURCES} ) set( UNIT_TEST_CPP_SOURCES main.cpp - RifReaderInterfaceEcl-Test.cpp + RifReaderEclipseOutput-Test.cpp Ert-Test.cpp ) @@ -76,6 +86,7 @@ set( LINK_LIBRARIES ) + add_executable( ${ProjectName} ${CPP_SOURCES} ${UNIT_TEST_CPP_SOURCES} @@ -85,35 +96,55 @@ add_executable( ${ProjectName} -IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - set ( LINUX_LINK_LIBRARIES +if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") + set ( EXTERNAL_LINK_LIBRARIES ${CMAKE_CURRENT_SOURCE_DIR}/../../../ThirdParty/Ert/ecl/lib/libecl.a ${CMAKE_CURRENT_SOURCE_DIR}/../../../ThirdParty/Ert/util/lib/libutil.a + ${CMAKE_CURRENT_SOURCE_DIR}/../../../ThirdParty/Ert/geometry/lib/libgeometry.a ${CMAKE_CURRENT_SOURCE_DIR}/../../../ThirdParty/Ert/well/lib/libwell.a lapack ) - - # Linux specific code - set(CMAKE_CXX_FLAGS "-DCVF_LINUX -DUSE_ECL_LIB -pipe -Wextra -Woverloaded-virtual -Wformat") - set(CMAKE_CXX_FLAGS_DEBUG "-g -DDEBUG -D_DEBUG") - set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNO_DEBUG") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp") - -ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") +elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows") + set ( EXTERNAL_LINK_LIBRARIES + ${CMAKE_CURRENT_SOURCE_DIR}/../../../ThirdParty/Ert-windows/ecl/lib/libecl.lib + ${CMAKE_CURRENT_SOURCE_DIR}/../../../ThirdParty/Ert-windows/util/lib/libutil.lib + ${CMAKE_CURRENT_SOURCE_DIR}/../../../ThirdParty/Ert-windows/geometry/lib/libgeometry.lib + ${CMAKE_CURRENT_SOURCE_DIR}/../../../ThirdParty/Ert-windows/well/lib/libwell.lib + ) +endif() -target_link_libraries( ${ProjectName} ${LINK_LIBRARIES} ${LINUX_LINK_LIBRARIES}) +target_link_libraries( ${ProjectName} ${LINK_LIBRARIES} ${EXTERNAL_LINK_LIBRARIES}) -# Copy Qt Dlls + +# Copy Dlls if (MSVC) - set (QTLIBLIST QtCore QtGui QtOpenGl) + + # Qt DLLs + set (QTLIBLIST QtCore QtCored QtGui QtGuid QtOpenGl QtOpenGld QtNetwork QtNetworkd) foreach (qtlib ${QTLIBLIST}) - - # Debug - execute_process(COMMAND cmake -E copy_if_different ${QT_BINARY_DIR}/${qtlib}d4.dll ${CMAKE_CURRENT_BINARY_DIR}/Debug/${qtlib}d4.dll) - - # Release - execute_process(COMMAND cmake -E copy_if_different ${QT_BINARY_DIR}/${qtlib}4.dll ${CMAKE_CURRENT_BINARY_DIR}/Release/${qtlib}4.dll) + add_custom_command(TARGET ${ProjectName} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${QT_BINARY_DIR}/${qtlib}4.dll" + ${CMAKE_CURRENT_BINARY_DIR}/$) endforeach( qtlib ) + + + # DLLs ERT depends on + add_custom_command(TARGET ${ProjectName} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + "${PROJECT_SOURCE_DIR}/../../../ThirdParty/Ert-windows/bin/" + ${CMAKE_CURRENT_BINARY_DIR}/$) + + + # ERT DLLs + set (ERT_MODULES ecl geometry util well) + foreach (ert_module ${ERT_MODULES}) + add_custom_command(TARGET ${ProjectName} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${CMAKE_CURRENT_SOURCE_DIR}/../../../ThirdParty/Ert-windows/${ert_module}/lib/lib${ert_module}.dll" + ${CMAKE_CURRENT_BINARY_DIR}/$) + endforeach() + endif(MSVC) diff --git a/ApplicationCode/FileInterface/FileInterface_UnitTests/Ert-Test.cpp b/ApplicationCode/FileInterface/FileInterface_UnitTests/Ert-Test.cpp index 57d5d5ebbc..d51e022bed 100644 --- a/ApplicationCode/FileInterface/FileInterface_UnitTests/Ert-Test.cpp +++ b/ApplicationCode/FileInterface/FileInterface_UnitTests/Ert-Test.cpp @@ -38,8 +38,10 @@ #include "gtest/gtest.h" +#include "RigReservoir.h" +#include "RifReaderEclipseInput.h" - +#if 0 //-------------------------------------------------------------------------------------------------- /// This file contains test code taken from the test cases in ERT source code. // There is a typedef issue (center) between ERT and QTextStream, so this file does not include any @@ -47,7 +49,7 @@ //-------------------------------------------------------------------------------------------------- TEST(RigReservoirTest, WellTestErt) { - char filename[1024] = "/mnt/hgfs/Statoil/testcase_juli_2011/data/TEST10K_FLT_LGR_NNC.UNRST"; + char filename[1024] = "TEST10K_FLT_LGR_NNC.UNRST"; well_info_type * well_info = well_info_alloc( NULL ); well_info_load_rstfile( well_info , filename); @@ -100,5 +102,20 @@ TEST(RigReservoirTest, WellTestErt) well_info_free( well_info ); } +#endif +//-------------------------------------------------------------------------------------------------- +/// This file contains test code taken from the test cases in ERT source code. +// There is a typedef issue (center) between ERT and QTextStream, so this file does not include any +// Qt files. +//-------------------------------------------------------------------------------------------------- +TEST(RigReservoirTest, ElipseInputGridFile) +{ + RigReservoir res; + RifReaderEclipseInput inputReader; + bool result = inputReader.open("TEST10K_FLT_LGR_NNC.grdecl", &res); + EXPECT_TRUE(result); + EXPECT_EQ(size_t(1), res.mainGrid()->cells().size()); + EXPECT_EQ(size_t(1), res.mainGrid()->numActiveCells()); +} #endif //USE_ECL_LIB diff --git a/ApplicationCode/FileInterface/FileInterface_UnitTests/RifReaderInterfaceEcl-Test.cpp b/ApplicationCode/FileInterface/FileInterface_UnitTests/RifReaderEclipseOutput-Test.cpp similarity index 67% rename from ApplicationCode/FileInterface/FileInterface_UnitTests/RifReaderInterfaceEcl-Test.cpp rename to ApplicationCode/FileInterface/FileInterface_UnitTests/RifReaderEclipseOutput-Test.cpp index 8ed44a7444..0e298da20c 100644 --- a/ApplicationCode/FileInterface/FileInterface_UnitTests/RifReaderInterfaceEcl-Test.cpp +++ b/ApplicationCode/FileInterface/FileInterface_UnitTests/RifReaderEclipseOutput-Test.cpp @@ -23,18 +23,67 @@ #include "RigReservoir.h" -#include "RifReaderInterfaceEcl.h" +#include "RifReaderEclipseOutput.h" +//#include "RifEclipseUnifiedRestartFileAccess.h" +/* +TEST(RigReservoirTest, UnifiedTestFile) +{ + + // Location of test dataset received from Håkon Høgstøl in July 2011 with 10k active cells +#ifdef WIN32 + QString filename("d:/Models/Statoil/testcase_juli_2011/data/TEST10K_FLT_LGR_NNC.UNRST"); +#else + QString filename("/mnt/hgfs/Statoil/testcase_juli_2011/data/TEST10K_FLT_LGR_NNC.UNRST"); +#endif + + size_t numActiveCells = 11125; + size_t numGrids = 2; + + { + cvf::ref restartFile = new RifEclipseUnifiedRestartFileAccess(numGrids, numActiveCells); + + QStringList fileNameList; + fileNameList << filename; + restartFile->open(fileNameList); + + QStringList resultNames = restartFile->resultNames(); + qDebug() << "Result names\n" << resultNames; + + QStringList timeStepText = restartFile->timeStepsText(); + qDebug() << "Time step texts\n" << timeStepText; + + std::vector resultValues; + size_t timeStep = 0; + restartFile->results(resultNames[0], timeStep, &resultValues); + + size_t i; + for (i = 0; i < 500; i++) + { + qDebug() << resultValues[i]; + } + + } + + +} +*/ + +#if 0 //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- TEST(RigReservoirTest, BasicTest) { - cvf::ref readerInterfaceEcl = new RifReaderInterfaceECL; + cvf::ref readerInterfaceEcl = new RifReaderEclipseOutput; cvf::ref reservoir = new RigReservoir; // Location of test dataset received from Håkon Høgstøl in July 2011 with 10k active cells +#ifdef WIN32 + QString filename("TEST10K_FLT_LGR_NNC.EGRID"); +#else QString filename("/mnt/hgfs/Statoil/testcase_juli_2011/data/TEST10K_FLT_LGR_NNC.EGRID"); +#endif bool result = readerInterfaceEcl->open(filename, reservoir.p()); EXPECT_TRUE(result); @@ -83,17 +132,21 @@ TEST(RigReservoirTest, BasicTest) //-------------------------------------------------------------------------------------------------- TEST(RigReservoirTest, WellTest) { - cvf::ref readerInterfaceEcl = new RifReaderInterfaceECL; + cvf::ref readerInterfaceEcl = new RifReaderEclipseOutput; cvf::ref reservoir = new RigReservoir; // Location of test dataset received from Håkon Høgstøl in July 2011 with 10k active cells +#ifdef WIN32 + QString filename("TEST10K_FLT_LGR_NNC.EGRID"); +#else QString filename("/mnt/hgfs/Statoil/testcase_juli_2011/data/TEST10K_FLT_LGR_NNC.EGRID"); +#endif bool result = readerInterfaceEcl->open(filename, reservoir.p()); EXPECT_TRUE(result); cvf::UByteArray* mainGridWellCells = reservoir->wellCellsInGrid(0); EXPECT_TRUE(mainGridWellCells->size() == reservoir->mainGrid()->cellCount()); - - } + +#endif diff --git a/ApplicationCode/FileInterface/RifEclipseInputFileTools.cpp b/ApplicationCode/FileInterface/RifEclipseInputFileTools.cpp new file mode 100644 index 0000000000..1188cd95d7 --- /dev/null +++ b/ApplicationCode/FileInterface/RifEclipseInputFileTools.cpp @@ -0,0 +1,434 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RifEclipseInputFileTools.h" +#include "RifReaderEclipseOutput.h" +#include "RigReservoirCellResults.h" + +#include "RigReservoir.h" +#include "cafProgressInfo.h" + +#include +#include +#include + +#include +#include + +#ifdef USE_ECL_LIB +#include "ecl_grid.h" +#include "well_state.h" +#include "util.h" +#endif +#include + + +//-------------------------------------------------------------------------------------------------- +/// Constructor +//-------------------------------------------------------------------------------------------------- +RifEclipseInputFileTools::RifEclipseInputFileTools() +{ + +} + + +//-------------------------------------------------------------------------------------------------- +/// Destructor +//-------------------------------------------------------------------------------------------------- +RifEclipseInputFileTools::~RifEclipseInputFileTools() +{ + +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RifEclipseInputFileTools::openGridFile(const QString& fileName, RigReservoir* reservoir) +{ + CVF_ASSERT(reservoir); + + FILE* gridFilePointer = util_fopen(fileName.toLatin1().data(), "r"); + if (!gridFilePointer) return false; + + // Main grid Dimentions + // SPECGRID - This is whats normally available, but not really the input to Eclipse. + // DIMENS - Is what Eclipse expects and uses, but is not defined in the GRID section and is not (?) available normally + // ZCORN, COORD, ACTNUM, MAPAXES + + //ecl_kw_type * ecl_kw_fscanf_alloc_grdecl_dynamic__( FILE * stream , const char * kw , bool strict , ecl_type_enum ecl_type); + //ecl_grid_type * ecl_grid_alloc_GRDECL_kw( int nx, int ny , int nz , const ecl_kw_type * zcorn_kw , const ecl_kw_type * coord_kw , const ecl_kw_type * actnum_kw , const ecl_kw_type * mapaxes_kw ); + + ecl_kw_type* specGridKw = NULL; + ecl_kw_type* zCornKw = NULL; + ecl_kw_type* coordKw = NULL; + ecl_kw_type* actNumKw = NULL; + ecl_kw_type* mapAxesKw = NULL; + + // Try to read all the needed keywords. Early exit if some are not found + caf::ProgressInfo progress(7, "Read Grid from Eclipse Input file"); + bool allKwReadOk = true; + + allKwReadOk = allKwReadOk && NULL != (specGridKw = ecl_kw_fscanf_alloc_grdecl_dynamic__( gridFilePointer , "SPECGRID" , false , ECL_INT_TYPE)); + progress.setProgress(1); + allKwReadOk = allKwReadOk && NULL != (zCornKw = ecl_kw_fscanf_alloc_grdecl_dynamic__( gridFilePointer , "ZCORN" , false , ECL_FLOAT_TYPE)); + progress.setProgress(2); + allKwReadOk = allKwReadOk && NULL != (coordKw = ecl_kw_fscanf_alloc_grdecl_dynamic__( gridFilePointer , "COORD" , false , ECL_FLOAT_TYPE)); + progress.setProgress(3); + allKwReadOk = allKwReadOk && NULL != (actNumKw = ecl_kw_fscanf_alloc_grdecl_dynamic__( gridFilePointer , "ACTNUM" , false , ECL_INT_TYPE)); + progress.setProgress(4); + allKwReadOk = allKwReadOk && NULL != (mapAxesKw = ecl_kw_fscanf_alloc_grdecl_dynamic__( gridFilePointer , "MAPAXES" , false , ECL_FLOAT_TYPE)); + + if (!allKwReadOk) + { + if(specGridKw) ecl_kw_free(specGridKw); + if(zCornKw) ecl_kw_free(zCornKw); + if(coordKw) ecl_kw_free(coordKw); + if(actNumKw) ecl_kw_free(actNumKw); + if(mapAxesKw) ecl_kw_free(mapAxesKw); + + return false; + } + + progress.setProgress(5); + + int nx = ecl_kw_iget_int(specGridKw, 0); + int ny = ecl_kw_iget_int(specGridKw, 1); + int nz = ecl_kw_iget_int(specGridKw, 2); + + ecl_grid_type* inputGrid = ecl_grid_alloc_GRDECL_kw( nx, ny, nz, zCornKw, coordKw, actNumKw, mapAxesKw ); + + progress.setProgress(6); + + RifReaderEclipseOutput::transferGeometry(inputGrid, reservoir); + + progress.setProgress(7); + progress.setProgressDescription("Cleaning up ..."); + + ecl_kw_free(specGridKw); + ecl_kw_free(zCornKw); + ecl_kw_free(coordKw); + ecl_kw_free(actNumKw); + ecl_kw_free(mapAxesKw); + + ecl_grid_free(inputGrid); + + util_fclose(gridFilePointer); + + return true; +} + + +//-------------------------------------------------------------------------------------------------- +/// Read known properties from the input file +//-------------------------------------------------------------------------------------------------- +std::map RifEclipseInputFileTools::readProperties(const QString &fileName, RigReservoir *reservoir) +{ + CVF_ASSERT(reservoir); + + std::set knownKeywordSet; + { + const std::vector& knownKeywords = RifEclipseInputFileTools::knownPropertyKeywords(); + for( size_t fkIt = 0; fkIt < knownKeywords.size(); ++fkIt) knownKeywordSet.insert(knownKeywords[fkIt]); + } + + caf::ProgressInfo mainProgress(2, "Reading Eclipse Input properties"); + caf::ProgressInfo startProgress(knownKeywordSet.size(), "Scanning for known properties"); + + std::vector fileKeywords = RifEclipseInputFileTools::findKeywordsOnFile(fileName); + + mainProgress.setProgress(1); + caf::ProgressInfo progress(fileKeywords.size(), "Reading properties"); + + FILE* gridFilePointer = util_fopen(fileName.toLatin1().data(), "r"); + + if (!gridFilePointer || !fileKeywords.size() ) + { + return std::map(); + } + + bool isSomethingRead = false; + std::map newResults; + for (size_t i = 0; i < fileKeywords.size(); ++i) + { + std::cout << fileKeywords[i].toLatin1().data() << std::endl; + if (knownKeywordSet.count(fileKeywords[i])) + { + ecl_kw_type* eclKeyWordData = ecl_kw_fscanf_alloc_grdecl_dynamic__( gridFilePointer , fileKeywords[i].toLatin1().data() , false , ECL_FLOAT_TYPE); + if (eclKeyWordData) + { + QString newResultName = reservoir->mainGrid()->results()->makeResultNameUnique(fileKeywords[i]); + + size_t resultIndex = reservoir->mainGrid()->results()->addEmptyScalarResult(RimDefines::INPUT_PROPERTY, newResultName); // Should really merge with inputProperty object information because we need to use PropertyName, and not keyword + + std::vector< std::vector >& newPropertyData = reservoir->mainGrid()->results()->cellScalarResults(resultIndex); + newPropertyData.push_back(std::vector()); + newPropertyData[0].resize(ecl_kw_get_size(eclKeyWordData), HUGE_VAL); + ecl_kw_get_data_as_double(eclKeyWordData, newPropertyData[0].data()); + + ecl_kw_free(eclKeyWordData); + newResults[newResultName] = fileKeywords[i]; + } + } + progress.setProgress(i); + } + + util_fclose(gridFilePointer); + return newResults; +} + +//-------------------------------------------------------------------------------------------------- +/// Read all the keywords from a file +//-------------------------------------------------------------------------------------------------- +std::vector RifEclipseInputFileTools::findKeywordsOnFile(const QString &fileName) +{ + std::vector keywords; + + std::ifstream is(fileName.toLatin1().data()); + + while (is) + { + std::string word; + is >> word; + if (word.size() && isalpha(word[0])) + { + keywords.push_back(word.c_str()); + } + + is.ignore(20000, '\n'); + } + + is.close(); + + /* + FILE* gridFilePointer = util_fopen(fileName.toLatin1().data(), "r"); + + if (!gridFilePointer) return keywords; + + char * keyWordString = NULL; + + keyWordString = ecl_kw_grdecl_alloc_next_header(gridFilePointer); + + while(keyWordString) + { + keywords.push_back(keyWordString); + util_realloc(keyWordString, 0, "RifEclipseInputFileTools::findKeywordsOnFile"); + keyWordString = ecl_kw_grdecl_alloc_next_header(gridFilePointer); + } + + util_fclose(gridFilePointer); + */ + return keywords; +} + +//-------------------------------------------------------------------------------------------------- +/// Reads the property data requested into the \a reservoir, overwriting any previous +/// propeties with the same name. +//-------------------------------------------------------------------------------------------------- +bool RifEclipseInputFileTools::readProperty(const QString& fileName, RigReservoir* reservoir, const QString& eclipseKeyWord, const QString& resultName) +{ + CVF_ASSERT(reservoir); + + FILE* filePointer = util_fopen(fileName.toLatin1().data(), "r"); + if (!filePointer) return false; + + ecl_kw_type* eclKeyWordData = ecl_kw_fscanf_alloc_grdecl_dynamic__( filePointer , eclipseKeyWord.toLatin1().data() , false , ECL_FLOAT_TYPE); + bool isOk = false; + if (eclKeyWordData) + { + QString newResultName = resultName; + size_t resultIndex = reservoir->mainGrid()->results()->findScalarResultIndex(newResultName); + if (resultIndex == cvf::UNDEFINED_SIZE_T) + { + resultIndex = reservoir->mainGrid()->results()->addEmptyScalarResult(RimDefines::INPUT_PROPERTY, newResultName); + } + + std::vector< std::vector >& newPropertyData = reservoir->mainGrid()->results()->cellScalarResults(resultIndex); + newPropertyData.resize(1); + newPropertyData[0].resize(ecl_kw_get_size(eclKeyWordData), HUGE_VAL); + ecl_kw_get_data_as_double(eclKeyWordData, newPropertyData[0].data()); + isOk = true; + ecl_kw_free(eclKeyWordData); + } + + util_fclose(filePointer); + return isOk; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +const std::vector& RifEclipseInputFileTools::knownPropertyKeywords() +{ + static std::vector knownKeywords; + static bool isInitialized = false; + if (!isInitialized) + { + knownKeywords.push_back("AQUIFERA"); + knownKeywords.push_back("ACTNUM"); + knownKeywords.push_back("EQLNUM"); + knownKeywords.push_back("FIPNUM"); + knownKeywords.push_back("KRG"); + knownKeywords.push_back("KRGR"); + knownKeywords.push_back("KRO"); + knownKeywords.push_back("KRORG"); + knownKeywords.push_back("KRORW"); + knownKeywords.push_back("KRW"); + knownKeywords.push_back("KRWR"); + knownKeywords.push_back("MINPVV"); + knownKeywords.push_back("MULTPV"); + knownKeywords.push_back("MULTX"); + knownKeywords.push_back("MULTX-"); + knownKeywords.push_back("MULTY"); + knownKeywords.push_back("MULTY-"); + knownKeywords.push_back("MULTZ"); + knownKeywords.push_back("NTG"); + knownKeywords.push_back("PCG"); + knownKeywords.push_back("PCW"); + knownKeywords.push_back("PERMX"); + knownKeywords.push_back("PERMY"); + knownKeywords.push_back("PERMZ"); + knownKeywords.push_back("PORO"); + knownKeywords.push_back("PVTNUM"); + knownKeywords.push_back("SATNUM"); + knownKeywords.push_back("SGCR"); + knownKeywords.push_back("SGL"); + knownKeywords.push_back("SGLPC"); + knownKeywords.push_back("SGU"); + knownKeywords.push_back("SGWCR"); + knownKeywords.push_back("SWATINIT"); + knownKeywords.push_back("SWCR"); + knownKeywords.push_back("SWGCR"); + knownKeywords.push_back("SWL"); + knownKeywords.push_back("SWLPC"); + knownKeywords.push_back("TRANX"); + knownKeywords.push_back("TRANY"); + knownKeywords.push_back("TRANZ"); + + isInitialized = true; + } + return knownKeywords; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RifEclipseInputFileTools::writePropertyToTextFile(const QString& fileName, RigReservoir* reservoir, size_t timeStep, const QString& resultName, const QString& eclipseKeyWord) +{ + CVF_ASSERT(reservoir); + + size_t resultIndex = reservoir->mainGrid()->results()->findScalarResultIndex(resultName); + if (resultIndex == cvf::UNDEFINED_SIZE_T) + { + return false; + } + + QFile file(fileName); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) + { + return false; + } + + std::vector< std::vector >& resultData = reservoir->mainGrid()->results()->cellScalarResults(resultIndex); + if (resultData.size() == 0) + { + return false; + } + + std::vector& singleTimeStepData = resultData[timeStep]; + writeDataToTextFile(&file, eclipseKeyWord, singleTimeStepData); + + return true; +} + +//-------------------------------------------------------------------------------------------------- +/// Create and write a result vector with values for all cells. +/// undefinedValue is used for cells with no result +//-------------------------------------------------------------------------------------------------- +bool RifEclipseInputFileTools::writeBinaryResultToTextFile(const QString& fileName, RigReservoir* reservoir, size_t timeStep, const QString& resultName, const QString& eclipseKeyWord, const double undefinedValue) +{ + CVF_ASSERT(reservoir); + + size_t resultIndex = reservoir->mainGrid()->results()->findScalarResultIndex(resultName); + if (resultIndex == cvf::UNDEFINED_SIZE_T) + { + return false; + } + + QFile file(fileName); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) + { + return false; + } + + std::vector resultData; + size_t i, j, k; + + for (k = 0; k < reservoir->mainGrid()->cellCountK(); k++) + { + for (j = 0; j < reservoir->mainGrid()->cellCountJ(); j++) + { + for (i = 0; i < reservoir->mainGrid()->cellCountI(); i++) + { + double resultValue = reservoir->mainGrid()->cellScalar(timeStep, resultIndex, i, j, k); + if (resultValue == HUGE_VAL) + { + resultValue = undefinedValue; + } + + resultData.push_back(resultValue); + } + } + } + + writeDataToTextFile(&file, eclipseKeyWord, resultData); + + return true; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RifEclipseInputFileTools::writeDataToTextFile(QFile* file, const QString& eclipseKeyWord, const std::vector& resultData) +{ + QTextStream out(file); + out << "\n"; + out << "-- Exported from ResInsight" << "\n"; + out << eclipseKeyWord << "\n" << right << qSetFieldWidth(16); + + caf::ProgressInfo pi(resultData.size(), QString("Writing data to file %1").arg(file->fileName()) ); + int progressSteps = resultData.size() / 20; + + size_t i; + for (i = 0; i < resultData.size(); i++) + { + out << resultData[i]; + + if ( (i + 1) % 5 == 0) + { + out << "\n"; + } + + if (i % progressSteps == 0) + { + pi.setProgress(i); + } + } + + out << "\n" << "/" << "\n"; +} diff --git a/ApplicationCode/FileInterface/RifEclipseInputFileTools.h b/ApplicationCode/FileInterface/RifEclipseInputFileTools.h new file mode 100644 index 0000000000..4767358f7c --- /dev/null +++ b/ApplicationCode/FileInterface/RifEclipseInputFileTools.h @@ -0,0 +1,55 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cvfBase.h" +#include "cvfObject.h" +#include "cvfLibCore.h" +#include + +class RigReservoir; +class QString; +class QFile; + +//================================================================================================== +// +// Class for access to Eclipse "keyword" files using libecl +// +//================================================================================================== +class RifEclipseInputFileTools : public cvf::Object +{ +public: + RifEclipseInputFileTools(); + virtual ~RifEclipseInputFileTools(); + + static bool openGridFile(const QString& fileName, RigReservoir* reservoir); + + // Returns map of assigned resultName and Eclipse Keyword. + static std::map readProperties(const QString& fileName, RigReservoir* reservoir); + static bool readProperty (const QString& fileName, RigReservoir* reservoir, const QString& eclipseKeyWord, const QString& resultName ); + static std::vector findKeywordsOnFile(const QString &fileName); + + static const std::vector& knownPropertyKeywords(); + + static bool writePropertyToTextFile(const QString& fileName, RigReservoir* reservoir, size_t timeStep, const QString& resultName, const QString& eclipseKeyWord); + static bool writeBinaryResultToTextFile(const QString& fileName, RigReservoir* reservoir, size_t timeStep, const QString& resultName, const QString& eclipseKeyWord, const double undefinedValue); + +private: + static void writeDataToTextFile(QFile* file, const QString& eclipseKeyWord, const std::vector& resultData); +}; diff --git a/ApplicationCode/FileInterface/RifReaderEclipseFileAccess.cpp b/ApplicationCode/FileInterface/RifEclipseOutputFileTools.cpp similarity index 90% rename from ApplicationCode/FileInterface/RifReaderEclipseFileAccess.cpp rename to ApplicationCode/FileInterface/RifEclipseOutputFileTools.cpp index 6531b2c1d6..696198fbb3 100644 --- a/ApplicationCode/FileInterface/RifReaderEclipseFileAccess.cpp +++ b/ApplicationCode/FileInterface/RifEclipseOutputFileTools.cpp @@ -16,9 +16,10 @@ // ///////////////////////////////////////////////////////////////////////////////// -#include "RifReaderEclipseFileAccess.h" +#include "RifEclipseOutputFileTools.h" #ifdef USE_ECL_LIB +#include "util.h" #include "ecl_file.h" #include "ecl_intehead.h" #endif //USE_ECL_LIB @@ -28,7 +29,7 @@ //-------------------------------------------------------------------------------------------------- /// Constructor //-------------------------------------------------------------------------------------------------- -RifReaderEclipseFileAccess::RifReaderEclipseFileAccess() +RifEclipseOutputFileTools::RifEclipseOutputFileTools() { #ifdef USE_ECL_LIB m_file = NULL; @@ -39,7 +40,7 @@ RifReaderEclipseFileAccess::RifReaderEclipseFileAccess() //-------------------------------------------------------------------------------------------------- /// Destructor //-------------------------------------------------------------------------------------------------- -RifReaderEclipseFileAccess::~RifReaderEclipseFileAccess() +RifEclipseOutputFileTools::~RifEclipseOutputFileTools() { close(); } @@ -48,7 +49,7 @@ RifReaderEclipseFileAccess::~RifReaderEclipseFileAccess() //-------------------------------------------------------------------------------------------------- /// Open file given by name //-------------------------------------------------------------------------------------------------- -bool RifReaderEclipseFileAccess::open(const QString& fileName) +bool RifEclipseOutputFileTools::open(const QString& fileName) { #ifdef USE_ECL_LIB // Close current file if any @@ -67,7 +68,7 @@ bool RifReaderEclipseFileAccess::open(const QString& fileName) //-------------------------------------------------------------------------------------------------- /// Close file //-------------------------------------------------------------------------------------------------- -void RifReaderEclipseFileAccess::close() +void RifEclipseOutputFileTools::close() { #ifdef USE_ECL_LIB if (m_file) @@ -82,7 +83,7 @@ void RifReaderEclipseFileAccess::close() //-------------------------------------------------------------------------------------------------- /// Get the number of occurrences of the given keyword //-------------------------------------------------------------------------------------------------- -size_t RifReaderEclipseFileAccess::numOccurrences(const QString& keyword) +size_t RifEclipseOutputFileTools::numOccurrences(const QString& keyword) { #ifdef USE_ECL_LIB CVF_ASSERT(m_file); @@ -97,7 +98,7 @@ size_t RifReaderEclipseFileAccess::numOccurrences(const QString& keyword) /// Get keywords found on file given by name. /// If numDataItems > -1, get keywords with that exact number of data items only. //-------------------------------------------------------------------------------------------------- -bool RifReaderEclipseFileAccess::keywordsOnFile(QStringList* keywords, size_t numDataItems, size_t numSteps) +bool RifEclipseOutputFileTools::keywordsOnFile(QStringList* keywords, size_t numDataItems, size_t numSteps) { #ifdef USE_ECL_LIB CVF_ASSERT(m_file); @@ -159,7 +160,7 @@ bool RifReaderEclipseFileAccess::keywordsOnFile(QStringList* keywords, size_t nu //-------------------------------------------------------------------------------------------------- /// Get list of time step texts (dates) //-------------------------------------------------------------------------------------------------- -bool RifReaderEclipseFileAccess::timeStepsText(QStringList* timeSteps) +bool RifEclipseOutputFileTools::timeStepsText(QStringList* timeSteps) { #ifdef USE_ECL_LIB CVF_ASSERT(timeSteps); @@ -208,7 +209,7 @@ bool RifReaderEclipseFileAccess::timeStepsText(QStringList* timeSteps) //-------------------------------------------------------------------------------------------------- /// Get list of time step texts (dates) //-------------------------------------------------------------------------------------------------- -bool RifReaderEclipseFileAccess::timeSteps(QList* timeSteps) +bool RifEclipseOutputFileTools::timeSteps(QList* timeSteps) { #ifdef USE_ECL_LIB CVF_ASSERT(timeSteps); @@ -256,7 +257,7 @@ bool RifReaderEclipseFileAccess::timeSteps(QList* timeSteps) //-------------------------------------------------------------------------------------------------- /// Get first occurrence of file of given type in given list of filenames, as filename or NULL if not found //-------------------------------------------------------------------------------------------------- -bool RifReaderEclipseFileAccess::keywordData(const QString& keyword, size_t index, std::vector* values) +bool RifEclipseOutputFileTools::keywordData(const QString& keyword, size_t index, std::vector* values) { #ifdef USE_ECL_LIB CVF_ASSERT(m_file); @@ -285,7 +286,7 @@ bool RifReaderEclipseFileAccess::keywordData(const QString& keyword, size_t inde /// Get first occurrence of file of given type in given list of filenames, as filename or NULL if not found //-------------------------------------------------------------------------------------------------- #ifdef USE_ECL_LIB -QString RifReaderEclipseFileAccess::fileNameByType(const QStringList& fileSet, ecl_file_enum fileType) +QString RifEclipseOutputFileTools::fileNameByType(const QStringList& fileSet, ecl_file_enum fileType) { int i; for (i = 0; i < fileSet.count(); i++) @@ -307,7 +308,7 @@ QString RifReaderEclipseFileAccess::fileNameByType(const QStringList& fileSet, e /// Get all files of file of given type in given list of filenames, as filename or NULL if not found //-------------------------------------------------------------------------------------------------- #ifdef USE_ECL_LIB -QStringList RifReaderEclipseFileAccess::fileNamesByType(const QStringList& fileSet, ecl_file_enum fileType) +QStringList RifEclipseOutputFileTools::fileNamesByType(const QStringList& fileSet, ecl_file_enum fileType) { QStringList fileNames; @@ -330,13 +331,14 @@ QStringList RifReaderEclipseFileAccess::fileNamesByType(const QStringList& fileS //-------------------------------------------------------------------------------------------------- /// Get set of Eclipse files based on an input file and its path //-------------------------------------------------------------------------------------------------- -bool RifReaderEclipseFileAccess::fileSet(const QString& fileName, QStringList* fileSet) +bool RifEclipseOutputFileTools::fileSet(const QString& fileName, QStringList* fileSet) { CVF_ASSERT(fileSet); fileSet->clear(); #ifdef USE_ECL_LIB - QString filePath = QFileInfo(fileName).path(); + QString filePath = QFileInfo(fileName).absoluteFilePath(); + filePath = QFileInfo(filePath).path(); QString fileNameBase = QFileInfo(fileName).baseName(); stringlist_type* eclipseFiles = stringlist_alloc_new(); @@ -358,7 +360,7 @@ bool RifReaderEclipseFileAccess::fileSet(const QString& fileName, QStringList* f /// //-------------------------------------------------------------------------------------------------- #ifdef USE_ECL_LIB -ecl_file_type* RifReaderEclipseFileAccess::filePointer() +ecl_file_type* RifEclipseOutputFileTools::filePointer() { return m_file; } diff --git a/ApplicationCode/FileInterface/RifReaderEclipseFileAccess.h b/ApplicationCode/FileInterface/RifEclipseOutputFileTools.h similarity index 94% rename from ApplicationCode/FileInterface/RifReaderEclipseFileAccess.h rename to ApplicationCode/FileInterface/RifEclipseOutputFileTools.h index 237757bae1..d28aac0b4c 100644 --- a/ApplicationCode/FileInterface/RifReaderEclipseFileAccess.h +++ b/ApplicationCode/FileInterface/RifEclipseOutputFileTools.h @@ -35,11 +35,11 @@ // Class for access to Eclipse "keyword" files using libecl // //================================================================================================== -class RifReaderEclipseFileAccess : public cvf::Object +class RifEclipseOutputFileTools : public cvf::Object { public: - RifReaderEclipseFileAccess(); - virtual ~RifReaderEclipseFileAccess(); + RifEclipseOutputFileTools(); + virtual ~RifEclipseOutputFileTools(); bool open(const QString& fileName); void close(); diff --git a/ApplicationCode/FileInterface/RifReaderEclipseResultAccess.cpp b/ApplicationCode/FileInterface/RifEclipseRestartDataAccess.cpp similarity index 86% rename from ApplicationCode/FileInterface/RifReaderEclipseResultAccess.cpp rename to ApplicationCode/FileInterface/RifEclipseRestartDataAccess.cpp index 1906e7ef5b..1adbf3ea19 100644 --- a/ApplicationCode/FileInterface/RifReaderEclipseResultAccess.cpp +++ b/ApplicationCode/FileInterface/RifEclipseRestartDataAccess.cpp @@ -16,13 +16,13 @@ // ///////////////////////////////////////////////////////////////////////////////// -#include "RifReaderEclipseResultAccess.h" +#include "RifEclipseRestartDataAccess.h" //-------------------------------------------------------------------------------------------------- /// Constructor //-------------------------------------------------------------------------------------------------- -RifReaderEclipseResultsAccess::RifReaderEclipseResultsAccess(size_t numGrids, size_t numActiveCells) +RifEclipseRestartDataAccess::RifEclipseRestartDataAccess(size_t numGrids, size_t numActiveCells) { m_numGrids = numGrids; m_numActiveCells = numActiveCells; @@ -32,6 +32,6 @@ RifReaderEclipseResultsAccess::RifReaderEclipseResultsAccess(size_t numGrids, si //-------------------------------------------------------------------------------------------------- /// Destructor //-------------------------------------------------------------------------------------------------- -RifReaderEclipseResultsAccess::~RifReaderEclipseResultsAccess() +RifEclipseRestartDataAccess::~RifEclipseRestartDataAccess() { } diff --git a/ApplicationCode/FileInterface/RifReaderEclipseResultAccess.h b/ApplicationCode/FileInterface/RifEclipseRestartDataAccess.h similarity index 91% rename from ApplicationCode/FileInterface/RifReaderEclipseResultAccess.h rename to ApplicationCode/FileInterface/RifEclipseRestartDataAccess.h index f57d57fba2..8f2eec3f0a 100644 --- a/ApplicationCode/FileInterface/RifReaderEclipseResultAccess.h +++ b/ApplicationCode/FileInterface/RifEclipseRestartDataAccess.h @@ -36,11 +36,11 @@ // Abstract class for results access // //================================================================================================== -class RifReaderEclipseResultsAccess : public cvf::Object +class RifEclipseRestartDataAccess : public cvf::Object { public: - RifReaderEclipseResultsAccess(size_t numGrids, size_t numActiveCells); - virtual ~RifReaderEclipseResultsAccess(); + RifEclipseRestartDataAccess(size_t numGrids, size_t numActiveCells); + virtual ~RifEclipseRestartDataAccess(); virtual bool open(const QStringList& fileSet) = 0; virtual void close() = 0; diff --git a/ApplicationCode/FileInterface/RifReaderEclipseRestartFiles.cpp b/ApplicationCode/FileInterface/RifEclipseRestartFilesetAccess.cpp similarity index 84% rename from ApplicationCode/FileInterface/RifReaderEclipseRestartFiles.cpp rename to ApplicationCode/FileInterface/RifEclipseRestartFilesetAccess.cpp index 1d70cc21b3..74e0a0d7b3 100644 --- a/ApplicationCode/FileInterface/RifReaderEclipseRestartFiles.cpp +++ b/ApplicationCode/FileInterface/RifEclipseRestartFilesetAccess.cpp @@ -16,22 +16,22 @@ // ///////////////////////////////////////////////////////////////////////////////// -#include "RifReaderEclipseRestartFiles.h" -#include "RifReaderEclipseFileAccess.h" +#include "RifEclipseRestartFilesetAccess.h" +#include "RifEclipseOutputFileTools.h" //-------------------------------------------------------------------------------------------------- /// Constructor //-------------------------------------------------------------------------------------------------- -RifReaderEclipseRestartFiles::RifReaderEclipseRestartFiles(size_t numGrids, size_t numActiveCells) - : RifReaderEclipseResultsAccess(numGrids, numActiveCells) +RifEclipseRestartFilesetAccess::RifEclipseRestartFilesetAccess(size_t numGrids, size_t numActiveCells) + : RifEclipseRestartDataAccess(numGrids, numActiveCells) { } //-------------------------------------------------------------------------------------------------- /// Destructor //-------------------------------------------------------------------------------------------------- -RifReaderEclipseRestartFiles::~RifReaderEclipseRestartFiles() +RifEclipseRestartFilesetAccess::~RifEclipseRestartFilesetAccess() { close(); } @@ -39,7 +39,7 @@ RifReaderEclipseRestartFiles::~RifReaderEclipseRestartFiles() //-------------------------------------------------------------------------------------------------- /// Open files //-------------------------------------------------------------------------------------------------- -bool RifReaderEclipseRestartFiles::open(const QStringList& fileSet) +bool RifEclipseRestartFilesetAccess::open(const QStringList& fileSet) { close(); @@ -47,7 +47,7 @@ bool RifReaderEclipseRestartFiles::open(const QStringList& fileSet) size_t i; for (i = 0; i < numFiles; i++) { - cvf::ref fileAccess = new RifReaderEclipseFileAccess; + cvf::ref fileAccess = new RifEclipseOutputFileTools; if (!fileAccess->open(fileSet[i])) { close(); @@ -63,7 +63,7 @@ bool RifReaderEclipseRestartFiles::open(const QStringList& fileSet) //-------------------------------------------------------------------------------------------------- /// Close files //-------------------------------------------------------------------------------------------------- -void RifReaderEclipseRestartFiles::close() +void RifEclipseRestartFilesetAccess::close() { m_files.clear(); } @@ -71,7 +71,7 @@ void RifReaderEclipseRestartFiles::close() //-------------------------------------------------------------------------------------------------- /// Get the number of time steps //-------------------------------------------------------------------------------------------------- -size_t RifReaderEclipseRestartFiles::numTimeSteps() +size_t RifEclipseRestartFilesetAccess::numTimeSteps() { return m_files.size(); } @@ -79,7 +79,7 @@ size_t RifReaderEclipseRestartFiles::numTimeSteps() //-------------------------------------------------------------------------------------------------- /// Get the time step texts //-------------------------------------------------------------------------------------------------- -QStringList RifReaderEclipseRestartFiles::timeStepsText() +QStringList RifEclipseRestartFilesetAccess::timeStepsText() { QStringList timeSteps; @@ -98,7 +98,7 @@ QStringList RifReaderEclipseRestartFiles::timeStepsText() //-------------------------------------------------------------------------------------------------- /// Get the time steps //-------------------------------------------------------------------------------------------------- -QList RifReaderEclipseRestartFiles::timeSteps() +QList RifEclipseRestartFilesetAccess::timeSteps() { QList timeSteps; @@ -125,7 +125,7 @@ QList RifReaderEclipseRestartFiles::timeSteps() //-------------------------------------------------------------------------------------------------- /// Get list of result names //-------------------------------------------------------------------------------------------------- -QStringList RifReaderEclipseRestartFiles::resultNames() +QStringList RifEclipseRestartFilesetAccess::resultNames() { CVF_ASSERT(numTimeSteps() > 0); @@ -139,7 +139,7 @@ QStringList RifReaderEclipseRestartFiles::resultNames() //-------------------------------------------------------------------------------------------------- /// Get result values for given time step //-------------------------------------------------------------------------------------------------- -bool RifReaderEclipseRestartFiles::results(const QString& resultName, size_t timeStep, std::vector* values) +bool RifEclipseRestartFilesetAccess::results(const QString& resultName, size_t timeStep, std::vector* values) { size_t numOccurrences = m_files[timeStep]->numOccurrences(resultName); CVF_ASSERT(m_numGrids == numOccurrences); @@ -164,7 +164,7 @@ bool RifReaderEclipseRestartFiles::results(const QString& resultName, size_t tim /// //-------------------------------------------------------------------------------------------------- #ifdef USE_ECL_LIB -void RifReaderEclipseRestartFiles::readWellData(well_info_type* well_info) +void RifEclipseRestartFilesetAccess::readWellData(well_info_type* well_info) { if (!well_info) return; diff --git a/ApplicationCode/FileInterface/RifReaderEclipseRestartFiles.h b/ApplicationCode/FileInterface/RifEclipseRestartFilesetAccess.h similarity index 82% rename from ApplicationCode/FileInterface/RifReaderEclipseRestartFiles.h rename to ApplicationCode/FileInterface/RifEclipseRestartFilesetAccess.h index 21240d8327..b92ce9aa91 100644 --- a/ApplicationCode/FileInterface/RifReaderEclipseRestartFiles.h +++ b/ApplicationCode/FileInterface/RifEclipseRestartFilesetAccess.h @@ -18,22 +18,22 @@ #pragma once -#include "RifReaderEclipseResultAccess.h" +#include "RifEclipseRestartDataAccess.h" #include -class RifReaderEclipseFileAccess; +class RifEclipseOutputFileTools; //================================================================================================== // // Class for access to results from a set of restart files // //================================================================================================== -class RifReaderEclipseRestartFiles : public RifReaderEclipseResultsAccess +class RifEclipseRestartFilesetAccess : public RifEclipseRestartDataAccess { public: - RifReaderEclipseRestartFiles(size_t numGrids, size_t numActiveCells); - virtual ~RifReaderEclipseRestartFiles(); + RifEclipseRestartFilesetAccess(size_t numGrids, size_t numActiveCells); + virtual ~RifEclipseRestartFilesetAccess(); bool open(const QStringList& fileSet); void close(); @@ -50,5 +50,5 @@ public: #endif //USE_ECL_LIB private: - std::vector< cvf::ref > m_files; + std::vector< cvf::ref > m_files; }; diff --git a/ApplicationCode/FileInterface/RifReaderEclipseUnifiedRestartFile.cpp b/ApplicationCode/FileInterface/RifEclipseUnifiedRestartFileAccess.cpp similarity index 82% rename from ApplicationCode/FileInterface/RifReaderEclipseUnifiedRestartFile.cpp rename to ApplicationCode/FileInterface/RifEclipseUnifiedRestartFileAccess.cpp index 789c61e015..05130e70c6 100644 --- a/ApplicationCode/FileInterface/RifReaderEclipseUnifiedRestartFile.cpp +++ b/ApplicationCode/FileInterface/RifEclipseUnifiedRestartFileAccess.cpp @@ -16,8 +16,8 @@ // ///////////////////////////////////////////////////////////////////////////////// -#include "RifReaderEclipseUnifiedRestartFile.h" -#include "RifReaderEclipseFileAccess.h" +#include "RifEclipseUnifiedRestartFileAccess.h" +#include "RifEclipseOutputFileTools.h" #ifdef USE_ECL_LIB #include @@ -29,15 +29,15 @@ //-------------------------------------------------------------------------------------------------- /// Constructor //-------------------------------------------------------------------------------------------------- -RifReaderEclipseUnifiedRestartFile::RifReaderEclipseUnifiedRestartFile(size_t numGrids, size_t numActiveCells) - : RifReaderEclipseResultsAccess(numGrids, numActiveCells) +RifEclipseUnifiedRestartFileAccess::RifEclipseUnifiedRestartFileAccess(size_t numGrids, size_t numActiveCells) + : RifEclipseRestartDataAccess(numGrids, numActiveCells) { } //-------------------------------------------------------------------------------------------------- /// Destructor //-------------------------------------------------------------------------------------------------- -RifReaderEclipseUnifiedRestartFile::~RifReaderEclipseUnifiedRestartFile() +RifEclipseUnifiedRestartFileAccess::~RifEclipseUnifiedRestartFileAccess() { close(); } @@ -45,12 +45,12 @@ RifReaderEclipseUnifiedRestartFile::~RifReaderEclipseUnifiedRestartFile() //-------------------------------------------------------------------------------------------------- /// Open file //-------------------------------------------------------------------------------------------------- -bool RifReaderEclipseUnifiedRestartFile::open(const QStringList& fileSet) +bool RifEclipseUnifiedRestartFileAccess::open(const QStringList& fileSet) { #ifdef USE_ECL_LIB QString fileName = fileSet[0]; - cvf::ref fileAccess = new RifReaderEclipseFileAccess; + cvf::ref fileAccess = new RifEclipseOutputFileTools; if (!fileAccess->open(fileName)) { return false; @@ -67,7 +67,7 @@ bool RifReaderEclipseUnifiedRestartFile::open(const QStringList& fileSet) //-------------------------------------------------------------------------------------------------- /// Close file //-------------------------------------------------------------------------------------------------- -void RifReaderEclipseUnifiedRestartFile::close() +void RifEclipseUnifiedRestartFileAccess::close() { if (m_file.notNull()) { @@ -79,7 +79,7 @@ void RifReaderEclipseUnifiedRestartFile::close() //-------------------------------------------------------------------------------------------------- /// Get the number of time steps //-------------------------------------------------------------------------------------------------- -size_t RifReaderEclipseUnifiedRestartFile::numTimeSteps() +size_t RifEclipseUnifiedRestartFileAccess::numTimeSteps() { QStringList timeSteps = timeStepsText(); return timeSteps.size(); @@ -88,9 +88,9 @@ size_t RifReaderEclipseUnifiedRestartFile::numTimeSteps() //-------------------------------------------------------------------------------------------------- /// Get the time step texts //-------------------------------------------------------------------------------------------------- -QStringList RifReaderEclipseUnifiedRestartFile::timeStepsText() +QStringList RifEclipseUnifiedRestartFileAccess::timeStepsText() { - RifReaderEclipseFileAccess* file = m_file.p(); + RifEclipseOutputFileTools* file = m_file.p(); CVF_ASSERT(file != NULL); QStringList timeSteps; @@ -102,9 +102,9 @@ QStringList RifReaderEclipseUnifiedRestartFile::timeStepsText() //-------------------------------------------------------------------------------------------------- /// Get the time steps //-------------------------------------------------------------------------------------------------- -QList RifReaderEclipseUnifiedRestartFile::timeSteps() +QList RifEclipseUnifiedRestartFileAccess::timeSteps() { - RifReaderEclipseFileAccess* file = m_file.p(); + RifEclipseOutputFileTools* file = m_file.p(); CVF_ASSERT(file != NULL); QList timeSteps; @@ -116,7 +116,7 @@ QList RifReaderEclipseUnifiedRestartFile::timeSteps() //-------------------------------------------------------------------------------------------------- /// Get list of result names //-------------------------------------------------------------------------------------------------- -QStringList RifReaderEclipseUnifiedRestartFile::resultNames() +QStringList RifEclipseUnifiedRestartFileAccess::resultNames() { // Get the results found on the UNRST file QStringList resultsList; @@ -128,7 +128,7 @@ QStringList RifReaderEclipseUnifiedRestartFile::resultNames() //-------------------------------------------------------------------------------------------------- /// Get result values for given time step //-------------------------------------------------------------------------------------------------- -bool RifReaderEclipseUnifiedRestartFile::results(const QString& resultName, size_t timeStep, std::vector* values) +bool RifEclipseUnifiedRestartFileAccess::results(const QString& resultName, size_t timeStep, std::vector* values) { size_t numOccurrences = m_file->numOccurrences(resultName); size_t startIndex = timeStep*m_numGrids; @@ -154,7 +154,7 @@ bool RifReaderEclipseUnifiedRestartFile::results(const QString& resultName, size /// //-------------------------------------------------------------------------------------------------- #ifdef USE_ECL_LIB -void RifReaderEclipseUnifiedRestartFile::readWellData(well_info_type* well_info) +void RifEclipseUnifiedRestartFileAccess::readWellData(well_info_type* well_info) { if (!well_info) return; diff --git a/ApplicationCode/FileInterface/RifReaderEclipseUnifiedRestartFile.h b/ApplicationCode/FileInterface/RifEclipseUnifiedRestartFileAccess.h similarity index 84% rename from ApplicationCode/FileInterface/RifReaderEclipseUnifiedRestartFile.h rename to ApplicationCode/FileInterface/RifEclipseUnifiedRestartFileAccess.h index e96887d16d..5047feeda3 100644 --- a/ApplicationCode/FileInterface/RifReaderEclipseUnifiedRestartFile.h +++ b/ApplicationCode/FileInterface/RifEclipseUnifiedRestartFileAccess.h @@ -18,9 +18,9 @@ #pragma once -#include "RifReaderEclipseResultAccess.h" +#include "RifEclipseRestartDataAccess.h" -class RifReaderEclipseFileAccess; +class RifEclipseOutputFileTools; #ifdef USE_ECL_LIB #include "well_info.h" @@ -31,11 +31,11 @@ class RifReaderEclipseFileAccess; // Class for access to results from a unified restart file // //================================================================================================== -class RifReaderEclipseUnifiedRestartFile : public RifReaderEclipseResultsAccess +class RifEclipseUnifiedRestartFileAccess : public RifEclipseRestartDataAccess { public: - RifReaderEclipseUnifiedRestartFile(size_t numGrids, size_t numActiveCells); - virtual ~RifReaderEclipseUnifiedRestartFile(); + RifEclipseUnifiedRestartFileAccess(size_t numGrids, size_t numActiveCells); + virtual ~RifEclipseUnifiedRestartFileAccess(); bool open(const QStringList& fileSet); void close(); @@ -52,5 +52,5 @@ public: #endif private: - cvf::ref m_file; + cvf::ref m_file; }; diff --git a/ApplicationCode/FileInterface/RifReaderEclipseInput.cpp b/ApplicationCode/FileInterface/RifReaderEclipseInput.cpp new file mode 100644 index 0000000000..3f0f63d9dd --- /dev/null +++ b/ApplicationCode/FileInterface/RifReaderEclipseInput.cpp @@ -0,0 +1,95 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "cvfBase.h" + +#include "RigMainGrid.h" +#include "RigReservoir.h" +#include "RigReservoirCellResults.h" + +#include "RifReaderEclipseInput.h" +#include "RifReaderEclipseOutput.h" + +#include "RifEclipseInputFileTools.h" + +#include +#include + +#ifdef USE_ECL_LIB +#include "ecl_grid.h" +#include "well_state.h" +#endif //USE_ECL_LIB +#include "util.h" + +//================================================================================================== +// +// Class RifReaderEclipseInput +// +//================================================================================================== + +//-------------------------------------------------------------------------------------------------- +/// Constructor +//-------------------------------------------------------------------------------------------------- +RifReaderEclipseInput::RifReaderEclipseInput() +{ +} + +//-------------------------------------------------------------------------------------------------- +/// Destructor +//-------------------------------------------------------------------------------------------------- +RifReaderEclipseInput::~RifReaderEclipseInput() +{ +} + +//-------------------------------------------------------------------------------------------------- +/// Open file and read geometry into given reservoir object +//-------------------------------------------------------------------------------------------------- +bool RifReaderEclipseInput::open(const QString& fileName, RigReservoir* reservoir) +{ + CVF_ASSERT(reservoir); + + // Make sure everything's closed + close(); + + // Should we handle gridless properties ? + // If so, they must match dimentions, and a grid afterwards must match dimension + + // Add file: + // Open file + // If we do not have any grid data, + // Search for grid keywords + // If grid data found + // Read grid keywords, + // produce ecl_grid, + // Transfer data to RigReservoir + // if not + // find include + // else + // Search through file for property keywords + // If found, + // read them, + // create InputProperty object + + bool isOk = false; + if (reservoir->mainGrid()->gridPointDimensions() == cvf::Vec3st(0,0,0)) + { + isOk = RifEclipseInputFileTools::openGridFile(fileName, reservoir); + } + + return isOk; +} diff --git a/ApplicationCode/FileInterface/RifReaderEclipseInput.h b/ApplicationCode/FileInterface/RifReaderEclipseInput.h new file mode 100644 index 0000000000..8f245083a6 --- /dev/null +++ b/ApplicationCode/FileInterface/RifReaderEclipseInput.h @@ -0,0 +1,44 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "RifReaderInterface.h" + +//================================================================================================== +// +// File interface for Eclipse output files +// +//================================================================================================== +class RifReaderEclipseInput : public RifReaderInterface +{ +public: + RifReaderEclipseInput(); + virtual ~RifReaderEclipseInput(); + + // Virtual interface implementation + virtual bool open(const QString& fileName, RigReservoir* reservoir); + + + + virtual void close() {} + + virtual bool staticResult(const QString& result, std::vector* values) { return false; } + virtual bool dynamicResult(const QString& result, size_t stepIndex, std::vector* values) { return false; } + +}; diff --git a/ApplicationCode/FileInterface/RifReaderInterfaceEcl.cpp b/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp similarity index 81% rename from ApplicationCode/FileInterface/RifReaderInterfaceEcl.cpp rename to ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp index f48383793e..1ed3f9bd4d 100644 --- a/ApplicationCode/FileInterface/RifReaderInterfaceEcl.cpp +++ b/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp @@ -20,12 +20,12 @@ #include "RigMainGrid.h" #include "RigReservoir.h" +#include "RigReservoirCellResults.h" -#include "RifReaderInterfaceEcl.h" -#include "RifReaderEclipseFileAccess.h" -#include "RifReaderEclipseUnifiedRestartFile.h" -#include "RifReaderEclipseRestartFiles.h" - +#include "RifReaderEclipseOutput.h" +#include "RifEclipseOutputFileTools.h" +#include "RifEclipseUnifiedRestartFileAccess.h" +#include "RifEclipseRestartFilesetAccess.h" #include @@ -33,6 +33,7 @@ #include "ecl_grid.h" #include "well_state.h" #endif //USE_ECL_LIB +#include "cafProgressInfo.h" //-------------------------------------------------------------------------------------------------- /// ECLIPSE cell numbering layout: @@ -85,7 +86,7 @@ static const size_t cellMappingECLRi[8] = { 0, 1, 3, 2, 4, 5, 7, 6 }; //************************************************************************************************** #ifdef USE_ECL_LIB -bool transferGridCellData(RigMainGrid* mainGrid, RigGridBase* localGrid, ecl_grid_type* localEclGrid, size_t activeStartIndex) +bool transferGridCellData(RigMainGrid* mainGrid, RigGridBase* localGrid, const ecl_grid_type* localEclGrid, size_t activeStartIndex) { int cellCount = ecl_grid_get_global_size(localEclGrid); size_t cellStartIndex = mainGrid->cells().size(); @@ -97,6 +98,8 @@ bool transferGridCellData(RigMainGrid* mainGrid, RigGridBase* localGrid, ecl_gri mainGrid->nodes().resize(nodeStartIndex + cellCount*8, cvf::Vec3d(0,0,0)); + caf::ProgressInfo progInfo(cellCount, ""); + size_t computedCellCount = 0; // Loop over cells and fill them with data #pragma omp parallel for @@ -142,7 +145,14 @@ bool transferGridCellData(RigMainGrid* mainGrid, RigGridBase* localGrid, ecl_gri CVF_ASSERT(subGridFileIndex > 0); cell.setSubGrid(static_cast(mainGrid->gridByIndex(subGridFileIndex))); } + +#pragma omp atomic + computedCellCount++; + + if (computedCellCount%5000 < 20) + progInfo.setProgress(computedCellCount); } + return true; } #endif @@ -155,7 +165,7 @@ bool transferGridCellData(RigMainGrid* mainGrid, RigGridBase* localGrid, ecl_gri //-------------------------------------------------------------------------------------------------- /// Constructor //-------------------------------------------------------------------------------------------------- -RifReaderInterfaceECL::RifReaderInterfaceECL() +RifReaderEclipseOutput::RifReaderEclipseOutput() { ground(); } @@ -163,30 +173,26 @@ RifReaderInterfaceECL::RifReaderInterfaceECL() //-------------------------------------------------------------------------------------------------- /// Destructor //-------------------------------------------------------------------------------------------------- -RifReaderInterfaceECL::~RifReaderInterfaceECL() +RifReaderEclipseOutput::~RifReaderEclipseOutput() { } //-------------------------------------------------------------------------------------------------- /// Ground members //-------------------------------------------------------------------------------------------------- -void RifReaderInterfaceECL::ground() +void RifReaderEclipseOutput::ground() { m_fileName.clear(); m_fileSet.clear(); - m_staticResults.clear(); - m_dynamicResults.clear(); - m_timeStepTexts.clear(); m_timeSteps.clear(); - m_numGrids = 0; } //-------------------------------------------------------------------------------------------------- /// Close interface (for now, no files are kept open after calling methods, so just clear members) //-------------------------------------------------------------------------------------------------- -void RifReaderInterfaceECL::close() +void RifReaderEclipseOutput::close() { m_staticResultsAccess = NULL; m_dynamicResultsAccess = NULL; @@ -197,12 +203,12 @@ void RifReaderInterfaceECL::close() //-------------------------------------------------------------------------------------------------- /// Read geometry from file given by name into given reservoir object //-------------------------------------------------------------------------------------------------- -bool RifReaderInterfaceECL::readGeometry(const QString& filename, RigReservoir* reservoir) +bool RifReaderEclipseOutput::transferGeometry(const ecl_grid_type* mainEclGrid, RigReservoir* reservoir) { CVF_ASSERT(reservoir); #ifdef USE_ECL_LIB - ecl_grid_type * mainEclGrid = ecl_grid_alloc( filename.toAscii().data() ); + if (!mainEclGrid) { // Some error @@ -249,22 +255,25 @@ bool RifReaderInterfaceECL::readGeometry(const QString& filename, RigReservoir* mainGrid->cells().reserve(totalCellCount); mainGrid->nodes().reserve(8*totalCellCount); + caf::ProgressInfo progInfo(1 + numLGRs, ""); + progInfo.setProgressDescription("Main Grid"); + transferGridCellData(mainGrid, mainGrid, mainEclGrid, 0); + progInfo.setProgress(1); + size_t globalActiveSize = ecl_grid_get_active_size(mainEclGrid); for (lgrIdx = 0; lgrIdx < numLGRs; ++lgrIdx) { + progInfo.setProgressDescription("LGR number " + QString::number(lgrIdx+1)); + ecl_grid_type* localEclGrid = ecl_grid_iget_lgr(mainEclGrid, lgrIdx); transferGridCellData(mainGrid, static_cast(mainGrid->gridByIndex(lgrIdx+1)), localEclGrid, globalActiveSize); globalActiveSize += ecl_grid_get_active_size(localEclGrid); + progInfo.setProgress(1 + lgrIdx); } - ecl_grid_free( mainEclGrid ); - - // !! Maybe this should set somewhere else, in a method that builds meta data !! - m_numGrids = numLGRs + 1; - #endif return true; @@ -274,60 +283,93 @@ bool RifReaderInterfaceECL::readGeometry(const QString& filename, RigReservoir* //-------------------------------------------------------------------------------------------------- /// Open file and read geometry into given reservoir object //-------------------------------------------------------------------------------------------------- -bool RifReaderInterfaceECL::open(const QString& fileName, RigReservoir* reservoir) +bool RifReaderEclipseOutput::open(const QString& fileName, RigReservoir* reservoir) { CVF_ASSERT(reservoir); + caf::ProgressInfo progInfo(4, ""); + + progInfo.setProgressDescription("Reading Grid"); // Make sure everything's closed close(); // Get set of files QStringList fileSet; - if (!RifReaderEclipseFileAccess::fileSet(fileName, &fileSet)) return false; + if (!RifEclipseOutputFileTools::fileSet(fileName, &fileSet)) return false; + // Keep the set of files of interest m_fileSet = fileSet; // Read geometry - if (!readGeometry(fileName, reservoir)) return false; +#ifdef USE_ECL_LIB + ecl_grid_type * mainEclGrid = ecl_grid_alloc( fileName.toAscii().data() ); + + progInfo.setProgress(1); + progInfo.setProgressDescription("Transferring grid geometry"); + + if (!transferGeometry(mainEclGrid, reservoir)) return false; + + ecl_grid_free( mainEclGrid ); + + progInfo.setProgress(2); + progInfo.setProgressDescription("Reading Result index"); + +#endif // Build results meta data if (!buildMetaData(reservoir)) return false; + progInfo.setProgress(3); + progInfo.setProgressDescription("Reading Well information"); + readWellCells(reservoir); - + return true; } //-------------------------------------------------------------------------------------------------- /// Build meta data - get states and results info //-------------------------------------------------------------------------------------------------- -bool RifReaderInterfaceECL::buildMetaData(RigReservoir* reservoir) +bool RifReaderEclipseOutput::buildMetaData(RigReservoir* reservoir) { #ifdef USE_ECL_LIB CVF_ASSERT(reservoir); CVF_ASSERT(m_fileSet.size() > 0); + caf::ProgressInfo progInfo(2,""); + // Get the number of active cells in the grid size_t numActiveCells = reservoir->mainGrid()->numActiveCells(); + size_t numGrids = reservoir->mainGrid()->gridCount(); // Create access object for dynamic results - m_dynamicResultsAccess = dynamicResultsAccess(m_fileSet, m_numGrids, numActiveCells); + m_dynamicResultsAccess = dynamicResultsAccess(m_fileSet, numGrids, numActiveCells); + + RigReservoirCellResults* resCellResults = reservoir->mainGrid()->results(); + if (m_dynamicResultsAccess.notNull()) { - // Get time steps texts - m_timeStepTexts = m_dynamicResultsAccess->timeStepsText(); + // Get time steps m_timeSteps = m_dynamicResultsAccess->timeSteps(); // Get the names of the dynamic results - m_dynamicResults = m_dynamicResultsAccess->resultNames(); + QStringList dynamicResultNames = m_dynamicResultsAccess->resultNames(); + + for (size_t i = 0; i < static_cast(dynamicResultNames.size()); ++i) + { + size_t resIndex = resCellResults->addEmptyScalarResult(RimDefines::DYNAMIC_NATIVE, dynamicResultNames[i]); + resCellResults->setTimeStepDates(resIndex, m_timeSteps); + } } - QString initFileName = RifReaderEclipseFileAccess::fileNameByType(m_fileSet, ECL_INIT_FILE); + progInfo.setProgress(1); + + QString initFileName = RifEclipseOutputFileTools::fileNameByType(m_fileSet, ECL_INIT_FILE); if (initFileName.size() > 0) { // Open init file - cvf::ref initFile = new RifReaderEclipseFileAccess; + cvf::ref initFile = new RifEclipseOutputFileTools; if (!initFile->open(initFileName)) { return false; @@ -336,7 +378,15 @@ bool RifReaderInterfaceECL::buildMetaData(RigReservoir* reservoir) // Get the names of the static results QStringList staticResults; initFile->keywordsOnFile(&staticResults, numActiveCells); - m_staticResults = staticResults; + QStringList staticResultNames = staticResults; + + QList staticDate; + staticDate.push_back(m_timeSteps.front()); + for (size_t i = 0; i < static_cast(staticResultNames.size()); ++i) + { + size_t resIndex = resCellResults->addEmptyScalarResult(RimDefines::STATIC_NATIVE, staticResultNames[i]); + resCellResults->setTimeStepDates(resIndex, staticDate); + } m_staticResultsAccess = initFile; } @@ -350,16 +400,16 @@ bool RifReaderInterfaceECL::buildMetaData(RigReservoir* reservoir) //-------------------------------------------------------------------------------------------------- /// Create results access object (.UNRST or .X0001 ... .XNNNN) //-------------------------------------------------------------------------------------------------- -RifReaderEclipseResultsAccess* RifReaderInterfaceECL::dynamicResultsAccess(const QStringList& fileSet, size_t numGrids, size_t numActiveCells) +RifEclipseRestartDataAccess* RifReaderEclipseOutput::dynamicResultsAccess(const QStringList& fileSet, size_t numGrids, size_t numActiveCells) { - RifReaderEclipseResultsAccess* resultsAccess = NULL; + RifEclipseRestartDataAccess* resultsAccess = NULL; #ifdef USE_ECL_LIB // Look for unified restart file - QString unrstFileName = RifReaderEclipseFileAccess::fileNameByType(fileSet, ECL_UNIFIED_RESTART_FILE); + QString unrstFileName = RifEclipseOutputFileTools::fileNameByType(fileSet, ECL_UNIFIED_RESTART_FILE); if (unrstFileName.size() > 0) { - resultsAccess = new RifReaderEclipseUnifiedRestartFile(numGrids, numActiveCells); + resultsAccess = new RifEclipseUnifiedRestartFileAccess(numGrids, numActiveCells); if (!resultsAccess->open(QStringList(unrstFileName))) { delete resultsAccess; @@ -369,10 +419,10 @@ RifReaderEclipseResultsAccess* RifReaderInterfaceECL::dynamicResultsAccess(const else { // Look for set of restart files (one file per time step) - QStringList restartFiles = RifReaderEclipseFileAccess::fileNamesByType(fileSet, ECL_RESTART_FILE); + QStringList restartFiles = RifEclipseOutputFileTools::fileNamesByType(fileSet, ECL_RESTART_FILE); if (restartFiles.size() > 0) { - resultsAccess = new RifReaderEclipseRestartFiles(numGrids, numActiveCells); + resultsAccess = new RifEclipseRestartFilesetAccess(numGrids, numActiveCells); if (!resultsAccess->open(restartFiles)) { delete resultsAccess; @@ -388,34 +438,10 @@ RifReaderEclipseResultsAccess* RifReaderInterfaceECL::dynamicResultsAccess(const return resultsAccess; } -//-------------------------------------------------------------------------------------------------- -/// Get the names of all static results -//-------------------------------------------------------------------------------------------------- -const QStringList& RifReaderInterfaceECL::staticResults() const -{ - return m_staticResults; -} - -//-------------------------------------------------------------------------------------------------- -/// Get the names of all dynamic results -//-------------------------------------------------------------------------------------------------- -const QStringList& RifReaderInterfaceECL::dynamicResults() const -{ - return m_dynamicResults; -} - -//-------------------------------------------------------------------------------------------------- -/// Get the number of time steps -//-------------------------------------------------------------------------------------------------- -size_t RifReaderInterfaceECL::numTimeSteps() const -{ - return m_timeStepTexts.size(); -} - //-------------------------------------------------------------------------------------------------- /// Get all values of a given static result as doubles //-------------------------------------------------------------------------------------------------- -bool RifReaderInterfaceECL::staticResult(const QString& result, std::vector* values) +bool RifReaderEclipseOutput::staticResult(const QString& result, std::vector* values) { CVF_ASSERT(values); CVF_ASSERT(m_staticResultsAccess.notNull()); @@ -435,24 +461,16 @@ bool RifReaderInterfaceECL::staticResult(const QString& result, std::vector* values) +bool RifReaderEclipseOutput::dynamicResult(const QString& result, size_t stepIndex, std::vector* values) { CVF_ASSERT(m_dynamicResultsAccess.notNull()); return m_dynamicResultsAccess->results(result, stepIndex, values); } -//-------------------------------------------------------------------------------------------------- -/// Get list of time step texts -//-------------------------------------------------------------------------------------------------- -const QStringList& RifReaderInterfaceECL::timeStepText() const -{ - return m_timeStepTexts; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -const QList& RifReaderInterfaceECL::timeSteps() const +const QList& RifReaderEclipseOutput::timeSteps() const { return m_timeSteps; } @@ -460,7 +478,7 @@ const QList& RifReaderInterfaceECL::timeSteps() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RifReaderInterfaceECL::readWellCells(RigReservoir* reservoir) +void RifReaderEclipseOutput::readWellCells(RigReservoir* reservoir) { CVF_ASSERT(reservoir); @@ -500,7 +518,7 @@ void RifReaderInterfaceECL::readWellCells(RigReservoir* reservoir) RigWellResultFrame& wellResFrame = wellResults->m_wellCellsTimeSteps[timeIdx]; // Build timestamp for well - // Also see RifReaderEclipseFileAccess::timeStepsText for accessing time_t structures + // Also see RifEclipseOutputFileAccess::timeStepsText for accessing time_t structures { time_t stepTime = well_state_get_sim_time(ert_well_state); wellResFrame.m_timestamp = QDateTime::fromTime_t(stepTime); @@ -586,7 +604,9 @@ void RifReaderInterfaceECL::readWellCells(RigReservoir* reservoir) RigWellResultCell& data = wellSegment.m_wellCells[existingConnCount + connIdx]; data.m_gridIndex = gridNr; data.m_gridCellIndex = grids[gridNr]->cellIndexFromIJK(ert_connection->i, ert_connection->j, ert_connection->k); - data.m_isOpen = ert_connection->open; + data.m_isOpen = ert_connection->open; + data.m_branchId = ert_connection->branch; + data.m_segmentId = ert_connection->segment; } } } diff --git a/ApplicationCode/FileInterface/RifReaderEclipseOutput.h b/ApplicationCode/FileInterface/RifReaderEclipseOutput.h new file mode 100644 index 0000000000..80a3c28e05 --- /dev/null +++ b/ApplicationCode/FileInterface/RifReaderEclipseOutput.h @@ -0,0 +1,69 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "RifReaderInterface.h" +#include +#include + +class RifEclipseOutputFileTools; +class RifEclipseRestartDataAccess; + +typedef struct ecl_grid_struct ecl_grid_type; + +//================================================================================================== +// +// File interface for Eclipse output files +// +//================================================================================================== +class RifReaderEclipseOutput : public RifReaderInterface +{ +public: + RifReaderEclipseOutput(); + virtual ~RifReaderEclipseOutput(); + + bool open(const QString& fileName, RigReservoir* reservoir); + void close(); + + const QList& timeSteps() const; + + bool staticResult(const QString& result, std::vector* values); + bool dynamicResult(const QString& result, size_t stepIndex, std::vector* values); + +#ifdef USE_ECL_LIB + static bool transferGeometry(const ecl_grid_type* mainEclGrid, RigReservoir* reservoir); +#endif + +private: + void ground(); + bool buildMetaData(RigReservoir* reservoir); + void readWellCells(RigReservoir* reservoir); + + static RifEclipseRestartDataAccess* staticResultsAccess(const QStringList& fileSet, size_t numGrids, size_t numActiveCells); + static RifEclipseRestartDataAccess* dynamicResultsAccess(const QStringList& fileSet, size_t numGrids, size_t numActiveCells); + +private: + QString m_fileName; // Name of file used to start accessing Eclipse output files + QStringList m_fileSet; // Set of files in filename's path with same base name as filename + + QList m_timeSteps; + + cvf::ref m_staticResultsAccess; // File access to static results + cvf::ref m_dynamicResultsAccess; // File access to dynamic results +}; diff --git a/ApplicationCode/FileInterface/RifReaderInterface.h b/ApplicationCode/FileInterface/RifReaderInterface.h index 0ec084e61e..8c1311124d 100644 --- a/ApplicationCode/FileInterface/RifReaderInterface.h +++ b/ApplicationCode/FileInterface/RifReaderInterface.h @@ -41,12 +41,9 @@ public: virtual bool open(const QString& fileName, RigReservoir* reservoir) = 0; virtual void close() = 0; - - virtual const QStringList& staticResults() const = 0; - virtual const QStringList& dynamicResults() const = 0; - virtual size_t numTimeSteps() const = 0; - virtual const QStringList& timeStepText() const = 0; + virtual bool staticResult(const QString& result, std::vector* values) = 0; virtual bool dynamicResult(const QString& result, size_t stepIndex, std::vector* values) = 0; + }; diff --git a/ApplicationCode/FileInterface/RifReaderInterfaceEcl.h b/ApplicationCode/FileInterface/RifReaderInterfaceEcl.h deleted file mode 100644 index 4f4d112bd1..0000000000 --- a/ApplicationCode/FileInterface/RifReaderInterfaceEcl.h +++ /dev/null @@ -1,70 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS -// -// ResInsight is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. -// -// See the GNU General Public License at -// for more details. -// -///////////////////////////////////////////////////////////////////////////////// - -#pragma once - -#include "RifReaderInterface.h" - -class RifReaderEclipseFileAccess; -class RifReaderEclipseResultsAccess; - -//================================================================================================== -// -// File interface for Eclipse output files -// -//================================================================================================== -class RifReaderInterfaceECL : public RifReaderInterface -{ -public: - RifReaderInterfaceECL(); - virtual ~RifReaderInterfaceECL(); - - bool open(const QString& fileName, RigReservoir* reservoir); - void close(); - - const QStringList& staticResults() const; - const QStringList& dynamicResults() const; - - size_t numTimeSteps() const; - const QStringList& timeStepText() const; - const QList& timeSteps() const; - - bool staticResult(const QString& result, std::vector* values); - bool dynamicResult(const QString& result, size_t stepIndex, std::vector* values); - -private: - void ground(); - bool buildMetaData(RigReservoir* reservoir); - bool readGeometry(const QString& fileName, RigReservoir* reservoir); - void readWellCells(RigReservoir* reservoir); - - static RifReaderEclipseResultsAccess* staticResultsAccess(const QStringList& fileSet, size_t numGrids, size_t numActiveCells); - static RifReaderEclipseResultsAccess* dynamicResultsAccess(const QStringList& fileSet, size_t numGrids, size_t numActiveCells); - -private: - QString m_fileName; // Name of file used to start accessing Eclipse output files - QStringList m_fileSet; // Set of files in filename's path with same base name as filename - QStringList m_staticResults; // List of names of static results - QStringList m_dynamicResults; // List of names of dynamic results - QStringList m_timeStepTexts; // List of time step infos (dates) - QList m_timeSteps; - size_t m_numGrids; // Total number of grids (main grid and all sub grids) - - cvf::ref m_staticResultsAccess; // File access to static results - cvf::ref m_dynamicResultsAccess; // File access to dynamic results -}; diff --git a/ApplicationCode/FileInterface/RifReaderInterfaceMock.h b/ApplicationCode/FileInterface/RifReaderInterfaceMock.h deleted file mode 100644 index 0866e31c80..0000000000 --- a/ApplicationCode/FileInterface/RifReaderInterfaceMock.h +++ /dev/null @@ -1,58 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS -// -// ResInsight is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. -// -// See the GNU General Public License at -// for more details. -// -///////////////////////////////////////////////////////////////////////////////// - -#pragma once - -#include "RifReaderInterface.h" -#include "RigReservoirBuilderMock.h" - -class RifReaderInterfaceMock : public RifReaderInterface -{ -public: - RifReaderInterfaceMock(); - virtual ~RifReaderInterfaceMock(); - - void setWorldCoordinates(cvf::Vec3d minWorldCoordinate, cvf::Vec3d maxWorldCoordinate); - void setGridPointDimensions(const cvf::Vec3st& gridPointDimensions); - void setResultInfo(size_t resultCount, size_t timeStepCount); - - void addLocalGridRefinement(const cvf::Vec3st& minCellPosition, const cvf::Vec3st& maxCellPosition, const cvf::Vec3st& singleCellRefinementFactors); - - - virtual bool open( const QString& fileName, RigReservoir* reservoir ); - virtual void close(); - virtual const QStringList& staticResults() const; - virtual const QStringList& dynamicResults() const; - virtual size_t numTimeSteps() const; - const QStringList& timeStepText() const; - - virtual bool staticResult( const QString& result, std::vector* values ); - virtual bool dynamicResult( const QString& result, size_t stepIndex, std::vector* values ); - -private: - void populateReservoir(RigReservoir* reservoir); - - QStringList m_staticResults; - QStringList m_dynamicResults; - QStringList m_timeStepTexts; - - RigReservoirBuilderMock m_reservoirBuilder; - - cvf::ref m_reservoir; -}; - diff --git a/ApplicationCode/FileInterface/RifReaderInterfaceMock.cpp b/ApplicationCode/FileInterface/RifReaderMockModel.cpp similarity index 61% rename from ApplicationCode/FileInterface/RifReaderInterfaceMock.cpp rename to ApplicationCode/FileInterface/RifReaderMockModel.cpp index f787f72602..8a31fb1a41 100644 --- a/ApplicationCode/FileInterface/RifReaderInterfaceMock.cpp +++ b/ApplicationCode/FileInterface/RifReaderMockModel.cpp @@ -18,28 +18,39 @@ #include "RIStdInclude.h" -#include "RifReaderInterfaceMock.h" +#include "RifReaderMockModel.h" +#include "RigReservoirCellResults.h" //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RifReaderInterfaceMock::open(const QString& fileName, RigReservoir* reservoir) +bool RifReaderMockModel::open(const QString& fileName, RigReservoir* reservoir) { m_reservoirBuilder.populateReservoir(reservoir); m_reservoir = reservoir; - m_dynamicResults.clear(); - m_staticResults.clear(); - m_timeStepTexts.clear(); + RigReservoirCellResults* cellResults = reservoir->mainGrid()->results(); - size_t i; - for (i = 0; i < m_reservoirBuilder.resultCount(); i++) + + QList dates; + + for (size_t i = 0; i < m_reservoirBuilder.timeStepCount(); i++) { - m_dynamicResults.push_back(QString("Dynamic_Result_%1").arg(i)); + dates.push_back(QDateTime(QDate(2012+i, 6, 1))); } - for (i = 0; i < m_reservoirBuilder.resultCount(); i++) + for (size_t i = 0; i < m_reservoirBuilder.resultCount(); i++) + { + size_t resIdx = cellResults->addEmptyScalarResult(RimDefines::DYNAMIC_NATIVE, QString("Dynamic_Result_%1").arg(i)); + cellResults->setTimeStepDates(resIdx, dates); + } + + if (m_reservoirBuilder.timeStepCount() == 0) return true; + + QList staticDates; + staticDates.push_back(dates[0]); + for (size_t i = 0; i < m_reservoirBuilder.resultCount(); i++) { QString varEnd; if (i == 0) varEnd = "X"; @@ -47,54 +58,50 @@ bool RifReaderInterfaceMock::open(const QString& fileName, RigReservoir* reservo int resIndex = 0; if (i > 1) resIndex = i; - m_staticResults.push_back(QString("Static_Result_%1%2").arg(resIndex).arg(varEnd)); + size_t resIdx = cellResults->addEmptyScalarResult(RimDefines::STATIC_NATIVE, QString("Static_Result_%1%2").arg(resIndex).arg(varEnd)); + cellResults->setTimeStepDates(resIdx, staticDates); } - for (i = 0; i < m_reservoirBuilder.timeStepCount(); i++) - { - m_timeStepTexts.push_back(QString("Timestep %1").arg(i)); + +#define ADD_INPUT_PROPERTY(Name) \ + { \ + size_t resIdx; \ + QString resultName(Name); \ + resIdx = cellResults->addEmptyScalarResult(RimDefines::INPUT_PROPERTY, resultName); \ + cellResults->setTimeStepDates(resIdx, staticDates); \ + cellResults->cellScalarResults(resIdx).resize(1); \ + std::vector& values = cellResults->cellScalarResults(resIdx)[0]; \ + this->inputProperty(resultName, &values); \ } + ADD_INPUT_PROPERTY("PORO"); + ADD_INPUT_PROPERTY("PERM"); + ADD_INPUT_PROPERTY("MULTX"); + return true; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RifReaderInterfaceMock::close() +void RifReaderMockModel::close() { } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RifReaderMockModel::inputProperty(const QString& propertyName, std::vector* values) +{ + return m_reservoirBuilder.inputProperty(m_reservoir.p(), propertyName, values); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -const QStringList& RifReaderInterfaceMock::staticResults() const -{ - - return m_staticResults; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -const QStringList& RifReaderInterfaceMock::dynamicResults() const -{ - return m_dynamicResults; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -size_t RifReaderInterfaceMock::numTimeSteps() const -{ - return m_reservoirBuilder.timeStepCount(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RifReaderInterfaceMock::staticResult(const QString& result, std::vector* values) +bool RifReaderMockModel::staticResult(const QString& result, std::vector* values) { m_reservoirBuilder.staticResult(m_reservoir.p(), result, values); @@ -104,7 +111,7 @@ bool RifReaderInterfaceMock::staticResult(const QString& result, std::vector* values) +bool RifReaderMockModel::dynamicResult(const QString& result, size_t stepIndex, std::vector* values) { m_reservoirBuilder.dynamicResult(m_reservoir.p(), result, stepIndex, values); @@ -114,7 +121,7 @@ bool RifReaderInterfaceMock::dynamicResult(const QString& result, size_t stepInd //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RifReaderInterfaceMock::RifReaderInterfaceMock() +RifReaderMockModel::RifReaderMockModel() { /* m_cellResults.push_back("Dummy results"); @@ -122,7 +129,7 @@ RifReaderInterfaceMock::RifReaderInterfaceMock() */ } -RifReaderInterfaceMock::~RifReaderInterfaceMock() +RifReaderMockModel::~RifReaderMockModel() { } @@ -130,7 +137,7 @@ RifReaderInterfaceMock::~RifReaderInterfaceMock() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RifReaderInterfaceMock::setWorldCoordinates(cvf::Vec3d minWorldCoordinate, cvf::Vec3d maxWorldCoordinate) +void RifReaderMockModel::setWorldCoordinates(cvf::Vec3d minWorldCoordinate, cvf::Vec3d maxWorldCoordinate) { m_reservoirBuilder.setWorldCoordinates(minWorldCoordinate, maxWorldCoordinate); } @@ -138,7 +145,7 @@ void RifReaderInterfaceMock::setWorldCoordinates(cvf::Vec3d minWorldCoordinate, //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RifReaderInterfaceMock::setGridPointDimensions(const cvf::Vec3st& gridPointDimensions) +void RifReaderMockModel::setGridPointDimensions(const cvf::Vec3st& gridPointDimensions) { m_reservoirBuilder.setGridPointDimensions(gridPointDimensions); } @@ -146,7 +153,7 @@ void RifReaderInterfaceMock::setGridPointDimensions(const cvf::Vec3st& gridPoint //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RifReaderInterfaceMock::setResultInfo(size_t resultCount, size_t timeStepCount) +void RifReaderMockModel::setResultInfo(size_t resultCount, size_t timeStepCount) { m_reservoirBuilder.setResultInfo(resultCount, timeStepCount); } @@ -154,7 +161,7 @@ void RifReaderInterfaceMock::setResultInfo(size_t resultCount, size_t timeStepCo //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RifReaderInterfaceMock::addLocalGridRefinement(const cvf::Vec3st& minCellPosition, const cvf::Vec3st& maxCellPosition, const cvf::Vec3st& singleCellRefinementFactors) +void RifReaderMockModel::addLocalGridRefinement(const cvf::Vec3st& minCellPosition, const cvf::Vec3st& maxCellPosition, const cvf::Vec3st& singleCellRefinementFactors) { m_reservoirBuilder.addLocalGridRefinement(minCellPosition, maxCellPosition, singleCellRefinementFactors); } @@ -162,17 +169,8 @@ void RifReaderInterfaceMock::addLocalGridRefinement(const cvf::Vec3st& minCellPo //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RifReaderInterfaceMock::populateReservoir(RigReservoir* reservoir) +void RifReaderMockModel::populateReservoir(RigReservoir* reservoir) { m_reservoirBuilder.populateReservoir(reservoir); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -const QStringList& RifReaderInterfaceMock::timeStepText() const -{ - return m_timeStepTexts; -} - - diff --git a/ApplicationCode/FileInterface/RifReaderMockModel.h b/ApplicationCode/FileInterface/RifReaderMockModel.h new file mode 100644 index 0000000000..75a3581fa6 --- /dev/null +++ b/ApplicationCode/FileInterface/RifReaderMockModel.h @@ -0,0 +1,49 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "RifReaderInterface.h" +#include "RigReservoirBuilderMock.h" + +class RifReaderMockModel : public RifReaderInterface +{ +public: + RifReaderMockModel(); + virtual ~RifReaderMockModel(); + + void setWorldCoordinates(cvf::Vec3d minWorldCoordinate, cvf::Vec3d maxWorldCoordinate); + void setGridPointDimensions(const cvf::Vec3st& gridPointDimensions); + void setResultInfo(size_t resultCount, size_t timeStepCount); + + void addLocalGridRefinement(const cvf::Vec3st& minCellPosition, const cvf::Vec3st& maxCellPosition, const cvf::Vec3st& singleCellRefinementFactors); + + virtual bool open( const QString& fileName, RigReservoir* reservoir ); + virtual void close(); + + virtual bool staticResult( const QString& result, std::vector* values ); + virtual bool dynamicResult( const QString& result, size_t stepIndex, std::vector* values ); + +private: + void populateReservoir(RigReservoir* reservoir); + bool inputProperty( const QString& propertyName, std::vector* values ); + + RigReservoirBuilderMock m_reservoirBuilder; + cvf::ref m_reservoir; +}; + diff --git a/ApplicationCode/ModelVisualization/RivCellEdgeEffectGenerator.cpp b/ApplicationCode/ModelVisualization/RivCellEdgeEffectGenerator.cpp index e7844e29e6..3b8d6f6d10 100644 --- a/ApplicationCode/ModelVisualization/RivCellEdgeEffectGenerator.cpp +++ b/ApplicationCode/ModelVisualization/RivCellEdgeEffectGenerator.cpp @@ -88,7 +88,10 @@ void RivCellEdgeGeometryGenerator::addCellEdgeResultsToDrawableGeo( CVF_ASSERT(grid != NULL); const std::vector< double >* cellScalarResults = NULL; + bool cellScalarResultUseGlobalActiveIndex = true; + const std::vector< double >* edgeScalarResults[6] = {NULL, NULL, NULL, NULL, NULL, NULL}; + bool edgeScalarResultUseGlobalActiveIndex[6]; if (cellResultSlot->hasResult()) { @@ -101,6 +104,8 @@ void RivCellEdgeGeometryGenerator::addCellEdgeResultsToDrawableGeo( { cellScalarResults = &scalarResultTimeSteps[0]; } + + cellScalarResultUseGlobalActiveIndex = grid->mainGrid()->results()->isUsingGlobalActiveIndex(cellResultSlot->gridScalarIndex()); } size_t resultIndices[6]; @@ -115,6 +120,7 @@ void RivCellEdgeGeometryGenerator::addCellEdgeResultsToDrawableGeo( { const std::vector< std::vector >& scalarResultTimeSteps = grid->mainGrid()->results()->cellScalarResults(resultIndices[cubeFaceIdx]); edgeScalarResults[cubeFaceIdx] = &scalarResultTimeSteps[0]; // Assuming only static edge results + edgeScalarResultUseGlobalActiveIndex[cubeFaceIdx] = grid->mainGrid()->results()->isUsingGlobalActiveIndex(resultIndices[cubeFaceIdx]); } } } @@ -136,7 +142,12 @@ void RivCellEdgeGeometryGenerator::addCellEdgeResultsToDrawableGeo( float cellColorTextureCoord = 0.5f; // If no results exists, the texture will have a special color size_t cellIndex = quadToCell[quadIdx]; - size_t resultIndex = grid->cell(cellIndex).globalActiveIndex(); + + size_t resultIndex = cellIndex; + if (cellScalarResultUseGlobalActiveIndex) + { + resultIndex = grid->cell(cellIndex).globalActiveIndex(); + } if (cellScalarResults ) { @@ -163,6 +174,12 @@ void RivCellEdgeGeometryGenerator::addCellEdgeResultsToDrawableGeo( { edgeColor = -1.0f; // Undefined texture coord. Shader handles this. + resultIndex = cellIndex; + if (edgeScalarResultUseGlobalActiveIndex[cubeFaceIdx]) + { + resultIndex = grid->cell(cellIndex).globalActiveIndex(); + } + if (resultIndices[cubeFaceIdx] != cvf::UNDEFINED_SIZE_T && resultIndex != cvf::UNDEFINED_SIZE_T) { double scalarValue = (*(edgeScalarResults[cubeFaceIdx]))[resultIndex]; diff --git a/ApplicationCode/ModelVisualization/RivReservoirPipesPartMgr.cpp b/ApplicationCode/ModelVisualization/RivReservoirPipesPartMgr.cpp index 8df065d805..4767910b98 100644 --- a/ApplicationCode/ModelVisualization/RivReservoirPipesPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivReservoirPipesPartMgr.cpp @@ -22,6 +22,7 @@ #include "RimReservoirView.h" #include "RimWellCollection.h" #include "RivWellPipesPartMgr.h" +#include "RivWellHeadPartMgr.h" //-------------------------------------------------------------------------------------------------- @@ -52,7 +53,7 @@ void RivReservoirPipesPartMgr::appendDynamicGeometryPartsToModel(cvf::ModelBasic if (m_reservoirView->wellCollection()->wells.size() != m_wellPipesPartMgrs.size()) { m_wellPipesPartMgrs.clear(); - m_wellPipesPartMgrs.clear(); + m_wellHeadPartMgrs.clear(); for (size_t i = 0; i < m_reservoirView->wellCollection()->wells.size(); ++i) { diff --git a/ApplicationCode/ModelVisualization/RivReservoirPipesPartMgr.h b/ApplicationCode/ModelVisualization/RivReservoirPipesPartMgr.h index 5f3f00b6f7..ce6209af96 100644 --- a/ApplicationCode/ModelVisualization/RivReservoirPipesPartMgr.h +++ b/ApplicationCode/ModelVisualization/RivReservoirPipesPartMgr.h @@ -22,10 +22,10 @@ #include "cvfCollection.h" -#include "RivWellHeadPartMgr.h" class RimReservoirView; class RivWellPipesPartMgr; +class RivWellHeadPartMgr; class RivReservoirPipesPartMgr : public cvf::Object { diff --git a/ApplicationCode/ModelVisualization/RivReservoirViewPartMgr.cpp b/ApplicationCode/ModelVisualization/RivReservoirViewPartMgr.cpp index 11ba090ffa..67c47e01c3 100644 --- a/ApplicationCode/ModelVisualization/RivReservoirViewPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivReservoirViewPartMgr.cpp @@ -601,17 +601,23 @@ void RivReservoirViewPartMgr::computePropertyVisibility(cvf::UByteArray* cellVis } const RimCellFilter::FilterModeType filterType = (*pfIt)->filterMode(); + bool useGlobalActiveIndex = grid->mainGrid()->results()->isUsingGlobalActiveIndex((*pfIt)->resultDefinition->gridScalarIndex()); #pragma omp parallel for schedule(dynamic) for (int cellIndex = 0; cellIndex < static_cast(grid->cellCount()); cellIndex++) { if ( (*cellVisibility)[cellIndex] ) { - size_t resultIndex = grid->cell(cellIndex).globalActiveIndex(); - double value = HUGE_VAL; - if (resultIndex != cvf::UNDEFINED_SIZE_T) value = (*scalarResult)[resultIndex]; + size_t resultIndex = cellIndex; + if (useGlobalActiveIndex) + { + resultIndex = grid->cell(cellIndex).globalActiveIndex(); + } + + double scalarValue = HUGE_VAL; + if (resultIndex != cvf::UNDEFINED_SIZE_T) scalarValue = (*scalarResult)[resultIndex]; - if (lowerBound <= value && value <= upperBound) + if (lowerBound <= scalarValue && scalarValue <= upperBound) { if (filterType == RimCellFilter::EXCLUDE) { diff --git a/ApplicationCode/ModelVisualization/RivWellHeadPartMgr.cpp b/ApplicationCode/ModelVisualization/RivWellHeadPartMgr.cpp index fa9e001fa6..e9a3d1f594 100644 --- a/ApplicationCode/ModelVisualization/RivWellHeadPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivWellHeadPartMgr.cpp @@ -18,6 +18,8 @@ +#include "RivWellHeadPartMgr.h" + #include "cvfLibCore.h" #include "cvfModelBasicList.h" @@ -38,7 +40,6 @@ #include "RigCell.h" #include "RivPipeGeometryGenerator.h" -#include "RivWellHeadPartMgr.h" #include "RivWellPipesPartMgr.h" @@ -49,6 +50,8 @@ RivWellHeadPartMgr::RivWellHeadPartMgr(RimReservoirView* reservoirView, RimWell* { m_rimReservoirView = reservoirView; m_rimWell = well; + + m_font = new cvf::FixedAtlasFont(cvf::FixedAtlasFont::LARGE); } //-------------------------------------------------------------------------------------------------- @@ -110,7 +113,7 @@ void RivWellHeadPartMgr::buildWellHeadParts(size_t frameIndex) cvf::ref pipeGeomGenerator = new RivPipeGeometryGenerator; pipeGeomGenerator->setPipeCenterCoords(wellHeadPipeCoords.p()); pipeGeomGenerator->setPipeColor(well->wellPipeColor()); - pipeGeomGenerator->setCrossSectionVertexCount(12); + pipeGeomGenerator->setCrossSectionVertexCount(m_rimReservoirView->wellCollection()->pipeCrossSectionVertexCount()); double pipeRadius = m_rimReservoirView->wellCollection()->pipeRadiusScaleFactor() * m_rimWell->pipeRadiusScaleFactor() * characteristicCellSize; pipeGeomGenerator->setRadius(pipeRadius); @@ -121,6 +124,7 @@ void RivWellHeadPartMgr::buildWellHeadParts(size_t frameIndex) if (pipeSurface.notNull()) { cvf::ref part = new cvf::Part; + part->setName("RivWellHeadPartMgr: surface " + cvfqt::Utils::fromQString(well->name())); part->setDrawable(pipeSurface.p()); caf::SurfaceEffectGenerator surfaceGen(cvf::Color4f(well->wellPipeColor()), true); @@ -134,6 +138,7 @@ void RivWellHeadPartMgr::buildWellHeadParts(size_t frameIndex) if (centerLineDrawable.notNull()) { cvf::ref part = new cvf::Part; + part->setName("RivWellHeadPartMgr: centerline " + cvfqt::Utils::fromQString(well->name())); part->setDrawable(centerLineDrawable.p()); caf::MeshEffectGenerator meshGen(well->wellPipeColor()); @@ -172,6 +177,7 @@ void RivWellHeadPartMgr::buildWellHeadParts(size_t frameIndex) gen.setShaftRelativeRadius(0.5f); gen.setHeadRelativeRadius(1.0f); gen.setHeadRelativeLength(0.4f); + gen.setNumSlices(m_rimReservoirView->wellCollection()->pipeCrossSectionVertexCount()); gen.generate(&builder); cvf::ref vertices = builder.vertices(); @@ -193,6 +199,7 @@ void RivWellHeadPartMgr::buildWellHeadParts(size_t frameIndex) { cvf::ref part = new cvf::Part; + part->setName("RivWellHeadPartMgr: arrow " + cvfqt::Utils::fromQString(well->name())); part->setDrawable(geo1.p()); cvf::Color4f headColor(cvf::Color3::GRAY); @@ -226,7 +233,7 @@ void RivWellHeadPartMgr::buildWellHeadParts(size_t frameIndex) if (m_rimReservoirView->wellCollection()->showWellLabel() && well->showWellLabel()) { cvf::ref drawableText = new cvf::DrawableText; - drawableText->setFont(new cvf::FixedAtlasFont(cvf::FixedAtlasFont::LARGE)); + drawableText->setFont(m_font.p()); drawableText->setCheckPosVisible(false); drawableText->setDrawBorder(false); drawableText->setDrawBackground(false); @@ -239,6 +246,7 @@ void RivWellHeadPartMgr::buildWellHeadParts(size_t frameIndex) drawableText->addText(cvfString, textCoord); cvf::ref part = new cvf::Part; + part->setName("RivWellHeadPartMgr: text " + cvfString); part->setDrawable(drawableText.p()); cvf::ref eff = new cvf::Effect; diff --git a/ApplicationCode/ModelVisualization/RivWellHeadPartMgr.h b/ApplicationCode/ModelVisualization/RivWellHeadPartMgr.h index b2abea0152..8a593e45df 100644 --- a/ApplicationCode/ModelVisualization/RivWellHeadPartMgr.h +++ b/ApplicationCode/ModelVisualization/RivWellHeadPartMgr.h @@ -18,14 +18,22 @@ #pragma once +#include "cvfBase.h" +#include "cvfAssert.h" +#include "cvfObject.h" +#include "cafPdmPointer.h" +#include "cvfCollection.h" + namespace cvf { class Part; class ModelBasicList; class Transform; + class Font; } class RimWell; +class RimReservoirView; class RivWellHeadPartMgr : public cvf::Object { @@ -48,4 +56,6 @@ private: cvf::ref m_scaleTransform; cvf::Collection< cvf::Part > m_wellHeadParts; + + cvf::ref m_font; }; diff --git a/ApplicationCode/ModelVisualization/RivWellPipesPartMgr.cpp b/ApplicationCode/ModelVisualization/RivWellPipesPartMgr.cpp index cc42159082..924e3adbfa 100644 --- a/ApplicationCode/ModelVisualization/RivWellPipesPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivWellPipesPartMgr.cpp @@ -41,6 +41,26 @@ RivWellPipesPartMgr::RivWellPipesPartMgr(RimReservoirView* reservoirView, RimWel m_rimReservoirView = reservoirView; m_rimWell = well; m_needsTransformUpdate = true; + + // Setup a scalar mapper + cvf::ref scalarMapper = new cvf::ScalarMapperDiscreteLinear; + cvf::Color3ubArray legendColors; + legendColors.resize(4); + legendColors[0] = cvf::Color3::GRAY; + legendColors[1] = cvf::Color3::GREEN; + legendColors[2] = cvf::Color3::BLUE; + legendColors[3] = cvf::Color3::RED; + scalarMapper->setColors(legendColors); + scalarMapper->setRange(0.0 , 4.0); + scalarMapper->setLevelsFromColorCount(4); + + m_scalarMapper = scalarMapper; + + caf::ScalarMapperEffectGenerator surfEffGen(scalarMapper.p(), true); + m_scalarMapperSurfaceEffect = surfEffGen.generateEffect(); + + caf::ScalarMapperMeshEffectGenerator meshEffGen(scalarMapper.p()); + m_scalarMapperMeshEffect = meshEffGen.generateEffect(); } //-------------------------------------------------------------------------------------------------- @@ -62,25 +82,24 @@ void RivWellPipesPartMgr::buildWellPipeParts() std::vector< size_t > pipeBranchIds; std::vector< std::vector > pipeBranchesCLCoords; - std::vector< std::vector > pipeBranchesCellIds; + std::vector< std::vector > pipeBranchesCellIds; - calculateWellPipeCenterline( pipeBranchIds, pipeBranchesCLCoords, pipeBranchesCellIds); + calculateWellPipeCenterline(pipeBranchesCLCoords, pipeBranchesCellIds); double characteristicCellSize = m_rimReservoirView->eclipseCase()->reservoirData()->mainGrid()->characteristicCellSize(); double pipeRadius = m_rimReservoirView->wellCollection()->pipeRadiusScaleFactor() *m_rimWell->pipeRadiusScaleFactor() * characteristicCellSize; - for (size_t brIdx = 0; brIdx < pipeBranchIds.size(); ++brIdx) + for (size_t brIdx = 0; brIdx < pipeBranchesCellIds.size(); ++brIdx) { m_wellBranches.push_back(RivPipeBranchData()); RivPipeBranchData& pbd = m_wellBranches.back(); - pbd.m_branchId = pipeBranchIds[brIdx]; pbd.m_cellIds = pipeBranchesCellIds[brIdx]; pbd.m_pipeGeomGenerator = new RivPipeGeometryGenerator; pbd.m_pipeGeomGenerator->setRadius(pipeRadius); - pbd.m_pipeGeomGenerator->setCrossSectionVertexCount(12); + pbd.m_pipeGeomGenerator->setCrossSectionVertexCount(m_rimReservoirView->wellCollection()->pipeCrossSectionVertexCount()); pbd.m_pipeGeomGenerator->setPipeColor( m_rimWell->wellPipeColor()); cvf::ref cvfCoords = new cvf::Vec3dArray; @@ -131,12 +150,13 @@ void RivWellPipesPartMgr::buildWellPipeParts() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RivWellPipesPartMgr::calculateWellPipeCenterline( std::vector< size_t >& pipeBranchIds, - std::vector< std::vector >& pipeBranchesCLCoords, - std::vector< std::vector >& pipeBranchesCellIds) const +void RivWellPipesPartMgr::calculateWellPipeCenterline( std::vector< std::vector >& pipeBranchesCLCoords, + std::vector< std::vector >& pipeBranchesCellIds) const { CVF_ASSERT(m_rimWell.notNull()); CVF_ASSERT(m_rimReservoirView.notNull()); + + bool isAutoDetectBranches = m_rimReservoirView->wellCollection()->isAutoDetectingBranches(); RigReservoir* rigReservoir = m_rimReservoirView->eclipseCase()->reservoirData(); RigWellResults* wellResults = m_rimWell->wellResults(); @@ -151,7 +171,6 @@ void RivWellPipesPartMgr::calculateWellPipeCenterline( std::vector< size_t >& p if (staticWellFrame.m_wellResultBranches.size() == 0) return; // Initialize the return arrays - pipeBranchIds.clear(); pipeBranchesCLCoords.clear(); pipeBranchesCellIds.clear(); @@ -163,115 +182,134 @@ void RivWellPipesPartMgr::calculateWellPipeCenterline( std::vector< size_t >& p // Loop over all the well branches const std::vector& resBranches = staticWellFrame.m_wellResultBranches; - - for (size_t brIdx = 0; brIdx < resBranches.size(); brIdx++) + bool hasResultCells = false; + if (resBranches.size()) { - if (resBranches[brIdx].m_wellCells.size() == 0) continue; // Skip empty branches. Do not know why they exist, but they make problems. + for (size_t i = 0 ; i < resBranches.size(); ++i) + { + if (resBranches[i].m_wellCells.size() != 0) + { + hasResultCells = true; + } + } + } + + if (hasResultCells) + { + // Create a new branch from wellhead - // Create a new branch - pipeBranchIds.push_back(resBranches[brIdx].m_branchNumber); pipeBranchesCLCoords.push_back(std::vector()); - pipeBranchesCellIds.push_back(std::vector ()); - + pipeBranchesCellIds.push_back(std::vector ()); + // We start by entering the first cell (the wellhead) const RigWellResultCell* prevResCell = whResCell; + pipeBranchesCLCoords.back().push_back(whStartPos); - pipeBranchesCellIds.back().push_back(CellId(prevResCell->m_gridIndex, prevResCell->m_gridCellIndex)); + pipeBranchesCellIds.back().push_back(*prevResCell ); // Add extra coordinate between cell face and cell center // to make sure the well pipe terminated in a segment parallel to z-axis cvf::Vec3d whIntermediate = whStartPos; whIntermediate.z() = (whStartPos.z() + whCell.center().z()) / 2.0; + pipeBranchesCLCoords.back().push_back(whIntermediate); - pipeBranchesCellIds.back().push_back(CellId(prevResCell->m_gridIndex, prevResCell->m_gridCellIndex)); + pipeBranchesCellIds.back().push_back(*prevResCell ); - // Loop over all the resultCells in the branch - const std::vector& resBranchCells = resBranches[brIdx].m_wellCells; - - for (size_t cIdx = 0; cIdx < resBranchCells.size(); cIdx++) + for (size_t brIdx = 0; brIdx < resBranches.size(); brIdx++) { - std::vector& branchCLCoords = pipeBranchesCLCoords.back(); - std::vector& branchCellIds = pipeBranchesCellIds.back(); + if (resBranches[brIdx].m_wellCells.size() == 0) + continue; // Skip empty branches. Do not know why they exist, but they make problems. - const RigWellResultCell& resCell = resBranchCells[cIdx]; - const RigCell& cell = rigReservoir->cellFromWellResultCell(resCell); + // Loop over all the resultCells in the branch + const std::vector& resBranchCells = resBranches[brIdx].m_wellCells; - // Check if this and the previous cells has shared faces - - cvf::StructGridInterface::FaceType sharedFace; - if (rigReservoir->findSharedSourceFace(sharedFace, resCell, *prevResCell)) + for (int cIdx = 0; cIdx < static_cast(resBranchCells.size()); cIdx++) // Need int because cIdx can temporarily end on -1 { - branchCLCoords.push_back(cell.faceCenter(sharedFace)); - branchCellIds.push_back(CellId(resCell.m_gridIndex, resCell.m_gridCellIndex)); - } - else - { - // This and the previous cell does not share a face. We need to go out of the previous cell, before entering this. - const RigCell& prevCell = rigReservoir->cellFromWellResultCell(*prevResCell); - cvf::Vec3d centerPrevCell = prevCell.center(); - cvf::Vec3d centerThisCell = cell.center(); + std::vector& branchCLCoords = pipeBranchesCLCoords.back(); + std::vector& branchCellIds = pipeBranchesCellIds.back(); - // First make sure this cell is not starting a new "display" branch - if ( (prevResCell == whResCell) || (centerThisCell-centerPrevCell).lengthSquared() <= (centerThisCell - whStartPos).lengthSquared()) + const RigWellResultCell& resCell = resBranchCells[cIdx]; + const RigCell& cell = rigReservoir->cellFromWellResultCell(resCell); + + // Check if this and the previous cells has shared faces + + cvf::StructGridInterface::FaceType sharedFace; + if (rigReservoir->findSharedSourceFace(sharedFace, resCell, *prevResCell)) { - // Create ray and intersect with cells - - cvf::Ray rayToThisCell; - rayToThisCell.setOrigin(centerPrevCell); - rayToThisCell.setDirection((centerThisCell - centerPrevCell).getNormalized()); - - cvf::Vec3d outOfPrevCell(centerPrevCell); - cvf::Vec3d intoThisCell(centerThisCell); - - bool intersectionOk = prevCell.firstIntersectionPoint(rayToThisCell, &outOfPrevCell); - //CVF_ASSERT(intersectionOk); - intersectionOk = cell.firstIntersectionPoint(rayToThisCell, &intoThisCell); - //CVF_ASSERT(intersectionOk); - if ((intoThisCell - outOfPrevCell).lengthSquared() > 1e-3) - { - branchCLCoords.push_back(outOfPrevCell); - branchCellIds.push_back(CellId(cvf::UNDEFINED_SIZE_T, cvf::UNDEFINED_SIZE_T)); - } - branchCLCoords.push_back(intoThisCell); - branchCellIds.push_back(CellId(resCell.m_gridIndex, resCell.m_gridCellIndex)); + branchCLCoords.push_back(cell.faceCenter(sharedFace)); + branchCellIds.push_back(resCell); } else { - // This cell is further from the previous cell than from the well head, - // thus we interpret it as a new branch. + // This and the previous cell does not share a face. We need to go out of the previous cell, before entering this. + const RigCell& prevCell = rigReservoir->cellFromWellResultCell(*prevResCell); + cvf::Vec3d centerPrevCell = prevCell.center(); + cvf::Vec3d centerThisCell = cell.center(); - // First finish the current branch - branchCLCoords.push_back(branchCLCoords.back() + 1.5*(centerPrevCell - branchCLCoords.back()) ); + // First make sure this cell is not starting a new "display" branch + if ( !isAutoDetectBranches || (prevResCell == whResCell) + || (centerThisCell-centerPrevCell).lengthSquared() <= (centerThisCell - whStartPos).lengthSquared()) + { + // Not starting a "display" branch + // Create ray and intersect with cells - // Create new display branch - pipeBranchIds.push_back(resBranches[brIdx].m_branchNumber); - pipeBranchesCLCoords.push_back(std::vector()); - pipeBranchesCellIds.push_back(std::vector ()); + cvf::Ray rayToThisCell; + rayToThisCell.setOrigin(centerPrevCell); + rayToThisCell.setDirection((centerThisCell - centerPrevCell).getNormalized()); - // Start the new branch by entering the first cell (the wellhead) and intermediate - prevResCell = whResCell; - pipeBranchesCLCoords.back().push_back(whStartPos); - pipeBranchesCellIds.back().push_back(CellId(prevResCell->m_gridIndex, prevResCell->m_gridCellIndex)); + cvf::Vec3d outOfPrevCell(centerPrevCell); + cvf::Vec3d intoThisCell(centerThisCell); - // Include intermediate - pipeBranchesCLCoords.back().push_back(whIntermediate); - pipeBranchesCellIds.back().push_back(CellId(prevResCell->m_gridIndex, prevResCell->m_gridCellIndex)); + bool intersectionOk = prevCell.firstIntersectionPoint(rayToThisCell, &outOfPrevCell); + //CVF_ASSERT(intersectionOk); + intersectionOk = cell.firstIntersectionPoint(rayToThisCell, &intoThisCell); + //CVF_ASSERT(intersectionOk); + if ((intoThisCell - outOfPrevCell).lengthSquared() > 1e-3) + { + branchCLCoords.push_back(outOfPrevCell); + branchCellIds.push_back(RigWellResultCell()); + } + branchCLCoords.push_back(intoThisCell); + branchCellIds.push_back(resCell); + } + else + { + // This cell is further from the previous cell than from the well head, + // thus we interpret it as a new branch. - // Well now we need to step one back to take this cell again, but in the new branch. - cIdx--; - continue; + // First finish the current branch + branchCLCoords.push_back(branchCLCoords.back() + 1.5*(centerPrevCell - branchCLCoords.back()) ); + + // Create new display branch + pipeBranchesCLCoords.push_back(std::vector()); + pipeBranchesCellIds.push_back(std::vector ()); + + // Start the new branch by entering the first cell (the wellhead) and intermediate + prevResCell = whResCell; + pipeBranchesCLCoords.back().push_back(whStartPos); + pipeBranchesCellIds.back().push_back(*prevResCell); + + // Include intermediate + pipeBranchesCLCoords.back().push_back(whIntermediate); + pipeBranchesCellIds.back().push_back(*prevResCell); + + // Well now we need to step one back to take this cell again, but in the new branch. + cIdx--; + continue; + } } - } - prevResCell = &resCell; + prevResCell = &resCell; - // If we are looking at last cell, add the point 0.5 past the center of that cell - if (cIdx == resBranchCells.size() -1) - { - branchCLCoords.push_back(branchCLCoords.back() + 1.5*(cell.center() - branchCLCoords.back()) ); - } + } } + + // For the last cell, add the point 0.5 past the center of that cell + const RigCell& prevCell = rigReservoir->cellFromWellResultCell(*prevResCell); + cvf::Vec3d centerPrevCell = prevCell.center(); + pipeBranchesCLCoords.back().push_back(pipeBranchesCLCoords.back().back() + 1.5*(centerPrevCell - pipeBranchesCLCoords.back().back()) ); + } CVF_ASSERT(pipeBranchesCellIds.size() == pipeBranchesCLCoords.size()); @@ -324,18 +362,6 @@ void RivWellPipesPartMgr::updatePipeResultColor(size_t frameIndex) if (frameIndex < wRes->firstResultTimeStep()) return; // Or reset colors or something - // Setup a scalar mapper - cvf::ref scalarMapper = new cvf::ScalarMapperDiscreteLinear; - cvf::Color3ubArray legendColors; - legendColors.resize(4); - legendColors[0] = cvf::Color3::GRAY; - legendColors[1] = cvf::Color3::GREEN; - legendColors[2] = cvf::Color3::BLUE; - legendColors[3] = cvf::Color3::RED; - scalarMapper->setColors(legendColors); - scalarMapper->setRange(0.0 , 4.0); - scalarMapper->setLevelsFromColorCount(4); - const double closed = -0.1, producing = 1.5, water = 2.5, hcInjection = 3.5; // Closed set to -0.1 instead of 0.5 to workaround bug in the scalar mapper. std::list::iterator brIt; @@ -345,77 +371,48 @@ void RivWellPipesPartMgr::updatePipeResultColor(size_t frameIndex) for (brIt = m_wellBranches.begin(); brIt != m_wellBranches.end(); ++brIt) { - size_t branchId = brIt->m_branchId; - - // find corresponding result branch - size_t i; - for ( i = 0; i < wResFrame.m_wellResultBranches.size(); ++i) - { - if (wResFrame.m_wellResultBranches[i].m_branchNumber == branchId) break; - } - // Initialize well states to "closed" state wellCellStates.clear(); wellCellStates.resize(brIt->m_cellIds.size(), closed); - // Find result values - if (i >= wResFrame.m_wellResultBranches.size()) + const std::vector & cellIds = brIt->m_cellIds; + + for (size_t wcIdx = 0; wcIdx < cellIds.size(); ++wcIdx) { - // Branch not found in results. Do nothing. Keep the "closed" states - } - else - { - const std::vector& resBranch = wResFrame.m_wellResultBranches[i].m_wellCells; - const std::vector & cellIds = brIt->m_cellIds; + // we need a faster lookup, I guess + const RigWellResultCell* wResCell = wResFrame.findResultCell(cellIds[wcIdx].m_gridIndex, cellIds[wcIdx].m_gridCellIndex); - // Find cellIds[wcIdx] in resBranch - // ifFound then give color from cell state - // else give closed color - - // The search can be simplified to comparing the current element against - // the first unmatched element in the result branch vector since the result is (supposed) to be - // a subset of the complete branch where all elements have the same order - - size_t rcIdx = 0; // index to first unmatched element in results - for (size_t wcIdx = 0; wcIdx < cellIds.size(); ++wcIdx) + if (wResCell == NULL) { - if (rcIdx >= resBranch.size()) + // We cant find any state. This well cell is closed. + } + else + { + double cellState = closed; + + if (wResCell->m_isOpen) { - // We are beyond the result cells. This well cell is closed. - } - else - { - if ( cellIds[wcIdx].gridIndex == resBranch[rcIdx].m_gridIndex - && cellIds[wcIdx].cellIndex == resBranch[rcIdx].m_gridCellIndex) + switch (wResFrame.m_productionType) { - double cellState = closed; - - if (resBranch[rcIdx].m_isOpen) - { - switch (wResFrame.m_productionType) - { - case RigWellResultFrame::PRODUCER: - cellState = producing; - break; - case RigWellResultFrame::OIL_INJECTOR: - cellState = hcInjection; - break; - case RigWellResultFrame::GAS_INJECTOR: - cellState = hcInjection; - break; - case RigWellResultFrame::WATER_INJECTOR: - cellState = water; - break; - case RigWellResultFrame::UNDEFINED_PRODUCTION_TYPE: - cellState = closed; - break; - } - } - - wellCellStates[wcIdx] = cellState; - rcIdx++; + case RigWellResultFrame::PRODUCER: + cellState = producing; + break; + case RigWellResultFrame::OIL_INJECTOR: + cellState = hcInjection; + break; + case RigWellResultFrame::GAS_INJECTOR: + cellState = hcInjection; + break; + case RigWellResultFrame::WATER_INJECTOR: + cellState = water; + break; + case RigWellResultFrame::UNDEFINED_PRODUCTION_TYPE: + cellState = closed; + break; } } + + wellCellStates[wcIdx] = cellState; } } @@ -430,13 +427,10 @@ void RivWellPipesPartMgr::updatePipeResultColor(size_t frameIndex) surfTexCoords = new cvf::Vec2fArray; } - brIt->m_pipeGeomGenerator->pipeSurfaceTextureCoords( surfTexCoords.p(), wellCellStates, scalarMapper.p()); + brIt->m_pipeGeomGenerator->pipeSurfaceTextureCoords( surfTexCoords.p(), wellCellStates, m_scalarMapper.p()); brIt->m_surfaceDrawable->setTextureCoordArray( surfTexCoords.p()); - caf::ScalarMapperEffectGenerator surfEffGen(scalarMapper.p(), true); - cvf::ref seff = surfEffGen.generateEffect(); - - brIt->m_surfacePart->setEffect(seff.p()); + brIt->m_surfacePart->setEffect(m_scalarMapperSurfaceEffect.p()); } // Find or create texture coords array for pipe center line @@ -450,7 +444,7 @@ void RivWellPipesPartMgr::updatePipeResultColor(size_t frameIndex) } // Calculate new texture coordinates - brIt->m_pipeGeomGenerator->centerlineTextureCoords( lineTexCoords.p(), wellCellStates, scalarMapper.p()); + brIt->m_pipeGeomGenerator->centerlineTextureCoords( lineTexCoords.p(), wellCellStates, m_scalarMapper.p()); // Set the new texture coordinates @@ -458,10 +452,7 @@ void RivWellPipesPartMgr::updatePipeResultColor(size_t frameIndex) // Set effects - caf::ScalarMapperMeshEffectGenerator meshEffGen(scalarMapper.p()); - cvf::ref meff = meshEffGen.generateEffect(); - - brIt->m_centerLinePart->setEffect(meff.p()); + brIt->m_centerLinePart->setEffect(m_scalarMapperMeshEffect.p()); } } } diff --git a/ApplicationCode/ModelVisualization/RivWellPipesPartMgr.h b/ApplicationCode/ModelVisualization/RivWellPipesPartMgr.h index 21f2b58a26..f3fc473a50 100644 --- a/ApplicationCode/ModelVisualization/RivWellPipesPartMgr.h +++ b/ApplicationCode/ModelVisualization/RivWellPipesPartMgr.h @@ -20,12 +20,14 @@ #include "cafPdmPointer.h" #include +#include "RigWellResults.h" namespace cvf { class Part; class ModelBasicList; class Transform; + class Effect; } class RivPipeGeometryGenerator; @@ -54,33 +56,17 @@ private: bool m_needsTransformUpdate; void buildWellPipeParts(); - class CellId - { - public: - CellId() : - gridIndex(cvf::UNDEFINED_SIZE_T), - cellIndex(cvf::UNDEFINED_SIZE_T) - { } - - CellId(size_t gidx, size_t cIdx) : - gridIndex(gidx), - cellIndex(cIdx) - { } - - size_t gridIndex; - size_t cellIndex; - }; + //void calculateWellPipeCenterline(std::vector& coords) const; - void calculateWellPipeCenterline(std::vector< size_t >& pipeBranchIds, - std::vector< std::vector >& pipeBranchesCLCoords, - std::vector< std::vector >& pipeBranchesCellIds ) const; + void calculateWellPipeCenterline(std::vector< std::vector >& pipeBranchesCLCoords, + std::vector< std::vector >& pipeBranchesCellIds ) const; struct RivPipeBranchData { - size_t m_branchId; - std::vector m_cellIds; + std::vector m_cellIds; + //std::vector< std::vector > m_cellStatusPrFrame; cvf::ref m_pipeGeomGenerator; cvf::ref m_surfacePart; @@ -91,5 +77,8 @@ private: }; std::list m_wellBranches; - cvf::Collection< cvf::Part > m_wellPipeParts; + + cvf::ref m_scalarMapper; + cvf::ref m_scalarMapperSurfaceEffect; + cvf::ref m_scalarMapperMeshEffect; }; diff --git a/ApplicationCode/ProjectDataModel/RimBinaryExportSettings.cpp b/ApplicationCode/ProjectDataModel/RimBinaryExportSettings.cpp new file mode 100644 index 0000000000..0a59a198b2 --- /dev/null +++ b/ApplicationCode/ProjectDataModel/RimBinaryExportSettings.cpp @@ -0,0 +1,55 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RIStdInclude.h" + +#include "RimBinaryExportSettings.h" +#include "cafPdmUiFilePathEditor.h" + + +CAF_PDM_SOURCE_INIT(RimBinaryExportSettings, "RimBinaryExportSettings"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimBinaryExportSettings::RimBinaryExportSettings() +{ + CAF_PDM_InitObject("RimBinaryExportSettings", "", "", ""); + + CAF_PDM_InitFieldNoDefault(&fileName, "Filename", "Export filename", "", "", ""); + fileName.setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName()); + CAF_PDM_InitFieldNoDefault(&eclipseKeyword, "EclipseKeyword", "Eclipse Keyword", "", "", ""); + CAF_PDM_InitField(&undefinedValue, "UndefinedValue", 0.0, "Undefined value", "", "", ""); + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimBinaryExportSettings::defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute * attribute) +{ + if (field == &fileName) + { + caf::PdmUiFilePathEditorAttribute* myAttr = static_cast(attribute); + if (myAttr) + { + myAttr->m_selectSaveFileName = true; + } + } +} + diff --git a/ApplicationCode/ProjectDataModel/RimBinaryExportSettings.h b/ApplicationCode/ProjectDataModel/RimBinaryExportSettings.h new file mode 100644 index 0000000000..b5f85e4784 --- /dev/null +++ b/ApplicationCode/ProjectDataModel/RimBinaryExportSettings.h @@ -0,0 +1,42 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafPdmField.h" +#include "cafPdmObject.h" + + +//================================================================================================== +/// +/// +//================================================================================================== +class RimBinaryExportSettings : public caf::PdmObject +{ + CAF_PDM_HEADER_INIT; +public: + RimBinaryExportSettings(); + + caf::PdmField fileName; + caf::PdmField eclipseKeyword; + caf::PdmField undefinedValue; + +protected: + virtual void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute); +}; + diff --git a/ApplicationCode/ProjectDataModel/RimCalcScript.cpp b/ApplicationCode/ProjectDataModel/RimCalcScript.cpp index 703df957c6..b16fe12977 100644 --- a/ApplicationCode/ProjectDataModel/RimCalcScript.cpp +++ b/ApplicationCode/ProjectDataModel/RimCalcScript.cpp @@ -21,6 +21,7 @@ #include "cafPdmField.h" #include "RimCalcScript.h" +#include "cafPdmUiFilePathEditor.h" CAF_PDM_SOURCE_INIT(RimCalcScript, "CalcScript"); @@ -33,7 +34,9 @@ RimCalcScript::RimCalcScript() CAF_PDM_InitField(&absolutePath, "AbsolutePath", QString(), "Location", "", "" ,""); CAF_PDM_InitField(&content, "Content", QString(), "Directory", "", "" ,""); - content.setHidden(true); + content.setUiHidden(true); + + absolutePath.setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName()); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimCellEdgeResultSlot.cpp b/ApplicationCode/ProjectDataModel/RimCellEdgeResultSlot.cpp index 72b7f7fbff..dcdec17d2a 100644 --- a/ApplicationCode/ProjectDataModel/RimCellEdgeResultSlot.cpp +++ b/ApplicationCode/ProjectDataModel/RimCellEdgeResultSlot.cpp @@ -25,7 +25,8 @@ #include "RimReservoirView.h" #include "RigReservoirCellResults.h" #include "RigReservoir.h" -#include "RifReaderInterface.h" + +#include "cafPdmUiListEditor.h" CAF_PDM_SOURCE_INIT(RimCellEdgeResultSlot, "CellEdgeResultSlot"); @@ -37,9 +38,11 @@ RimCellEdgeResultSlot::RimCellEdgeResultSlot() { CAF_PDM_InitObject("Cell Edge Result", "", "", ""); - CAF_PDM_InitFieldNoDefault(&resultVariable, "CellEdgeVariable", "Result variable", ":/Default.png", "", ""); + CAF_PDM_InitFieldNoDefault(&resultVariable, "CellEdgeVariable", "Result variable", "", "", ""); CAF_PDM_InitFieldNoDefault(&legendConfig, "LegendDefinition", "Legend Definition", ":/Legend.png", "", ""); + resultVariable.setUiEditorTypeName(caf::PdmUiListEditor::uiEditorTypeName()); + legendConfig = new RimLegendConfig(); m_ignoredResultScalar = cvf::UNDEFINED_DOUBLE; @@ -68,13 +71,16 @@ void RimCellEdgeResultSlot::setReservoirView(RimReservoirView* ownerReservoirVie //-------------------------------------------------------------------------------------------------- void RimCellEdgeResultSlot::loadResult() { + CVF_ASSERT(m_reservoirView && m_reservoirView->gridCellResults()); + resetResultIndices(); QStringList vars = findResultVariableNames(); updateIgnoredScalarValue(); + int i; for (i = 0; i < vars.size(); ++i) { - size_t resultindex = gridCellResults()->loadResultIntoGrid(RimDefines::STATIC_NATIVE, vars[i]); + size_t resultindex = m_reservoirView->gridCellResults()->findOrLoadScalarResult(RimDefines::STATIC_NATIVE, vars[i]); int cubeFaceIdx; for (cubeFaceIdx = 0; cubeFaceIdx < 6; ++cubeFaceIdx) { @@ -124,10 +130,13 @@ QList RimCellEdgeResultSlot::calculateValueOptions(const { if (fieldNeedingOptions == &resultVariable) { - if (fileReaderinterface()) + if (m_reservoirView && m_reservoirView->gridCellResults()) { QStringList varList; - varList = fileReaderinterface()->staticResults(); + varList = m_reservoirView->gridCellResults()->resultNames(RimDefines::STATIC_NATIVE); + + //TODO: Must also handle input properties + //varList += m_reservoirView->gridCellResults()->resultNames(RimDefines::INPUT_PROPERTY); QList optionList; @@ -196,10 +205,12 @@ QStringList RimCellEdgeResultSlot::findResultVariableNames() { QStringList varNames; - if (fileReaderinterface() && !resultVariable().isEmpty()) + if (m_reservoirView && m_reservoirView->gridCellResults() && !resultVariable().isEmpty()) { QStringList varList; - varList = fileReaderinterface()->staticResults(); + varList = m_reservoirView->gridCellResults()->resultNames(RimDefines::STATIC_NATIVE); + //TODO: Must handle Input properties + int i; for (i = 0; i < varList.size(); ++i) { @@ -212,33 +223,7 @@ QStringList RimCellEdgeResultSlot::findResultVariableNames() return varNames; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RigReservoirCellResults* RimCellEdgeResultSlot::gridCellResults() -{ - CVF_ASSERT(m_reservoirView != NULL - && m_reservoirView->eclipseCase() - && m_reservoirView->eclipseCase()->reservoirData() - && m_reservoirView->eclipseCase()->reservoirData()->mainGrid()); - return m_reservoirView->eclipseCase()->reservoirData()->mainGrid()->results(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RifReaderInterface* RimCellEdgeResultSlot::fileReaderinterface() -{ - if (m_reservoirView && m_reservoirView->eclipseCase()) - { - return m_reservoirView->eclipseCase()->fileInterface(); - } - else - { - return NULL; - } -} //-------------------------------------------------------------------------------------------------- /// diff --git a/ApplicationCode/ProjectDataModel/RimCellEdgeResultSlot.h b/ApplicationCode/ProjectDataModel/RimCellEdgeResultSlot.h index 3a5634351e..5eb678d7ff 100644 --- a/ApplicationCode/ProjectDataModel/RimCellEdgeResultSlot.h +++ b/ApplicationCode/ProjectDataModel/RimCellEdgeResultSlot.h @@ -75,9 +75,6 @@ protected: QStringList findResultVariableNames(); private: - RigReservoirCellResults* gridCellResults(); - RifReaderInterface* fileReaderinterface(); - void resetResultIndices(); void updateIgnoredScalarValue(); protected: diff --git a/ApplicationCode/ProjectDataModel/RimCellPropertyFilter.cpp b/ApplicationCode/ProjectDataModel/RimCellPropertyFilter.cpp index ef68ea6734..3cc8822740 100644 --- a/ApplicationCode/ProjectDataModel/RimCellPropertyFilter.cpp +++ b/ApplicationCode/ProjectDataModel/RimCellPropertyFilter.cpp @@ -53,7 +53,16 @@ RimCellPropertyFilter::RimCellPropertyFilter() CAF_PDM_InitFieldNoDefault(&resultDefinition, "ResultDefinition", "Result definition", "", "", ""); resultDefinition = new RimResultDefinition(); - resultDefinition.setHidden(true); + + // Take ownership of the fields in RimResultDefinition to be able to trap fieldChangedByUi in this class + resultDefinition->resultType.setOwnerObject(this); + resultDefinition->resultVariable.setOwnerObject(this); + resultDefinition->resultType.setUiName(""); + resultDefinition->resultVariable.setUiName(""); + + // Set to hidden to avoid this item to been displayed as a child item + // Fields in this object are displayed using defineUiOrdering() + resultDefinition.setUiHidden(true); CAF_PDM_InitField(&lowerBound, "LowerBound", 0.0, "Min", "", "", ""); CAF_PDM_InitField(&upperBound, "UpperBound", 0.0, "Max", "", "", ""); @@ -76,8 +85,10 @@ void RimCellPropertyFilter::fieldChangedByUi(const caf::PdmFieldHandle* changedF if (changedField == &name) { } - else if (&resultDefinition == changedField) + else if (&(resultDefinition->resultType) == changedField || &(resultDefinition->resultVariable) == changedField) { + resultDefinition->fieldChangedByUi(changedField, oldValue, newValue); + setDefaultValues(); m_parentContainer->fieldChangedByUi(changedField, oldValue, newValue); } @@ -86,71 +97,6 @@ void RimCellPropertyFilter::fieldChangedByUi(const caf::PdmFieldHandle* changedF m_parentContainer->fieldChangedByUi(changedField, oldValue, newValue); this->updateIconState(); } - -} - - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RimCellPropertyFilter::isCellRejected(const RigGridBase* grid, size_t timeStepIndex, size_t cellIndex) const -{ - CVF_ASSERT(grid); - - if (resultDefinition->gridScalarIndex() == cvf::UNDEFINED_SIZE_T) - { - return false; - } - - size_t resultIndex = 0; - if (resultDefinition->hasDynamicResult()) - { - resultIndex = timeStepIndex; - } - - double scalarValue = grid->cellScalar(resultIndex, resultDefinition->gridScalarIndex(), cellIndex); - bool rejected = false; - if (scalarValue < lowerBound || scalarValue > upperBound) - { - rejected = true; - } - - if (filterMode == INCLUDE) - { - return rejected; - } - else - { - return !rejected; - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -cvf::CellRangeFilter::CellStateType RimCellPropertyFilter::cellFilterState(const RigGridBase* grid, size_t timeStepIndex, size_t cellIndex) const -{ - CVF_TIGHT_ASSERT(grid); - CVF_TIGHT_ASSERT(resultDefinition->gridScalarIndex() != cvf::UNDEFINED_SIZE_T); - - size_t tStepIdx = 0; - if (resultDefinition->hasDynamicResult()) - { - tStepIdx = timeStepIndex; - } - - double scalarValue = grid->cellScalar(tStepIdx, resultDefinition->gridScalarIndex(), cellIndex); - - if ( lowerBound <= scalarValue && scalarValue <= upperBound) - { - if (filterMode == INCLUDE) return cvf::CellRangeFilter::INCLUDED; - else return cvf::CellRangeFilter::EXCLUDED; - } - else - { - return cvf::CellRangeFilter::NOT_INCLUDED; - } } //-------------------------------------------------------------------------------------------------- @@ -204,3 +150,26 @@ void RimCellPropertyFilter::setDefaultValues() upperBound.setUiName(QString("Max (%1)").arg(max)); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimCellPropertyFilter::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) const +{ + // Fields declared in RimCellFilter + uiOrdering.add(&name); + + // Fields declared in RimResultDefinition + caf::PdmUiGroup* group1 = uiOrdering.addNewGroup("Result"); + group1->add(&(resultDefinition->resultType)); + group1->add(&(resultDefinition->resultVariable)); + + // Fields declared in RimCellFilter + uiOrdering.add(&active); + uiOrdering.add(&filterMode); + + // Fields declared in this class (RimCellPropertyFilter) + uiOrdering.add(&lowerBound); + uiOrdering.add(&upperBound); + uiOrdering.add(&filterMode); +} + diff --git a/ApplicationCode/ProjectDataModel/RimCellPropertyFilter.h b/ApplicationCode/ProjectDataModel/RimCellPropertyFilter.h index 6c4dcbc548..b0de0712ff 100644 --- a/ApplicationCode/ProjectDataModel/RimCellPropertyFilter.h +++ b/ApplicationCode/ProjectDataModel/RimCellPropertyFilter.h @@ -33,6 +33,7 @@ class RimResultDefinition; class RigGridBase; class RigReservoirCellResults; + namespace cvf { //enum CellRangeFilter::CellStateType; @@ -66,13 +67,13 @@ public: caf::PdmField upperBound; caf::PdmField< caf::AppEnum< EvaluationRegionType > > evaluationRegion; - bool isCellRejected(const RigGridBase* grid, size_t timeStepIndex, size_t cellIndex) const; - cvf::CellRangeFilter::CellStateType cellFilterState(const RigGridBase* grid, size_t timeStepIndex, size_t cellIndex) const; - virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue); virtual QList calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly ); +protected: + virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) const; + private: RimCellPropertyFilterCollection* m_parentContainer; }; diff --git a/ApplicationCode/ProjectDataModel/RimCellPropertyFilterCollection.cpp b/ApplicationCode/ProjectDataModel/RimCellPropertyFilterCollection.cpp index b40d7ef8bd..828aad2447 100644 --- a/ApplicationCode/ProjectDataModel/RimCellPropertyFilterCollection.cpp +++ b/ApplicationCode/ProjectDataModel/RimCellPropertyFilterCollection.cpp @@ -102,64 +102,6 @@ RimCellPropertyFilter* RimCellPropertyFilterCollection::createAndAppendPropertyF return propertyFilter; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RimCellPropertyFilterCollection::isCellRejected(const RigGridBase* grid, size_t timeStepIndex, size_t cellIndex) const -{ - std::list< caf::PdmPointer< RimCellPropertyFilter > >::const_iterator it; - if (propertyFilters.v().empty()) return false; - - bool rejectCell = true; - for (it = propertyFilters.v().begin(); it != propertyFilters.v().end(); ++it) - { - if (!(*it)->isCellRejected(grid, timeStepIndex, cellIndex)) - { - rejectCell = false; - } - } - - return rejectCell; -} - -cvf::CellRangeFilter::CellStateType RimCellPropertyFilterCollection::cellFilterState(const RigGridBase* grid, cvf::CellRangeFilter::CellStateType rangeCellState, size_t timeStepIndex, size_t cellIndex) const -{ - bool included = false; - - std::list< caf::PdmPointer< RimCellPropertyFilter > >::const_iterator it; - for (it = propertyFilters.v().begin(); it != propertyFilters.v().end(); ++it) - { - RimCellPropertyFilter* propertyFilter = *it; - CVF_ASSERT(propertyFilter); - - if (propertyFilter->active() && propertyFilter->resultDefinition->hasResult()) - { - // No property filter evaluation outside evaluation region - if (propertyFilter->evaluationRegion == RimCellPropertyFilter::RANGE_FILTER_REGION && rangeCellState != cvf::CellRangeFilter::INCLUDED) - { - continue; - } - - bool rejected = propertyFilter->isCellRejected(grid, timeStepIndex, cellIndex); - - if (propertyFilter->filterMode == RimCellFilter::EXCLUDE) - { - if (rejected) - { - // Reject from exclude filters will always win - return cvf::CellRangeFilter::EXCLUDED; - } - } - - if (!rejected) - { - included = true; - } - } - } - - return included ? cvf::CellRangeFilter::INCLUDED : cvf::CellRangeFilter::EXCLUDED; -} //-------------------------------------------------------------------------------------------------- /// diff --git a/ApplicationCode/ProjectDataModel/RimCellPropertyFilterCollection.h b/ApplicationCode/ProjectDataModel/RimCellPropertyFilterCollection.h index a111f3aab3..6c4299099d 100644 --- a/ApplicationCode/ProjectDataModel/RimCellPropertyFilterCollection.h +++ b/ApplicationCode/ProjectDataModel/RimCellPropertyFilterCollection.h @@ -39,9 +39,6 @@ public: RimCellPropertyFilter* createAndAppendPropertyFilter(); void remove(RimCellPropertyFilter* propertyFilter); - bool isCellRejected(const RigGridBase* grid, size_t timeStepIndex, size_t cellIndex) const; - cvf::CellRangeFilter::CellStateType cellFilterState(const RigGridBase* grid, cvf::CellRangeFilter::CellStateType rangeCellState, size_t timeStepIndex, size_t cellIndex) const; - bool hasActiveFilters() const; bool hasActiveDynamicFilters() const; diff --git a/ApplicationCode/ProjectDataModel/RimDefines.cpp b/ApplicationCode/ProjectDataModel/RimDefines.cpp index 03f3ff9e18..7cd3f827a3 100644 --- a/ApplicationCode/ProjectDataModel/RimDefines.cpp +++ b/ApplicationCode/ProjectDataModel/RimDefines.cpp @@ -20,7 +20,6 @@ #include "RimDefines.h" #include "cafAppEnum.h" -#include "RifReaderInterface.h" namespace caf @@ -30,7 +29,8 @@ namespace caf { addItem(RimDefines::DYNAMIC_NATIVE, "DYNAMIC_NATIVE", "Dynamic"); addItem(RimDefines::STATIC_NATIVE, "STATIC_NATIVE", "Static"); - addItem(RimDefines::GENERATED, "Generated", "Generated"); + addItem(RimDefines::GENERATED, "GENERATED", "Generated"); + addItem(RimDefines::INPUT_PROPERTY, "INPUT_PROPERTY", "Input Property"); setDefault(RimDefines::DYNAMIC_NATIVE); } diff --git a/ApplicationCode/ProjectDataModel/RimDefines.h b/ApplicationCode/ProjectDataModel/RimDefines.h index 07f33137ed..f2272bba41 100644 --- a/ApplicationCode/ProjectDataModel/RimDefines.h +++ b/ApplicationCode/ProjectDataModel/RimDefines.h @@ -18,11 +18,7 @@ #pragma once -#include "cafPdmUiItem.h" -#include - -class RifReaderInterface; - +#include class RimDefines { @@ -32,8 +28,11 @@ public: { DYNAMIC_NATIVE, STATIC_NATIVE, - GENERATED + GENERATED, + INPUT_PROPERTY, + REMOVED }; - + static QString nonSelectedResultName() { return "None"; } }; + diff --git a/ApplicationCode/ProjectDataModel/RimExportInputPropertySettings.cpp b/ApplicationCode/ProjectDataModel/RimExportInputPropertySettings.cpp new file mode 100644 index 0000000000..f2f432b775 --- /dev/null +++ b/ApplicationCode/ProjectDataModel/RimExportInputPropertySettings.cpp @@ -0,0 +1,54 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RIStdInclude.h" + +#include "RimExportInputPropertySettings.h" +#include "cafPdmUiFilePathEditor.h" + + +CAF_PDM_SOURCE_INIT(RimExportInputSettings, "RimExportInputSettings"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimExportInputSettings::RimExportInputSettings() +{ + CAF_PDM_InitObject("RimExportInputSettings", "", "", ""); + + CAF_PDM_InitFieldNoDefault(&fileName, "Filename", "Export filename", "", "", ""); + fileName.setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName()); + CAF_PDM_InitFieldNoDefault(&eclipseKeyword, "Eclipse Keyword", "Keyword", "", "", ""); + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimExportInputSettings::defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute * attribute) +{ + if (field == &fileName) + { + caf::PdmUiFilePathEditorAttribute* myAttr = static_cast(attribute); + if (myAttr) + { + myAttr->m_selectSaveFileName = true; + } + } +} + diff --git a/ApplicationCode/ProjectDataModel/RimExportInputPropertySettings.h b/ApplicationCode/ProjectDataModel/RimExportInputPropertySettings.h new file mode 100644 index 0000000000..3348e8bbaf --- /dev/null +++ b/ApplicationCode/ProjectDataModel/RimExportInputPropertySettings.h @@ -0,0 +1,41 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafPdmField.h" +#include "cafPdmObject.h" + + +//================================================================================================== +/// +/// +//================================================================================================== +class RimExportInputSettings : public caf::PdmObject +{ + CAF_PDM_HEADER_INIT; +public: + RimExportInputSettings(); + + caf::PdmField fileName; + caf::PdmField eclipseKeyword; + +protected: + virtual void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute); +}; + diff --git a/ApplicationCode/ProjectDataModel/RimInputProperty.cpp b/ApplicationCode/ProjectDataModel/RimInputProperty.cpp new file mode 100644 index 0000000000..f226a8673c --- /dev/null +++ b/ApplicationCode/ProjectDataModel/RimInputProperty.cpp @@ -0,0 +1,72 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RIStdInclude.h" + +#include "RimInputProperty.h" + +#include "cvfAssert.h" + +#include "cafPdmUiLineEditor.h" + +#include + +namespace caf { +template<> +void RimInputProperty::ResolveStateEnum::setUp() +{ + addItem(RimInputProperty::UNKNOWN, "UNKNOWN", "Unknown"); + addItem(RimInputProperty::FILE_MISSING, "FILE_MISSING", "No data loaded, can't find the file"); + addItem(RimInputProperty::KEYWORD_NOT_IN_FILE, "KEYWORD_NOT_IN_FILE", "No data loaded, can't find the keyword"); + addItem(RimInputProperty::RESOLVED_NOT_SAVED, "RESOLVED_NOT_SAVED", "Ok, but not saved"); + addItem(RimInputProperty::RESOLVED, "RESOLVED", "Loaded, Ok"); + setDefault(RimInputProperty::UNKNOWN); +} +} + + +CAF_PDM_SOURCE_INIT(RimInputProperty, "RimInputProperty"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimInputProperty::RimInputProperty() +{ + CAF_PDM_InitObject("Input Property", ":/EclipseInput48x48.png", "", ""); + + CAF_PDM_InitField(&resultName, "ResultName", QString(), "Result name", "", "" ,""); + CAF_PDM_InitField(&eclipseKeyword, "EclipseKeyword", QString(), "Eclipse Keyword", "", "" ,""); + CAF_PDM_InitField(&fileName, "FileName", QString(), "Filename", "", "" ,""); + CAF_PDM_InitField(&resolvedState, "ResolvedState", (ResolveStateEnum)UNKNOWN, "Data state", "", "", ""); + + resolvedState.setUiReadOnly(true); + resolvedState.setIOReadable(false); + resolvedState.setIOWritable(false); + resolvedState.setUiEditorTypeName(caf::PdmUiLineEditor::uiEditorTypeName()); + + fileName.setUiReadOnly(true); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimInputProperty::~RimInputProperty() +{ + +} + diff --git a/ApplicationCode/ProjectDataModel/RimInputProperty.h b/ApplicationCode/ProjectDataModel/RimInputProperty.h new file mode 100644 index 0000000000..7ee9e916a1 --- /dev/null +++ b/ApplicationCode/ProjectDataModel/RimInputProperty.h @@ -0,0 +1,64 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cvfBase.h" +#include "cvfObject.h" +#include "cafPdmField.h" +#include "cafPdmObject.h" +#include "cafAppEnum.h" + +class QString; + +//================================================================================================== +// +// +// +//================================================================================================== +class RimInputProperty : public caf::PdmObject +{ + CAF_PDM_HEADER_INIT; + +public: + RimInputProperty(); + virtual ~RimInputProperty(); + + enum ResolveState + { + UNKNOWN, + FILE_MISSING, + KEYWORD_NOT_IN_FILE, + RESOLVED_NOT_SAVED, + RESOLVED + }; + typedef caf::AppEnum ResolveStateEnum; + + // Fields: + caf::PdmField resultName; + caf::PdmField eclipseKeyword; + caf::PdmField fileName; // ReadOnly Serves as key to syncronize read eclipse prop data and this inputProp object. + caf::PdmField resolvedState; // ReadOnly and not writable + + // PdmObject Overrides + virtual caf::PdmFieldHandle* userDescriptionField() { return &resultName;} + +private: + // Possibly the resultIndex, but it should be superfluous + +}; diff --git a/ApplicationCode/ProjectDataModel/RimInputPropertyCollection.cpp b/ApplicationCode/ProjectDataModel/RimInputPropertyCollection.cpp new file mode 100644 index 0000000000..4520653a03 --- /dev/null +++ b/ApplicationCode/ProjectDataModel/RimInputPropertyCollection.cpp @@ -0,0 +1,97 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RIStdInclude.h" + +#include "RimInputPropertyCollection.h" + + +CAF_PDM_SOURCE_INIT(RimInputPropertyCollection, "RimInputPropertyCollection"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimInputPropertyCollection::RimInputPropertyCollection() +{ + CAF_PDM_InitObject("Input Properties", ":/EclipseInput48x48.png", "", ""); + + CAF_PDM_InitFieldNoDefault(&inputProperties, "InputProperties", "", "", "", ""); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimInputPropertyCollection::~RimInputPropertyCollection() +{ + +} + +//-------------------------------------------------------------------------------------------------- +/// Returns the InputProperties pointing to the same file as \a fileName +//-------------------------------------------------------------------------------------------------- +std::vector RimInputPropertyCollection::findInputProperties(QString fileName) +{ + QFileInfo fileInfo(fileName); + std::vector result; + for (size_t i = 0; i < this->inputProperties.size(); ++i) + { + if (!inputProperties[i]) continue; + + QFileInfo propFile(inputProperties[i]->fileName()); + if (fileInfo == propFile) result.push_back(inputProperties[i]); + } + + return result; +} + +//-------------------------------------------------------------------------------------------------- +/// Remove given input property from collection and checks if the associated file is referenced by other input +/// properties +//-------------------------------------------------------------------------------------------------- +void RimInputPropertyCollection::removeInputProperty(RimInputProperty* inputProperty, bool& isPropertyFileReferencedByOthers) +{ + CVF_ASSERT(inputProperty); + + this->inputProperties.removeChildObject(inputProperty); + + isPropertyFileReferencedByOthers = false; + for (size_t i = 0; i < this->inputProperties.size(); i++) + { + if (inputProperties[i]->fileName() == inputProperty->fileName) + { + isPropertyFileReferencedByOthers = true; + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// Returns the InputProperty with resultName \a resultName +//-------------------------------------------------------------------------------------------------- +RimInputProperty * RimInputPropertyCollection::findInputProperty(QString resultName) +{ + for (size_t i = 0; i < this->inputProperties.size(); i++) + { + if (inputProperties[i] && inputProperties[i]->resultName() == resultName) + { + return inputProperties[i]; + } + } + + return NULL; +} + diff --git a/ApplicationCode/ProjectDataModel/RimInputPropertyCollection.h b/ApplicationCode/ProjectDataModel/RimInputPropertyCollection.h new file mode 100644 index 0000000000..2e865fda76 --- /dev/null +++ b/ApplicationCode/ProjectDataModel/RimInputPropertyCollection.h @@ -0,0 +1,50 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cvfBase.h" +#include "cvfObject.h" +#include "cafPdmField.h" +#include "cafPdmObject.h" + +#include "RimInputProperty.h" + + +//================================================================================================== +// +// +// +//================================================================================================== +class RimInputPropertyCollection : public caf::PdmObject +{ + CAF_PDM_HEADER_INIT; + +public: + RimInputPropertyCollection(); + virtual ~RimInputPropertyCollection(); + std::vector findInputProperties(QString fileName); + RimInputProperty* findInputProperty(QString resultName); + + void removeInputProperty(RimInputProperty* inputProperty, bool& isPropertyFileReferencedByOthers); + + + // Fields: + caf::PdmPointersField inputProperties; + +}; diff --git a/ApplicationCode/ProjectDataModel/RimInputReservoir.cpp b/ApplicationCode/ProjectDataModel/RimInputReservoir.cpp new file mode 100644 index 0000000000..9d3e3ee924 --- /dev/null +++ b/ApplicationCode/ProjectDataModel/RimInputReservoir.cpp @@ -0,0 +1,398 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RIStdInclude.h" + +#include "RimInputReservoir.h" +#include "RimInputProperty.h" +#include "RimReservoirView.h" + +#include "RifReaderEclipseInput.h" + +#include "RigReservoir.h" +#include "RigReservoirCellResults.h" + +#include "cvfAssert.h" + +#include +#include "RifReaderMockModel.h" +#include "RifEclipseInputFileTools.h" +#include "cafProgressInfo.h" + +CAF_PDM_SOURCE_INIT(RimInputReservoir, "RimInputReservoir"); +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimInputReservoir::RimInputReservoir() + : RimReservoir() +{ + CAF_PDM_InitObject("RimInputReservoir", ":/EclipseInput48x48.png", "", ""); + CAF_PDM_InitField(&m_gridFileName, "GridFileName", QString(), "Case grid filename", "", "" ,""); + CAF_PDM_InitFieldNoDefault(&m_additionalFileNames, "AdditionalFileNames", "Additional files", "", "" ,""); + + + CAF_PDM_InitFieldNoDefault(&m_inputPropertyCollection, "InputPropertyCollection", "", "", "", ""); + m_inputPropertyCollection = new RimInputPropertyCollection; +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimInputReservoir::~RimInputReservoir() +{ + delete m_inputPropertyCollection; +} + +//-------------------------------------------------------------------------------------------------- +/// Open the supplied file set. If no grid data has been read, it will first find the possible +/// grid data among the files then read all supported properties from the files matching the grid +//-------------------------------------------------------------------------------------------------- +void RimInputReservoir::openDataFileSet(const QStringList& filenames) +{ + if (caseName().contains("Input Mock Debug Model")) + { + cvf::ref readerInterface = this->createMockModel(this->caseName()); + m_rigReservoir->mainGrid()->results()->setReaderInterface(readerInterface.p()); + return; + } + + if (m_rigReservoir.isNull()) + { + RigReservoir* reservoir = new RigReservoir; + m_rigReservoir = reservoir; + } + + // First find and read the grid data + if (this->reservoirData()->mainGrid()->gridPointDimensions() == cvf::Vec3st(0,0,0)) + { + for (int i = 0; i < filenames.size(); i++) + { + if (RifEclipseInputFileTools::openGridFile(filenames[i], this->reservoirData())) + { + m_gridFileName = filenames[i]; + + m_rigReservoir->computeFaults(); + m_rigReservoir->mainGrid()->computeCachedData(); + + break; + } + } + } + + if (this->reservoirData()->mainGrid()->gridPointDimensions() == cvf::Vec3st(0,0,0)) + { + return ; // No grid present + } + + // Then read the properties possibly in the grid file + QStringList filesToRead; + for (int i = 0; i < filenames.size(); i++) + { + size_t j; + bool exist = false; + for (j = 0; j < m_additionalFileNames().size(); j++) + { + if (m_additionalFileNames()[j] == filenames[i]) + { + exist = true; + } + } + + if (!exist) + { + filesToRead.push_back(filenames[i]); + } + } + + for (int i = 0; i < filesToRead.size(); i++) + { + QString propertyFileName = filesToRead[i]; + std::map readProperties = RifEclipseInputFileTools::readProperties(propertyFileName, this->reservoirData()); + + std::map::iterator it; + for (it = readProperties.begin(); it != readProperties.end(); ++it) + { + RimInputProperty* inputProperty = new RimInputProperty; + inputProperty->resultName = it->first; + inputProperty->eclipseKeyword = it->second; + inputProperty->fileName = propertyFileName; + inputProperty->resolvedState = RimInputProperty::RESOLVED; + m_inputPropertyCollection->inputProperties.push_back(inputProperty); + } + + if (propertyFileName != m_gridFileName) + { + m_additionalFileNames.v().push_back(propertyFileName); + } + } +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimInputReservoir::openEclipseGridFile() +{ + // Early exit if reservoir data is created + if (m_rigReservoir.notNull()) return true; + + cvf::ref readerInterface; + + if (caseName().contains("Input Mock Debug Model")) + { + readerInterface = this->createMockModel(this->caseName()); + } + else + { + RigReservoir* reservoir = new RigReservoir; + readerInterface = new RifReaderEclipseInput; + if (!readerInterface->open(m_gridFileName, reservoir)) + { + delete reservoir; + return false; + } + + m_rigReservoir = reservoir; + loadAndSyncronizeInputProperties(); + } + + CVF_ASSERT(m_rigReservoir.notNull()); + CVF_ASSERT(readerInterface.notNull()); + + m_rigReservoir->mainGrid()->results()->setReaderInterface(readerInterface.p()); + m_rigReservoir->computeFaults(); + m_rigReservoir->mainGrid()->computeCachedData(); + + return true; + } + +#define for_all(stdVector, indexName) for (size_t indexName = 0; indexName < stdVector.size(); ++indexName) +//-------------------------------------------------------------------------------------------------- +/// Loads input property data from the gridFile and additional files +/// Creates new InputProperties if necessary, and flags the unused ones as obsolete +//-------------------------------------------------------------------------------------------------- +void RimInputReservoir::loadAndSyncronizeInputProperties() +{ + // Make sure we actually have reservoir data + + CVF_ASSERT(m_rigReservoir.notNull()); + CVF_ASSERT(this->reservoirData()->mainGrid()->gridPointDimensions() != cvf::Vec3st(0,0,0)); + + // Then read the properties from all the files referenced by the InputReservoir + + std::vector filenames = m_additionalFileNames; + filenames.push_back(m_gridFileName); + + const std::vector& knownKeywords = RifEclipseInputFileTools::knownPropertyKeywords(); + + size_t inputPropCount = this->m_inputPropertyCollection()->inputProperties.size(); + + caf::ProgressInfo progInfo(filenames.size() *( inputPropCount + knownKeywords.size()), "Reading Input properties" ); + int progress = 0; + + for_all(filenames, i) + { + progress = i*( inputPropCount + knownKeywords.size()); + // Find all the keywords present on the file + + progInfo.setProgressDescription(filenames[i]); + + QFileInfo fileNameInfo(filenames[i]); + bool isExistingFile = fileNameInfo.exists(); + + std::set fileKeywordSet; + + if (isExistingFile) + { + std::vector fileKeywords = RifEclipseInputFileTools::findKeywordsOnFile(filenames[i]); + for_all(fileKeywords, fkIt) fileKeywordSet.insert(fileKeywords[fkIt]); + } + + // Find the input property objects referring to the file + + std::vector ipsUsingThisFile = this->m_inputPropertyCollection()->findInputProperties(filenames[i]); + + // Read property data for each inputProperty + + for_all(ipsUsingThisFile, ipIdx) + { + if (!isExistingFile) + { + ipsUsingThisFile[ipIdx]->resolvedState = RimInputProperty::FILE_MISSING; + } + else + { + QString kw = ipsUsingThisFile[ipIdx]->eclipseKeyword(); + ipsUsingThisFile[ipIdx]->resolvedState = RimInputProperty::KEYWORD_NOT_IN_FILE; + if (fileKeywordSet.count(kw)) + { + if (RifEclipseInputFileTools::readProperty(filenames[i], this->reservoirData(), kw, ipsUsingThisFile[ipIdx]->resultName )) + { + ipsUsingThisFile[ipIdx]->resolvedState = RimInputProperty::RESOLVED; + } + } + fileKeywordSet.erase(kw); + } + + progInfo.setProgress(progress + ipIdx ); + } + + progInfo.setProgress(progress + inputPropCount); + // Check if there are more known property keywords left on file. If it is, read them and create inputProperty objects + + if (!fileKeywordSet.empty()) + { + + + std::vector knownKwsLeft; + for_all(knownKeywords, fkIt) + { + if (fileKeywordSet.count(knownKeywords[fkIt])) + { + QString resultName = this->reservoirData()->mainGrid()->results()->makeResultNameUnique(knownKeywords[fkIt]); + if (RifEclipseInputFileTools::readProperty(filenames[i], this->reservoirData(), knownKeywords[fkIt], resultName)) + { + RimInputProperty* inputProperty = new RimInputProperty; + inputProperty->resultName = resultName; + inputProperty->eclipseKeyword = knownKeywords[fkIt]; + inputProperty->fileName = filenames[i]; + inputProperty->resolvedState = RimInputProperty::RESOLVED; + m_inputPropertyCollection->inputProperties.push_back(inputProperty); + } + } + progInfo.setProgress(progress + inputPropCount + fkIt); + } + } + } + + for_all(m_inputPropertyCollection->inputProperties, i) + { + if (m_inputPropertyCollection->inputProperties[i]->resolvedState() == RimInputProperty::UNKNOWN) + { + m_inputPropertyCollection->inputProperties[i]->resolvedState = RimInputProperty::FILE_MISSING; + } + } +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimInputReservoir::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) +{ + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimInputReservoir::addFiles(const QStringList& newFileNames) +{ + +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimInputReservoir::removeFiles(const QStringList& obsoleteFileNames) +{ + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimInputReservoir::removeProperty(RimInputProperty* inputProperty) +{ + bool isPropertyFileReferencedByOthers = false; + + m_inputPropertyCollection->removeInputProperty(inputProperty, isPropertyFileReferencedByOthers); + if (!isPropertyFileReferencedByOthers) + { + std::vector newList; + size_t i; + for (i = 0; i < m_additionalFileNames().size(); i++) + { + if (m_additionalFileNames()[i] != inputProperty->fileName) + { + newList.push_back(m_additionalFileNames()[i]); + } + } + + m_additionalFileNames.v() = newList; + } + + // Remove the results pointed to by this input property + RigReservoirCellResults* results = m_rigReservoir->mainGrid()->results(); + results->removeResult(inputProperty->resultName); + + this->removeResult(inputProperty->resultName); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::ref RimInputReservoir::createMockModel(QString modelName) +{ + cvf::ref reservoir = new RigReservoir; + cvf::ref mockFileInterface = new RifReaderMockModel; + + if (modelName == "Input Mock Debug Model Simple") + { + // Create the mock file interface and and RigSerervoir and set them up. + mockFileInterface->setWorldCoordinates(cvf::Vec3d(10, 10, 10), cvf::Vec3d(20, 20, 20)); + mockFileInterface->setGridPointDimensions(cvf::Vec3st(4, 5, 6)); + mockFileInterface->addLocalGridRefinement(cvf::Vec3st(0, 2, 2), cvf::Vec3st(0, 2, 2), cvf::Vec3st(3, 3, 3)); + mockFileInterface->setResultInfo(3, 10); + + mockFileInterface->open("", reservoir.p()); + { + size_t idx = reservoir->mainGrid()->cellIndexFromIJK(1, 3, 4); + reservoir->mainGrid()->cell(idx).setActive(false); + } + + { + size_t idx = reservoir->mainGrid()->cellIndexFromIJK(2, 2, 3); + reservoir->mainGrid()->cell(idx).setActive(false); + } + + // Add a property + RimInputProperty* inputProperty = new RimInputProperty; + inputProperty->resultName = "PORO"; + inputProperty->eclipseKeyword = "PORO"; + inputProperty->fileName = "PORO.prop"; + m_inputPropertyCollection->inputProperties.push_back(inputProperty); + } + + m_rigReservoir = reservoir; + + return mockFileInterface.p(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimInputReservoir::locationOnDisc() const +{ + if (m_gridFileName().isEmpty()) return QString(); + + QFileInfo fi(m_gridFileName); + return fi.absolutePath(); +} diff --git a/ApplicationCode/ProjectDataModel/RimInputReservoir.h b/ApplicationCode/ProjectDataModel/RimInputReservoir.h new file mode 100644 index 0000000000..45f06d8c7c --- /dev/null +++ b/ApplicationCode/ProjectDataModel/RimInputReservoir.h @@ -0,0 +1,73 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cvfBase.h" +#include "cvfObject.h" +#include "cafPdmField.h" +#include "cafPdmObject.h" + +#include "RimReservoir.h" +#include "RimInputPropertyCollection.h" + + +class QString; + +class RifReaderInterface; + +//================================================================================================== +// +// +// +//================================================================================================== +class RimInputReservoir : public RimReservoir +{ + CAF_PDM_HEADER_INIT; + +public: + RimInputReservoir(); + virtual ~RimInputReservoir(); + + // Fields + caf::PdmField > m_additionalFileNames; + caf::PdmField m_gridFileName; + + caf::PdmField m_inputPropertyCollection; + + // File open methods + void openDataFileSet(const QStringList& filenames); + void loadAndSyncronizeInputProperties(); + + void removeProperty(RimInputProperty* inputProperty); + + // RimReservoir overrides + virtual bool openEclipseGridFile(); // Find grid file among file set. Read, Find read and validate property date. Syncronize child property sets. + + // PdmObject overrides + virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue); + + virtual QString locationOnDisc() const; + +private: + void addFiles(const QStringList& newFileNames); + void removeFiles(const QStringList& obsoleteFileNames); + + cvf::ref createMockModel(QString modelName); + +}; diff --git a/ApplicationCode/ProjectDataModel/RimLegendConfig.cpp b/ApplicationCode/ProjectDataModel/RimLegendConfig.cpp index 25268ab026..5384f8e702 100644 --- a/ApplicationCode/ProjectDataModel/RimLegendConfig.cpp +++ b/ApplicationCode/ProjectDataModel/RimLegendConfig.cpp @@ -20,6 +20,9 @@ #include "RimLegendConfig.h" #include "RimReservoirView.h" +#include "cafFactory.h" +#include "cafPdmUiLineEditor.h" +#include "cafPdmUiComboBoxEditor.h" CAF_PDM_SOURCE_INIT(RimLegendConfig, "Legend"); @@ -78,7 +81,7 @@ RimLegendConfig::RimLegendConfig() CAF_PDM_InitField(&m_userDefinedMaxValue, "UserDefinedMax", 1.0, "Max", "", "Min value of the legend", ""); CAF_PDM_InitField(&m_userDefinedMinValue, "UserDefinedMin", 0.0, "Min", "", "Max value of the legend", ""); CAF_PDM_InitField(&resultVariableName, "ResultVariableUsage", QString(""), "", "", "", ""); - resultVariableName.setHidden(true); + resultVariableName.setUiHidden(true); m_linDiscreteScalarMapper = new cvf::ScalarMapperUniformLevels; m_linDiscreteScalarMapper->setTextureSize(1024); @@ -300,13 +303,13 @@ void RimLegendConfig::updateFieldVisibility() { if (m_rangeMode == USER_DEFINED) { - m_userDefinedMaxValue.setHidden(false); - m_userDefinedMinValue.setHidden(false); + m_userDefinedMaxValue.setUiHidden(false); + m_userDefinedMinValue.setUiHidden(false); } else { - m_userDefinedMaxValue.setHidden(true); - m_userDefinedMinValue.setHidden(true); + m_userDefinedMaxValue.setUiHidden(true); + m_userDefinedMinValue.setUiHidden(true); } } diff --git a/ApplicationCode/ProjectDataModel/RimProject.cpp b/ApplicationCode/ProjectDataModel/RimProject.cpp index fa2b114cd0..4a07ccbb52 100644 --- a/ApplicationCode/ProjectDataModel/RimProject.cpp +++ b/ApplicationCode/ProjectDataModel/RimProject.cpp @@ -30,13 +30,13 @@ CAF_PDM_SOURCE_INIT(RimProject, "ResInsightProject"); RimProject::RimProject(void) { CAF_PDM_InitFieldNoDefault(&m_projectFileVersionString, "ProjectFileVersionString", "", "", "", ""); - m_projectFileVersionString.setHidden(true); + m_projectFileVersionString.setUiHidden(true); CAF_PDM_InitFieldNoDefault(&reservoirs, "Reservoirs", "", "", "", ""); CAF_PDM_InitFieldNoDefault(&scriptCollection, "ScriptCollection", "Scripts", ":/Default.png", "", ""); scriptCollection = new RimScriptCollection(); - scriptCollection->directory.setHidden(true); + scriptCollection->directory.setUiHidden(true); initAfterRead(); } @@ -48,7 +48,7 @@ RimProject::~RimProject(void) { if (scriptCollection()) delete scriptCollection(); - reservoirs.deleteChildren(); + reservoirs.deleteAllChildObjects(); } //-------------------------------------------------------------------------------------------------- @@ -56,7 +56,7 @@ RimProject::~RimProject(void) //-------------------------------------------------------------------------------------------------- void RimProject::close() { - reservoirs.deleteChildren(); + reservoirs.deleteAllChildObjects(); fileName = ""; } @@ -89,8 +89,8 @@ void RimProject::setupBeforeSave() //-------------------------------------------------------------------------------------------------- void RimProject::setUserScriptPath(const QString& scriptDirectory) { - scriptCollection->calcScripts().deleteChildren(); - scriptCollection->subDirectories().deleteChildren(); + scriptCollection->calcScripts().deleteAllChildObjects(); + scriptCollection->subDirectories().deleteAllChildObjects(); QDir dir(scriptDirectory); diff --git a/ApplicationCode/ProjectDataModel/RimReservoir.cpp b/ApplicationCode/ProjectDataModel/RimReservoir.cpp index b873a7b7ae..8c4cdec334 100644 --- a/ApplicationCode/ProjectDataModel/RimReservoir.cpp +++ b/ApplicationCode/ProjectDataModel/RimReservoir.cpp @@ -18,45 +18,31 @@ #include "RIStdInclude.h" -#include "RifReaderInterfaceEcl.h" +#include "RifReaderEclipseOutput.h" #include "RimReservoir.h" #include "RigReservoir.h" #include "RigMainGrid.h" #include "RigReservoirCellResults.h" -#include "RimWell.h" -#include "RimWellCollection.h" #include "RimReservoirView.h" #include "cvfAssert.h" #include -#include "RifReaderInterfaceMock.h" +#include "RifReaderMockModel.h" -CAF_PDM_SOURCE_INIT(RimReservoir, "EclipseCase"); //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- RimReservoir::RimReservoir() { m_rigReservoir = NULL; - m_fileInterface = NULL; - CAF_PDM_InitObject("Reservoir", ":/AppLogo48x48.png", "", ""); CAF_PDM_InitField(&caseName, "CaseName", QString(), "Case name", "", "" ,""); - CAF_PDM_InitField(&caseDirectory, "CaseFolder", QString(), "Directory", "", "" ,""); CAF_PDM_InitFieldNoDefault(&reservoirViews, "ReservoirViews", "", "", "", ""); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RimReservoir::RimReservoir(RigReservoir* reservoir) -{ - m_rigReservoir = reservoir; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -73,144 +59,6 @@ const RigReservoir* RimReservoir::reservoirData() const return m_rigReservoir.p(); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RifReaderInterface* RimReservoir::fileInterface() -{ - return m_fileInterface.p(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -const RifReaderInterface* RimReservoir::fileInterface() const -{ - return m_fileInterface.p(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RimReservoir::openEclipseGridFile() -{ - // Early exit if reservoir data is created - if (m_rigReservoir.notNull()) return true; - - if (caseName().contains("Mock Debug Model")) - { - this->createMockModel(this->caseName()); - } - else - { - QString fullCaseName = caseName + ".EGRID"; - - QDir dir(caseDirectory.v()); - if (!dir.exists(fullCaseName)) - { - fullCaseName = caseName + ".GRID"; - if (!dir.exists(fullCaseName)) - { - return false; - } - } - - QString fname = dir.absoluteFilePath(fullCaseName); - - RigReservoir* reservoir = new RigReservoir; - m_fileInterface = new RifReaderInterfaceECL; - if (!m_fileInterface->open(fname, reservoir)) - { - delete reservoir; - return false; - } - - m_rigReservoir = reservoir; - } - - CVF_ASSERT(m_rigReservoir.notNull()); - CVF_ASSERT(m_fileInterface.notNull()); - - m_rigReservoir->mainGrid()->results()->setReaderInterface(m_fileInterface.p()); - m_rigReservoir->computeFaults(); - m_rigReservoir->mainGrid()->computeCachedData(); - - return true; - } - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimReservoir::createMockModel(QString modelName) -{ - cvf::ref mockFileInterface = new RifReaderInterfaceMock; - cvf::ref reservoir = new RigReservoir; - - if (modelName == "Mock Debug Model Simple") - { - // Create the mock file interface and and RigSerervoir and set them up. - mockFileInterface->setWorldCoordinates(cvf::Vec3d(10, 10, 10), cvf::Vec3d(20, 20, 20)); - mockFileInterface->setGridPointDimensions(cvf::Vec3st(4, 5, 6)); - mockFileInterface->addLocalGridRefinement(cvf::Vec3st(0, 2, 2), cvf::Vec3st(0, 2, 2), cvf::Vec3st(3, 3, 3)); - - mockFileInterface->open("", reservoir.p()); - { - size_t idx = reservoir->mainGrid()->cellIndexFromIJK(1, 3, 4); - reservoir->mainGrid()->cell(idx).setActive(false); - } - - { - size_t idx = reservoir->mainGrid()->cellIndexFromIJK(2, 2, 3); - reservoir->mainGrid()->cell(idx).setActive(false); - } - } - else if (modelName == "Mock Debug Model With Results") - { - mockFileInterface->setWorldCoordinates(cvf::Vec3d(10, 10, 10), cvf::Vec3d(-20, -20, -20)); - mockFileInterface->setGridPointDimensions(cvf::Vec3st(5, 10, 20)); - mockFileInterface->addLocalGridRefinement(cvf::Vec3st(0, 3, 3), cvf::Vec3st(1, 4, 9), cvf::Vec3st(2, 2, 2)); - mockFileInterface->setResultInfo(3, 10); - - mockFileInterface->open("", reservoir.p()); - - // Make a fault - cvf::Vec3d& tmp = reservoir->mainGrid()->nodes()[1]; - tmp += cvf::Vec3d(1, 0, 0); - } - else if (modelName =="Mock Debug Model Large With Results") - { - double startX = 0; - double startY = 0; - double startZ = 0; - - double widthX = 6000; - double widthY = 12000; - double widthZ = 500; - - double offsetX = 0; - double offsetY = 0; - double offsetZ = 0; - - // Test code to simulate UTM coordinates - offsetX = 400000; - offsetY = 6000000; - offsetZ = 0; - - - mockFileInterface->setWorldCoordinates(cvf::Vec3d(startX + offsetX, startY + offsetY, startZ + offsetZ), cvf::Vec3d(startX + widthX + offsetX, startY + widthY + offsetY, startZ + widthZ + offsetZ)); - mockFileInterface->setGridPointDimensions(cvf::Vec3st(50, 100, 200)); - mockFileInterface->addLocalGridRefinement(cvf::Vec3st(0, 30, 30), cvf::Vec3st(1, 40, 90), cvf::Vec3st(2, 2, 2)); - mockFileInterface->setResultInfo(3, 10); - - mockFileInterface->open("", reservoir.p()); - - } - - m_rigReservoir = reservoir; - m_fileInterface = mockFileInterface; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -231,7 +79,7 @@ void RimReservoir::initAfterRead() //-------------------------------------------------------------------------------------------------- RimReservoir::~RimReservoir() { - reservoirViews.deleteChildren(); + reservoirViews.deleteAllChildObjects(); } //-------------------------------------------------------------------------------------------------- @@ -274,3 +122,54 @@ void RimReservoir::removeReservoirView(RimReservoirView* reservoirView) } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimReservoir::removeResult(const QString& resultName) +{ + size_t i; + for (i = 0; i < reservoirViews().size(); i++) + { + RimReservoirView* reservoirView = reservoirViews()[i]; + CVF_ASSERT(reservoirView); + + RimResultSlot* result = reservoirView->cellResult; + CVF_ASSERT(result); + + bool rebuildDisplayModel = false; + + // Set cell result variable to none if displaying + if (result->resultVariable() == resultName) + { + result->resultVariable.v() = QString("None"); + result->loadResult(); + + rebuildDisplayModel = true; + } + + std::list< caf::PdmPointer< RimCellPropertyFilter > >::iterator it; + RimCellPropertyFilterCollection* propFilterCollection = reservoirView->propertyFilterCollection(); + for (it = propFilterCollection->propertyFilters.v().begin(); it != propFilterCollection->propertyFilters.v().end(); ++it) + { + RimCellPropertyFilter* propertyFilter = *it; + if (propertyFilter->resultDefinition->resultVariable.v() == resultName) + { + propertyFilter->resultDefinition->resultVariable.v() = QString("None"); + propertyFilter->resultDefinition->loadResult(); + propertyFilter->setDefaultValues(); + + rebuildDisplayModel = true; + } + } + + if (rebuildDisplayModel) + { + reservoirViews()[i]->createDisplayModelAndRedraw(); + } + + + // TODO + // CellEdgeResults are not considered, as they do not support display of input properties yet + } +} + diff --git a/ApplicationCode/ProjectDataModel/RimReservoir.h b/ApplicationCode/ProjectDataModel/RimReservoir.h index 2e9c502ef1..4e5e2c115e 100644 --- a/ApplicationCode/ProjectDataModel/RimReservoir.h +++ b/ApplicationCode/ProjectDataModel/RimReservoir.h @@ -23,57 +23,51 @@ #include "cafPdmField.h" #include "cafPdmObject.h" -#include "RimWellCollection.h" class QString; class RigReservoir; -class RifReaderInterface; -class RimWellCollection; class RigGridBase; +class RimReservoirView; //================================================================================================== -// // -// +// Interface for reservoirs. +// As this is a pure virtual class, the factory macros are not relevant (nor possible) to use +// CAF_PDM_HEADER_INIT and CAF_PDM_SOURCE_INIT +// //================================================================================================== -class RimReservoir : public caf::PdmObject, public cvf::Object +class RimReservoir : public caf::PdmObject { - CAF_PDM_HEADER_INIT; public: RimReservoir(); - RimReservoir(RigReservoir* reservoir); virtual ~RimReservoir(); - bool openEclipseGridFile(); + virtual bool openEclipseGridFile() = 0; RigReservoir* reservoirData(); const RigReservoir* reservoirData() const; - RifReaderInterface* fileInterface(); - const RifReaderInterface* fileInterface() const; - RimReservoirView* createAndAddReservoirView(); void removeReservoirView(RimReservoirView* reservoirView); + + void removeResult(const QString& resultName); // Fields: caf::PdmField caseName; - caf::PdmField caseDirectory; caf::PdmPointersField reservoirViews; - virtual caf::PdmFieldHandle* userDescriptionField() { return &caseName;} + virtual caf::PdmFieldHandle* userDescriptionField() { return &caseName; } + + virtual QString locationOnDisc() const { return QString(); } protected: // Overridden methods virtual void initAfterRead(); -private: - void createMockModel(QString modelName); -private: +protected: cvf::ref m_rigReservoir; - cvf::ref m_fileInterface; - }; diff --git a/ApplicationCode/ProjectDataModel/RimReservoirView.cpp b/ApplicationCode/ProjectDataModel/RimReservoirView.cpp index f80512de75..41f8a7ff0c 100644 --- a/ApplicationCode/ProjectDataModel/RimReservoirView.cpp +++ b/ApplicationCode/ProjectDataModel/RimReservoirView.cpp @@ -41,7 +41,6 @@ #include "cafCadNavigation.h" #include "cafCeetronNavigation.h" #include "RimReservoir.h" -#include "RifReaderInterface.h" namespace caf { @@ -90,13 +89,13 @@ RimReservoirView::RimReservoirView() CAF_PDM_InitField(&name, "UserDescription", QString(""), "Name", "", "", ""); CAF_PDM_InitField(&scaleZ, "GridZScale", 1.0, "Z Scale", "", "Scales the scene in the Z direction", ""); CAF_PDM_InitField(&showWindow, "ShowWindow", true, "Show 3D viewer", "", "", ""); - showWindow.setHidden(true); + showWindow.setUiHidden(true); CAF_PDM_InitField(&m_currentTimeStep, "CurrentTimeStep", 0, "Current Time Step","", "", ""); - m_currentTimeStep.setHidden(true); + m_currentTimeStep.setUiHidden(true); CAF_PDM_InitField(&animationMode, "AnimationMode", false, "Animation Mode","", "", ""); - animationMode.setHidden(true); + animationMode.setUiHidden(true); CAF_PDM_InitFieldNoDefault(&wellCollection, "WellCollection","Wells", "", "", ""); wellCollection = new RimWellCollection; @@ -113,7 +112,7 @@ RimReservoirView::RimReservoirView() CAF_PDM_InitFieldNoDefault(&surfaceMode, "SurfaceMode", "Grid surface", "", "", ""); CAF_PDM_InitField(&maximumFrameRate, "MaximumFrameRate", 10, "Maximum frame rate","", "", ""); - maximumFrameRate.setHidden(true); + maximumFrameRate.setUiHidden(true); // Visualization fields CAF_PDM_InitField(&showMainGrid, "ShowMainGrid", true, "Show Main Grid", "", "", ""); @@ -404,12 +403,6 @@ void RimReservoirView::createDisplayModel() if (m_reservoir && m_reservoir->reservoirData()) { - RigReservoir* reservoir = m_reservoir->reservoirData(); - CVF_ASSERT(reservoir); - - RigReservoirCellResults* results = reservoir->mainGrid()->results(); - CVF_ASSERT(results); - // Define a vector containing time step indices to produce geometry for. // First entry in this vector is used to define the geometry only result mode with no results. std::vector timeStepIndices; @@ -417,12 +410,16 @@ void RimReservoirView::createDisplayModel() // The one and only geometry entry timeStepIndices.push_back(0); + // Find the number of time frames the animation needs to show the requested data. + if (this->cellResult()->hasDynamicResult() || this->propertyFilterCollection()->hasActiveDynamicFilters() || this->wellCollection->hasVisibleWellPipes()) { + CVF_ASSERT(gridCellResults()); + size_t i; - for (i = 0; i < m_reservoir->fileInterface()->numTimeSteps(); i++) + for (i = 0; i < gridCellResults()->maxTimeStepCount(); i++) { timeStepIndices.push_back(i); } @@ -522,16 +519,16 @@ void RimReservoirView::createDisplayModel() // Create Scenes from the frameModels // Animation frames for results display, starts from frame 1 - size_t modelIndex; - for (modelIndex = 0; modelIndex < frameModels.size(); modelIndex++) + size_t frameIndex; + for (frameIndex = 0; frameIndex < frameModels.size(); frameIndex++) { - cvf::ModelBasicList* model = frameModels.at(modelIndex); + cvf::ModelBasicList* model = frameModels.at(frameIndex); model->updateBoundingBoxesRecursive(); cvf::ref scene = new cvf::Scene; scene->addModel(model); - if (modelIndex == 0) + if (frameIndex == 0) m_viewer->setMainScene(scene.p()); else m_viewer->addFrame(scene.p()); @@ -552,7 +549,6 @@ void RimReservoirView::createDisplayModel() //-------------------------------------------------------------------------------------------------- void RimReservoirView::updateCurrentTimeStep() { - updateLegends(); std::vector geometriesToRecolor; @@ -622,14 +618,33 @@ void RimReservoirView::updateCurrentTimeStep() cvf::Scene* frameScene = m_viewer->frame(m_currentTimeStep); if (frameScene) { - cvf::ref frameParts = new cvf::ModelBasicList; - m_pipesPartManager->appendDynamicGeometryPartsToModel(frameParts.p(), m_currentTimeStep); + cvf::String modelName = "WellPipeModel"; + std::vector models; + for (i = 0; i < frameScene->modelCount(); i++) + { + if (frameScene->model(i)->name() == modelName) + { + models.push_back(frameScene->model(i)); + } + } + + for (i = 0; i < models.size(); i++) + { + frameScene->removeModel(models[i]); + } + + cvf::ref pipeModel = new cvf::ModelBasicList; + pipeModel->setName(modelName); + + m_pipesPartManager->appendDynamicGeometryPartsToModel(pipeModel.p(), m_currentTimeStep); m_pipesPartManager->updatePipeResultColor(m_currentTimeStep); - frameParts->updateBoundingBoxesRecursive(); - frameScene->addModel(frameParts.p()); + pipeModel->updateBoundingBoxesRecursive(); + frameScene->addModel(pipeModel.p()); } } + + updateLegends(); } //-------------------------------------------------------------------------------------------------- @@ -643,7 +658,7 @@ void RimReservoirView::loadDataAndUpdate() { if (!m_reservoir->openEclipseGridFile()) { - QMessageBox::warning(RIMainWindow::instance(), "Error when opening project file", "Could not open the Eclipse Grid file (EGRID/GRID): \n"+ m_reservoir->caseName() + "\nIn directory " + m_reservoir->caseDirectory()); + QMessageBox::warning(RIMainWindow::instance(), "Error when opening project file", "Could not open the Eclipse Grid file (EGRID/GRID): \n"+ m_reservoir->caseName()); } else { diff --git a/ApplicationCode/ProjectDataModel/RimReservoirView.h b/ApplicationCode/ProjectDataModel/RimReservoirView.h index 12ee720396..d1866bb8f6 100644 --- a/ApplicationCode/ProjectDataModel/RimReservoirView.h +++ b/ApplicationCode/ProjectDataModel/RimReservoirView.h @@ -40,7 +40,6 @@ class RIViewer; class RigGridBase; class RigGridCellFaceVisibilityFilter; -class RimReservoir; class RivReservoirViewPartMgr; namespace cvf diff --git a/ApplicationCode/ProjectDataModel/RimResultDefinition.cpp b/ApplicationCode/ProjectDataModel/RimResultDefinition.cpp index bbac6f3b5e..4e8d1a4f24 100644 --- a/ApplicationCode/ProjectDataModel/RimResultDefinition.cpp +++ b/ApplicationCode/ProjectDataModel/RimResultDefinition.cpp @@ -25,7 +25,7 @@ #include "RigReservoirCellResults.h" #include "RigReservoir.h" #include "RigMainGrid.h" -#include "RifReaderInterface.h" +#include "cafPdmUiListEditor.h" CAF_PDM_SOURCE_INIT(RimResultDefinition, "ResultDefinition"); @@ -38,8 +38,10 @@ RimResultDefinition::RimResultDefinition() { CAF_PDM_InitObject("Result Definition", "", "", ""); - CAF_PDM_InitFieldNoDefault(&resultType, "ResultType","Result type", "", "", ""); - CAF_PDM_InitFieldNoDefault(&resultVariable, "ResultVariable","Variable", "", "", "" ); + CAF_PDM_InitFieldNoDefault(&resultType, "ResultType", "Type", "", "", ""); + CAF_PDM_InitField(&resultVariable, "ResultVariable", RimDefines::nonSelectedResultName(), "Variable", "", "", "" ); + + resultVariable.setUiEditorTypeName(caf::PdmUiListEditor::uiEditorTypeName()); } //-------------------------------------------------------------------------------------------------- @@ -65,21 +67,10 @@ void RimResultDefinition::fieldChangedByUi(const caf::PdmFieldHandle* changedFie { if (changedField == &resultType) { - resultVariable = ""; + resultVariable = RimDefines::nonSelectedResultName(); } loadResult(); - - // Notify the parent objects that this object has changed - // In this case the RimCellPropertyFilter. - // The RimReservoirView can also be a parent, but the call should have no effect there - - std::vector parentFields; - this->parentFields(parentFields); - for (size_t i = 0; i < parentFields.size(); ++i) - { - parentFields[i]->ownerObject()->fieldChangedByUi(parentFields[i], QVariant(), QVariant()); - } } //-------------------------------------------------------------------------------------------------- @@ -89,17 +80,13 @@ QList RimResultDefinition::calculateValueOptions(const c { if (fieldNeedingOptions == &resultVariable) { - if (m_reservoirView && - m_reservoirView->eclipseCase() && - m_reservoirView->eclipseCase()->fileInterface()) + if (m_reservoirView && m_reservoirView->gridCellResults()) { - RifReaderInterface* readerInterface = m_reservoirView->eclipseCase()->fileInterface(); - CVF_ASSERT(readerInterface); - + /* QStringList varList; if (resultType() == RimDefines::DYNAMIC_NATIVE) { - varList = readerInterface->dynamicResults(); + varList = readerInterface->dynamicResultNames(); if (!varList.contains("SOIL", Qt::CaseInsensitive)) { @@ -112,20 +99,26 @@ QList RimResultDefinition::calculateValueOptions(const c } else if (resultType == RimDefines::STATIC_NATIVE) { - varList = readerInterface->staticResults(); + varList = readerInterface->staticResultNames(); } else if (resultType == RimDefines::GENERATED) { varList = m_reservoirView->eclipseCase()->reservoirData()->mainGrid()->results()->resultNames(resultType()); } - + else if (resultType == RimDefines::INPUT_PROPERTY) + { + varList = readerInterface->inputPropertyNames(); + } + */ + + QStringList varList = m_reservoirView->gridCellResults()->resultNames(resultType()); QList optionList; int i; for (i = 0; i < varList.size(); ++i) { optionList.push_back(caf::PdmOptionItemInfo( varList[i], varList[i])); } - optionList.push_front(caf::PdmOptionItemInfo( "None", "" )); + optionList.push_front(caf::PdmOptionItemInfo( RimDefines::nonSelectedResultName(), RimDefines::nonSelectedResultName() )); if (useOptionsOnly) *useOptionsOnly = true; @@ -144,7 +137,7 @@ size_t RimResultDefinition::gridScalarIndex() const if (m_gridScalarResultIndex == cvf::UNDEFINED_SIZE_T) { const RigReservoirCellResults* gridCellResults = m_reservoirView->gridCellResults(); - if (gridCellResults) m_gridScalarResultIndex = gridCellResults->findGridScalarIndex(resultType(), resultVariable()); + if (gridCellResults) m_gridScalarResultIndex = gridCellResults->findScalarResultIndex(resultType(), resultVariable()); } return m_gridScalarResultIndex; } @@ -157,7 +150,7 @@ void RimResultDefinition::loadResult() RigReservoirCellResults* gridCellResults = m_reservoirView->gridCellResults(); if (gridCellResults) { - m_gridScalarResultIndex = gridCellResults->loadResultIntoGrid(resultType(), resultVariable); + m_gridScalarResultIndex = gridCellResults->findOrLoadScalarResult(resultType(), resultVariable); } else { @@ -167,7 +160,8 @@ void RimResultDefinition::loadResult() //-------------------------------------------------------------------------------------------------- -/// +/// Returns whether the result requested by the definition is a single frame result +/// The result needs to be loaded before asking //-------------------------------------------------------------------------------------------------- bool RimResultDefinition::hasStaticResult() const { @@ -183,7 +177,7 @@ bool RimResultDefinition::hasStaticResult() const } //-------------------------------------------------------------------------------------------------- -/// +/// Returns whether the result requested by the definition is loaded or possible to load from the result file //-------------------------------------------------------------------------------------------------- bool RimResultDefinition::hasResult() const { @@ -192,7 +186,7 @@ bool RimResultDefinition::hasResult() const const RigReservoirCellResults* gridCellResults = m_reservoirView->gridCellResults(); if (gridCellResults) { - m_gridScalarResultIndex = gridCellResults->findGridScalarIndex(resultType(), resultVariable()); + m_gridScalarResultIndex = gridCellResults->findScalarResultIndex(resultType(), resultVariable()); return m_gridScalarResultIndex != cvf::UNDEFINED_SIZE_T; } @@ -200,7 +194,8 @@ bool RimResultDefinition::hasResult() const } //-------------------------------------------------------------------------------------------------- -/// +/// Returns whether the result requested by the definition is a multi frame result +/// The result needs to be loaded before asking //-------------------------------------------------------------------------------------------------- bool RimResultDefinition::hasDynamicResult() const { @@ -210,3 +205,11 @@ bool RimResultDefinition::hasDynamicResult() const else return false; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimReservoirView* RimResultDefinition::reservoirView() +{ + return m_reservoirView; +} diff --git a/ApplicationCode/ProjectDataModel/RimResultDefinition.h b/ApplicationCode/ProjectDataModel/RimResultDefinition.h index b6cf3d61d7..5805b71f73 100644 --- a/ApplicationCode/ProjectDataModel/RimResultDefinition.h +++ b/ApplicationCode/ProjectDataModel/RimResultDefinition.h @@ -40,8 +40,9 @@ public: virtual ~RimResultDefinition(); virtual void setReservoirView(RimReservoirView* ownerReservoirView); + RimReservoirView* reservoirView(); - caf::PdmField< caf::AppEnum< RimDefines::ResultCatType > > resultType; + caf::PdmField< caf::AppEnum< RimDefines::ResultCatType > > resultType; caf::PdmField resultVariable; void loadResult(); @@ -52,9 +53,6 @@ public: virtual QList calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly ); - -protected: - virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue); protected: diff --git a/ApplicationCode/ProjectDataModel/RimResultReservoir.cpp b/ApplicationCode/ProjectDataModel/RimResultReservoir.cpp new file mode 100644 index 0000000000..3a616984b0 --- /dev/null +++ b/ApplicationCode/ProjectDataModel/RimResultReservoir.cpp @@ -0,0 +1,191 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RIStdInclude.h" +#include "RimResultReservoir.h" +#include "RigReservoir.h" +#include "RifReaderEclipseOutput.h" +#include "RigReservoirCellResults.h" +#include "RimReservoirView.h" +#include "RifReaderMockModel.h" +#include "RifReaderEclipseInput.h" +#include "cafProgressInfo.h" + + +CAF_PDM_SOURCE_INIT(RimResultReservoir, "EclipseCase"); +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimResultReservoir::RimResultReservoir() + : RimReservoir() +{ + CAF_PDM_InitField(&caseFileName, "CaseFileName", QString(), "Case file name", "", "" ,""); + CAF_PDM_InitField(&caseDirectory, "CaseFolder", QString(), "Directory", "", "" ,""); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimResultReservoir::openEclipseGridFile() +{ + caf::ProgressInfo progInfo(2, "Reading Eclipse Grid File"); + + progInfo.setProgressDescription("Open Grid File"); + // Early exit if reservoir data is created + if (m_rigReservoir.notNull()) return true; + + cvf::ref readerInterface; + + if (caseName().contains("Result Mock Debug Model")) + { + readerInterface = this->createMockModel(this->caseName()); + } + else + { + QString fullCaseName = caseName + ".EGRID"; + + QDir dir(caseDirectory.v()); + if (!dir.exists(fullCaseName)) + { + fullCaseName = caseName + ".GRID"; + if (!dir.exists(fullCaseName)) + { + return false; + } + } + + QString fname = dir.absoluteFilePath(fullCaseName); + + RigReservoir* reservoir = new RigReservoir; + readerInterface = new RifReaderEclipseOutput; + if (!readerInterface->open(fname, reservoir)) + { + delete reservoir; + return false; + } + + m_rigReservoir = reservoir; + } + + progInfo.setProgress(1); + + CVF_ASSERT(m_rigReservoir.notNull()); + CVF_ASSERT(readerInterface.notNull()); + + m_rigReservoir->mainGrid()->results()->setReaderInterface(readerInterface.p()); + + progInfo.setProgressDescription("Computing Faults"); + m_rigReservoir->computeFaults(); + progInfo.setProgressDescription("Computing Cache"); + m_rigReservoir->mainGrid()->computeCachedData(); + + return true; + } + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::ref RimResultReservoir::createMockModel(QString modelName) +{ + cvf::ref mockFileInterface = new RifReaderMockModel; + cvf::ref reservoir = new RigReservoir; + + if (modelName == "Result Mock Debug Model Simple") + { + // Create the mock file interface and and RigSerervoir and set them up. + mockFileInterface->setWorldCoordinates(cvf::Vec3d(10, 10, 10), cvf::Vec3d(20, 20, 20)); + mockFileInterface->setGridPointDimensions(cvf::Vec3st(4, 5, 6)); + mockFileInterface->addLocalGridRefinement(cvf::Vec3st(0, 2, 2), cvf::Vec3st(0, 2, 2), cvf::Vec3st(3, 3, 3)); + + mockFileInterface->open("", reservoir.p()); + { + size_t idx = reservoir->mainGrid()->cellIndexFromIJK(1, 3, 4); + reservoir->mainGrid()->cell(idx).setActive(false); + } + + { + size_t idx = reservoir->mainGrid()->cellIndexFromIJK(2, 2, 3); + reservoir->mainGrid()->cell(idx).setActive(false); + } + } + else if (modelName == "Result Mock Debug Model With Results") + { + mockFileInterface->setWorldCoordinates(cvf::Vec3d(10, 10, 10), cvf::Vec3d(-20, -20, -20)); + mockFileInterface->setGridPointDimensions(cvf::Vec3st(5, 10, 20)); + mockFileInterface->addLocalGridRefinement(cvf::Vec3st(0, 3, 3), cvf::Vec3st(1, 4, 9), cvf::Vec3st(2, 2, 2)); + mockFileInterface->setResultInfo(3, 10); + + mockFileInterface->open("", reservoir.p()); + + // Make a fault + cvf::Vec3d& tmp = reservoir->mainGrid()->nodes()[1]; + tmp += cvf::Vec3d(1, 0, 0); + } + else if (modelName =="Result Mock Debug Model Large With Results") + { + double startX = 0; + double startY = 0; + double startZ = 0; + + double widthX = 6000; + double widthY = 12000; + double widthZ = 500; + + double offsetX = 0; + double offsetY = 0; + double offsetZ = 0; + + // Test code to simulate UTM coordinates + offsetX = 400000; + offsetY = 6000000; + offsetZ = 0; + + + mockFileInterface->setWorldCoordinates(cvf::Vec3d(startX + offsetX, startY + offsetY, startZ + offsetZ), cvf::Vec3d(startX + widthX + offsetX, startY + widthY + offsetY, startZ + widthZ + offsetZ)); + mockFileInterface->setGridPointDimensions(cvf::Vec3st(50, 100, 200)); + mockFileInterface->addLocalGridRefinement(cvf::Vec3st(0, 30, 30), cvf::Vec3st(1, 40, 90), cvf::Vec3st(2, 2, 2)); + mockFileInterface->setResultInfo(3, 10); + + mockFileInterface->open("", reservoir.p()); + + } + + m_rigReservoir = reservoir; + + return mockFileInterface.p(); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimResultReservoir::~RimResultReservoir() +{ + reservoirViews.deleteAllChildObjects(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimResultReservoir::locationOnDisc() const +{ + return caseDirectory; +} + diff --git a/ApplicationCode/ProjectDataModel/RimResultReservoir.h b/ApplicationCode/ProjectDataModel/RimResultReservoir.h new file mode 100644 index 0000000000..30d8a2afd3 --- /dev/null +++ b/ApplicationCode/ProjectDataModel/RimResultReservoir.h @@ -0,0 +1,56 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cvfBase.h" +#include "cvfObject.h" +#include "cafPdmField.h" +#include "cafPdmObject.h" +#include "RimReservoir.h" + + class RifReaderInterface; + +//================================================================================================== +// +// +// +//================================================================================================== +class RimResultReservoir : public RimReservoir +{ + CAF_PDM_HEADER_INIT; + +public: + RimResultReservoir(); + virtual ~RimResultReservoir(); + + + // Fields: + caf::PdmField caseFileName; + caf::PdmField caseDirectory; + + virtual bool openEclipseGridFile(); + + //virtual caf::PdmFieldHandle* userDescriptionField() { return &caseName;} + + virtual QString locationOnDisc() const; + +private: + cvf::ref createMockModel(QString modelName); + +}; diff --git a/ApplicationCode/ProjectDataModel/RimResultSlot.cpp b/ApplicationCode/ProjectDataModel/RimResultSlot.cpp index 6fe93770f4..a00faa1eed 100644 --- a/ApplicationCode/ProjectDataModel/RimResultSlot.cpp +++ b/ApplicationCode/ProjectDataModel/RimResultSlot.cpp @@ -37,7 +37,7 @@ RimResultSlot::RimResultSlot() CAF_PDM_InitFieldNoDefault(&legendConfig, "LegendDefinition", "Legend Definition", "", "", ""); CAF_PDM_InitFieldNoDefault(&m_legendConfigData, "ResultVarLegendDefinitionList", "", "", "", ""); - m_legendConfigData.setHidden(true); + m_legendConfigData.setUiHidden(true); legendConfig = new RimLegendConfig(); } diff --git a/ApplicationCode/ProjectDataModel/RimScriptCollection.cpp b/ApplicationCode/ProjectDataModel/RimScriptCollection.cpp index d7658e15fd..f7e6a2e344 100644 --- a/ApplicationCode/ProjectDataModel/RimScriptCollection.cpp +++ b/ApplicationCode/ProjectDataModel/RimScriptCollection.cpp @@ -24,6 +24,7 @@ #include "cafUtils.h" #include "RIMainWindow.h" #include "RimUiTreeModelPdm.h" +#include "cafPdmUiFilePathEditor.h" CAF_PDM_SOURCE_INIT(RimScriptCollection, "ScriptLocation"); @@ -37,6 +38,8 @@ RimScriptCollection::RimScriptCollection() CAF_PDM_InitFieldNoDefault(&directory, "ScriptDirectory", "Dir", "", "", ""); CAF_PDM_InitFieldNoDefault(&calcScripts, "CalcScripts", "", "", "", ""); CAF_PDM_InitFieldNoDefault(&subDirectories, "SubDirectories", "", "", "", ""); + + directory.setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName()); } //-------------------------------------------------------------------------------------------------- @@ -44,8 +47,8 @@ RimScriptCollection::RimScriptCollection() //-------------------------------------------------------------------------------------------------- RimScriptCollection::~RimScriptCollection() { - calcScripts.deleteChildren(); - subDirectories.deleteChildren(); + calcScripts.deleteAllChildObjects(); + subDirectories.deleteAllChildObjects(); } //-------------------------------------------------------------------------------------------------- @@ -53,7 +56,7 @@ RimScriptCollection::~RimScriptCollection() //-------------------------------------------------------------------------------------------------- void RimScriptCollection::readContentFromDisc() { - calcScripts.deleteChildren(); + calcScripts.deleteAllChildObjects(); if (directory().isEmpty()) { @@ -91,7 +94,7 @@ void RimScriptCollection::readContentFromDisc() { QDir dir(directory); QFileInfoList fileInfoList = dir.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot); - subDirectories.deleteChildren(); + subDirectories.deleteAllChildObjects(); QStringList retFileNames; @@ -162,3 +165,15 @@ void RimScriptCollection::fieldChangedByUi(const caf::PdmFieldHandle *changedFie if (treeModel) treeModel->rebuildUiSubTree(this); } } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimScriptCollection::defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute) +{ + if (field == &directory) + { + caf::PdmUiFilePathEditorAttribute* myAttr = static_cast(attribute); + myAttr->m_selectDirectory = true; + } +} diff --git a/ApplicationCode/ProjectDataModel/RimScriptCollection.h b/ApplicationCode/ProjectDataModel/RimScriptCollection.h index 7f2e823a58..0c030e9be6 100644 --- a/ApplicationCode/ProjectDataModel/RimScriptCollection.h +++ b/ApplicationCode/ProjectDataModel/RimScriptCollection.h @@ -22,6 +22,12 @@ #include "cafPdmObject.h" #include "RimCalcScript.h" +namespace caf +{ + class PdmUiEditorAttribute; + +} + //================================================================================================== /// /// @@ -47,5 +53,6 @@ public: // Methods // Overrides from PdmObject virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue); - +protected: + virtual void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute ); }; diff --git a/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp b/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp index f9ac621fff..8352be54b4 100644 --- a/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp +++ b/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp @@ -31,6 +31,10 @@ #include "RimCalcScript.h" #include "RIApplication.h" #include "RIMainWindow.h" +#include "RimInputProperty.h" +#include "RimInputPropertyCollection.h" +#include "cafPdmField.h" +#include "RimInputReservoir.h" //-------------------------------------------------------------------------------------------------- /// @@ -103,7 +107,7 @@ bool RimUiTreeModelPdm::insertRows(int position, int rows, const QModelIndex &pa //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RimUiTreeModelPdm::removePropertyFilter(const QModelIndex& itemIndex) +bool RimUiTreeModelPdm::deletePropertyFilter(const QModelIndex& itemIndex) { CVF_ASSERT(itemIndex.isValid()); @@ -140,7 +144,7 @@ bool RimUiTreeModelPdm::removePropertyFilter(const QModelIndex& itemIndex) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RimUiTreeModelPdm::removeRangeFilter(const QModelIndex& itemIndex) +bool RimUiTreeModelPdm::deleteRangeFilter(const QModelIndex& itemIndex) { CVF_ASSERT(itemIndex.isValid()); @@ -178,7 +182,7 @@ bool RimUiTreeModelPdm::removeRangeFilter(const QModelIndex& itemIndex) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RimUiTreeModelPdm::removeReservoirView(const QModelIndex& itemIndex) +bool RimUiTreeModelPdm::deleteReservoirView(const QModelIndex& itemIndex) { CVF_ASSERT(itemIndex.isValid()); @@ -354,493 +358,64 @@ void RimUiTreeModelPdm::slotRefreshScriptTree(QString path) } } - - - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RimTreeView::RimTreeView(QWidget *parent /*= 0*/) - : QTreeView(parent) +void RimUiTreeModelPdm::addInputProperty(const QModelIndex& itemIndex, const QStringList& fileNames) { - setHeaderHidden(true); -} + caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(itemIndex); -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimTreeView::contextMenuEvent(QContextMenuEvent* event) -{ - RimUiTreeModelPdm* myModel = dynamic_cast(model()); - if (myModel) + RimInputPropertyCollection* inputPropertyCollection = dynamic_cast(currentItem->dataObject().p()); + CVF_ASSERT(inputPropertyCollection); + + std::vector parentObjects; + inputPropertyCollection->parentObjects(parentObjects); + + + CVF_ASSERT(parentObjects.size() == 1); + + RimInputReservoir* inputReservoir = dynamic_cast(parentObjects[0]); + CVF_ASSERT(inputReservoir); + if (inputReservoir) { - caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(currentIndex()); - if (uiItem && uiItem->dataObject()) - { - // Range filters - if (dynamic_cast(uiItem->dataObject().p())) - { - QMenu menu; - menu.addAction(QString("Show 3D Window"), this, SLOT(slotShowWindow())); - menu.addAction(QString("New View"), this, SLOT(slotAddView())); - menu.addAction(QString("Delete"), this, SLOT(slotDeleteView())); - menu.exec(event->globalPos()); - } - else if (dynamic_cast(uiItem->dataObject().p())) - { - QMenu menu; - menu.addAction(QString("New Range Filter"), this, SLOT(slotAddRangeFilter())); - menu.addAction(QString("Slice I Filter"), this, SLOT(slotAddSliceFilterI())); - menu.addAction(QString("Slice J Filter"), this, SLOT(slotAddSliceFilterJ())); - menu.addAction(QString("Slice K Filter"), this, SLOT(slotAddSliceFilterK())); - menu.exec(event->globalPos()); - } - else if (dynamic_cast(uiItem->dataObject().p())) - { - QMenu menu; - menu.addAction(QString("Insert Range Filter"), this, SLOT(slotAddRangeFilter())); - menu.addAction(QString("Slice I Filter"), this, SLOT(slotAddSliceFilterI())); - menu.addAction(QString("Slice J Filter"), this, SLOT(slotAddSliceFilterJ())); - menu.addAction(QString("Slice K Filter"), this, SLOT(slotAddSliceFilterK())); - menu.addSeparator(); - menu.addAction(QString("Delete"), this, SLOT(slotDeleteRangeFilter())); - - menu.exec(event->globalPos()); - } - else if (dynamic_cast(uiItem->dataObject().p())) - { - - QMenu menu; - menu.addAction(QString("New Property Filter"), this, SLOT(slotAddPropertyFilter())); - menu.exec(event->globalPos()); - } - else if (dynamic_cast(uiItem->dataObject().p())) - { - - QMenu menu; - menu.addAction(QString("Insert Property Filter"), this, SLOT(slotAddPropertyFilter())); - menu.addSeparator(); - menu.addAction(QString("Delete"), this, SLOT(slotDeletePropertyFilter())); - menu.exec(event->globalPos()); - } - else if (dynamic_cast(uiItem->dataObject().p())) - { - RIApplication* app = RIApplication::instance(); - - QMenu menu; - { - QAction* action = menu.addAction(QString("Edit"), this, SLOT(slotEditScript())); - if (app->scriptEditorPath().isEmpty()) - { - action->setEnabled(false); - } - } - menu.addAction(QString("New"), this, SLOT(slotNewScript())); - //menu.addAction(QString("ReadFromFile"), this, SLOT(slotReadScriptContentFromFile())); - menu.addSeparator(); - - { - QAction* action = menu.addAction(QString("Execute"), this, SLOT(slotExecuteScript())); - if (app->octavePath().isEmpty()) - { - action->setEnabled(false); - } - } - - menu.exec(event->globalPos()); - } - } - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimTreeView::slotAddChildItem() -{ - - QModelIndex index = currentIndex(); - QAbstractItemModel* myModel = model(); - - // Insert a single row at the end of the collection of items - int itemCount = myModel->rowCount(index); - if (!myModel->insertRow(itemCount, index)) - return; - - selectionModel()->setCurrentIndex(myModel->index(0, 0, index), QItemSelectionModel::ClearAndSelect); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimTreeView::slotDeleteItem() -{ - QModelIndex index = currentIndex(); - QAbstractItemModel* myModel = model(); - - if (!myModel->removeRow(index.row(), index.parent())) - return; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimTreeView::slotShowWindow() -{ - QModelIndex index = currentIndex(); - RimUiTreeModelPdm* myModel = dynamic_cast(model()); - caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(currentIndex()); - RimReservoirView * riv = NULL; - if (riv = dynamic_cast(uiItem->dataObject().p())) - { - riv->showWindow = true; - bool generateDisplayModel = (riv->viewer() == NULL); - riv->updateViewerWidget(); - if (generateDisplayModel) - { - riv->createDisplayModelAndRedraw(); - } - - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimTreeView::slotDeletePropertyFilter() -{ - RimUiTreeModelPdm* myModel = dynamic_cast(model()); - if (myModel) - { - myModel->removePropertyFilter(currentIndex()); - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimTreeView::slotDeleteRangeFilter() -{ - RimUiTreeModelPdm* myModel = dynamic_cast(model()); - if (myModel) - { - myModel->removeRangeFilter(currentIndex()); - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimTreeView::slotAddPropertyFilter() -{ - RimUiTreeModelPdm* myModel = dynamic_cast(model()); - if (myModel) - { - QModelIndex insertedIndex; - RimCellPropertyFilter* propFilter = myModel->addPropertyFilter(currentIndex(), insertedIndex); - setCurrentIndex(insertedIndex); - if (propFilter) - { - propFilter->parentContainer()->reservoirView()->createDisplayModelAndRedraw(); - } - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimTreeView::slotAddRangeFilter() -{ - RimUiTreeModelPdm* myModel = dynamic_cast(model()); - if (myModel) - { - QModelIndex insertedIndex; - RimCellRangeFilter* newFilter = myModel->addRangeFilter(currentIndex(), insertedIndex); - setCurrentIndex(insertedIndex); - - if (newFilter && newFilter->parentContainer()) - { - newFilter->parentContainer()->reservoirView()->createDisplayModelAndRedraw(); - } - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimTreeView::slotAddSliceFilterI() -{ - RimUiTreeModelPdm* myModel = dynamic_cast(model()); - if (myModel) - { - QModelIndex insertedIndex; - RimCellRangeFilter* rangeFilter = myModel->addRangeFilter(currentIndex(), insertedIndex); - - RimCellRangeFilterCollection* rangeFilterCollection = rangeFilter->parentContainer(); - rangeFilter->name = QString("Slice I (%1)").arg(rangeFilterCollection->rangeFilters().size()); - rangeFilter->cellCountI = 1; - - rangeFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::RANGE_FILTERED); - rangeFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::RANGE_FILTERED_INACTIVE); - - rangeFilterCollection->reservoirView()->createDisplayModelAndRedraw(); - - setCurrentIndex(insertedIndex); - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimTreeView::slotAddSliceFilterJ() -{ - RimUiTreeModelPdm* myModel = dynamic_cast(model()); - if (myModel) - { - QModelIndex insertedIndex; - RimCellRangeFilter* rangeFilter = myModel->addRangeFilter(currentIndex(), insertedIndex); - - RimCellRangeFilterCollection* rangeFilterCollection = rangeFilter->parentContainer(); - rangeFilter->name = QString("Slice J (%1)").arg(rangeFilterCollection->rangeFilters().size()); - rangeFilter->cellCountJ = 1; - - rangeFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::RANGE_FILTERED); - rangeFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::RANGE_FILTERED_INACTIVE); - - rangeFilterCollection->reservoirView()->createDisplayModelAndRedraw(); - - setCurrentIndex(insertedIndex); - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimTreeView::slotAddSliceFilterK() -{ - RimUiTreeModelPdm* myModel = dynamic_cast(model()); - if (myModel) - { - QModelIndex insertedIndex; - RimCellRangeFilter* rangeFilter = myModel->addRangeFilter(currentIndex(), insertedIndex); - - RimCellRangeFilterCollection* rangeFilterCollection = rangeFilter->parentContainer(); - rangeFilter->name = QString("Slice K (%1)").arg(rangeFilterCollection->rangeFilters().size()); - rangeFilter->cellCountK = 1; - - rangeFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::RANGE_FILTERED); - rangeFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::RANGE_FILTERED_INACTIVE); - - rangeFilterCollection->reservoirView()->createDisplayModelAndRedraw(); - - setCurrentIndex(insertedIndex); - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimTreeView::slotReadScriptContentFromFile() -{ - QModelIndex index = currentIndex(); - RimUiTreeModelPdm* myModel = dynamic_cast(model()); - caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(currentIndex()); - if (uiItem) - { - RimCalcScript* calcScript = dynamic_cast(uiItem->dataObject().p()); - if (calcScript) - { - calcScript->readContentFromFile(); - } + inputReservoir->openDataFileSet(fileNames); } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimTreeView::slotEditScript() -{ - QModelIndex index = currentIndex(); - RimUiTreeModelPdm* myModel = dynamic_cast(model()); - caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(currentIndex()); - if (uiItem) - { - RimCalcScript* calcScript = dynamic_cast(uiItem->dataObject().p()); - - RIApplication* app = RIApplication::instance(); - QString scriptEditor = app->scriptEditorPath(); - if (!scriptEditor.isEmpty()) - { - QStringList arguments; - arguments << calcScript->absolutePath; - - QProcess* myProcess = new QProcess(this); - myProcess->start(scriptEditor, arguments); - - if (!myProcess->waitForStarted(1000)) - { - QMessageBox::warning(RIMainWindow::instance(), "Script editor", "Failed to start script editor executable\n" + scriptEditor); - } - } - } + this->rebuildUiSubTree(inputPropertyCollection); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimTreeView::slotNewScript() +void RimUiTreeModelPdm::deleteInputProperty(const QModelIndex& itemIndex) { - QModelIndex index = currentIndex(); - RimUiTreeModelPdm* myModel = dynamic_cast(model()); - caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(currentIndex()); - RimCalcScript* calcScript = NULL; - RimScriptCollection * scriptColl = NULL; + if (!itemIndex.isValid()) return; - calcScript = dynamic_cast(uiItem->dataObject().p()); - scriptColl = dynamic_cast(uiItem->dataObject().p()); - QString fullPathNewScript; + caf::PdmUiTreeItem* uiItem = getTreeItemFromIndex(itemIndex); + if (!uiItem) return; - if (calcScript ) - { - QFileInfo existingScriptFileInfo(calcScript->absolutePath()); - fullPathNewScript = existingScriptFileInfo.absolutePath(); - } - else if (scriptColl) - { - fullPathNewScript = scriptColl->directory(); - } - else - { - return; - } + caf::PdmObject* object = uiItem->dataObject().p(); + RimInputProperty* inputProperty = dynamic_cast(object); + if (!inputProperty) return; - QString fullPathFilenameNewScript; + // Remove item from UI tree model before delete of project data structure + removeRow(itemIndex.row(), itemIndex.parent()); - fullPathFilenameNewScript = fullPathNewScript + "/untitled.m"; - int num= 1; - while (QFileInfo(fullPathFilenameNewScript).exists()) - { - fullPathFilenameNewScript = fullPathNewScript + "/untitled" + QString::number(num) + ".m"; - num++; - } + std::vector parentObjects; + object->parentObjects(parentObjects); + CVF_ASSERT(parentObjects.size() == 1); - RIApplication* app = RIApplication::instance(); - QString scriptEditor = app->scriptEditorPath(); - if (!scriptEditor.isEmpty()) - { - QStringList arguments; - arguments << fullPathFilenameNewScript; + RimInputPropertyCollection* inputPropertyCollection = dynamic_cast(parentObjects[0]); + if (!inputPropertyCollection) return; - QProcess* myProcess = new QProcess(this); - myProcess->start(scriptEditor, arguments); + std::vector parentObjects2; + inputPropertyCollection->parentObjects(parentObjects2); + CVF_ASSERT(parentObjects2.size() == 1); - if (!myProcess->waitForStarted(1000)) - { - QMessageBox::warning(RIMainWindow::instance(), "Script editor", "Failed to start script editor executable\n" + scriptEditor); - } - } + RimInputReservoir* inputReservoir = dynamic_cast(parentObjects2[0]); + if (!inputReservoir) return; + + inputReservoir->removeProperty(inputProperty); + + delete inputProperty; } - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimTreeView::slotExecuteScript() -{ - QModelIndex index = currentIndex(); - RimUiTreeModelPdm* myModel = dynamic_cast(model()); - caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(currentIndex()); - if (uiItem) - { - RimCalcScript* calcScript = dynamic_cast(uiItem->dataObject().p()); - - RIApplication* app = RIApplication::instance(); - QString octavePath = app->octavePath(); - if (!octavePath.isEmpty()) - { - QStringList arguments; - - arguments << calcScript->absolutePath(); - - if (!RIApplication::instance()->launchProcess(octavePath, arguments)) - { - QMessageBox::warning(RIMainWindow::instance(), "Script execution", "Failed to start script executable located at\n" + octavePath); - } - } - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimTreeView::slotAddView() -{ - QModelIndex index = currentIndex(); - RimUiTreeModelPdm* myModel = dynamic_cast(model()); - caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(currentIndex()); - - RimReservoirView* rimView = dynamic_cast(uiItem->dataObject().p()); - if (rimView) - { - QModelIndex insertedIndex; - myModel->addReservoirView(index, insertedIndex); - } - -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimTreeView::slotDeleteView() -{ - RimUiTreeModelPdm* myModel = dynamic_cast(model()); - if (myModel) - { - myModel->removeReservoirView(currentIndex()); - - RIApplication* app = RIApplication::instance(); - app->setActiveReservoirView(NULL); - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RimUiPropertyCreatorPdm::RimUiPropertyCreatorPdm(QObject* parent) - : caf::UiPropertyCreatorPdm(parent) -{ - -} - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimUiPropertyCreatorPdm::uiFields(const caf::PdmObject* object, std::vector& fields) const -{ - const RimCellPropertyFilter* propertyFilter = dynamic_cast(object); - if (propertyFilter) - { - caf::UiPropertyCreatorPdm::uiFields(object, fields); - - CVF_ASSERT(propertyFilter->resultDefinition); - - // Append fields from result definition object - std::vector childFields; - propertyFilter->resultDefinition->fields(childFields); - - size_t i; - for (i = 0; i < childFields.size(); i++) - { - fields.push_back(childFields[i]); - } - } - else - { - caf::UiPropertyCreatorPdm::uiFields(object, fields); - } - - -} - diff --git a/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.h b/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.h index 5e1c2bbcf9..b49a915631 100644 --- a/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.h +++ b/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.h @@ -21,14 +21,13 @@ #include "cafPdmObject.h" #include "cafPdmPointer.h" #include "cafUiTreeModelPdm.h" -#include "RimCellRangeFilter.h" - -#include -#include "cafUiPropertyCreatorPdm.h" class QFileSystemWatcher; class RimCellPropertyFilter; +class RimCellRangeFilter; +class RimReservoirView; +class RimInputProperty; //================================================================================================== /// @@ -45,13 +44,15 @@ public: virtual bool insertRows(int position, int rows, const QModelIndex &parent = QModelIndex()); // Special edit methods - bool removeRangeFilter(const QModelIndex& itemIndex); - bool removePropertyFilter(const QModelIndex& itemIndex); - bool removeReservoirView(const QModelIndex& itemIndex); - + bool deleteRangeFilter(const QModelIndex& itemIndex); + bool deletePropertyFilter(const QModelIndex& itemIndex); + bool deleteReservoirView(const QModelIndex& itemIndex); + void deleteInputProperty(const QModelIndex& itemIndex); + RimCellPropertyFilter* addPropertyFilter(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex); RimCellRangeFilter* addRangeFilter(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex); RimReservoirView* addReservoirView(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex); + void addInputProperty(const QModelIndex& itemIndex, const QStringList& fileNames); void updateScriptPaths(); @@ -64,50 +65,5 @@ private: -//================================================================================================== -/// -/// -//================================================================================================== -class RimTreeView : public QTreeView -{ - Q_OBJECT - -public: - RimTreeView(QWidget *parent = 0); - -protected: - void contextMenuEvent(QContextMenuEvent* event); - -private slots: - void slotAddChildItem(); - void slotDeleteItem(); - void slotShowWindow(); - - void slotAddRangeFilter(); - void slotAddSliceFilterI(); - void slotAddSliceFilterJ(); - void slotAddSliceFilterK(); - - void slotAddPropertyFilter(); - - void slotDeletePropertyFilter(); - void slotDeleteRangeFilter(); - - void slotReadScriptContentFromFile(); - void slotEditScript(); - void slotNewScript(); - void slotExecuteScript(); - - void slotAddView(); - void slotDeleteView(); -}; - -class RimUiPropertyCreatorPdm : public caf::UiPropertyCreatorPdm -{ -public: - RimUiPropertyCreatorPdm(QObject* parent); - - virtual void uiFields(const caf::PdmObject* object, std::vector& fields) const; -}; diff --git a/ApplicationCode/ProjectDataModel/RimUiTreeView.cpp b/ApplicationCode/ProjectDataModel/RimUiTreeView.cpp new file mode 100644 index 0000000000..02b46539f5 --- /dev/null +++ b/ApplicationCode/ProjectDataModel/RimUiTreeView.cpp @@ -0,0 +1,707 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RIStdInclude.h" + +#include "RimUiTreeView.h" +#include "RimUiTreeModelPdm.h" +#include "RimReservoirView.h" +#include "RimCalcScript.h" +#include "RIApplication.h" +#include "RIMainWindow.h" +#include "RimInputPropertyCollection.h" +#include "RimExportInputPropertySettings.h" +#include "RIPreferencesDialog.h" +#include "RifEclipseInputFileTools.h" +#include "RimInputReservoir.h" +#include "RimBinaryExportSettings.h" + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimUiTreeView::RimUiTreeView(QWidget *parent /*= 0*/) + : QTreeView(parent) +{ + setHeaderHidden(true); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimUiTreeView::contextMenuEvent(QContextMenuEvent* event) +{ + RimUiTreeModelPdm* myModel = dynamic_cast(model()); + if (myModel) + { + caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(currentIndex()); + if (uiItem && uiItem->dataObject()) + { + // Range filters + if (dynamic_cast(uiItem->dataObject().p())) + { + QMenu menu; + menu.addAction(QString("Show 3D Window"), this, SLOT(slotShowWindow())); + menu.addAction(QString("New View"), this, SLOT(slotAddView())); + menu.addAction(QString("Delete"), this, SLOT(slotDeleteView())); + menu.exec(event->globalPos()); + } + else if (dynamic_cast(uiItem->dataObject().p())) + { + QMenu menu; + menu.addAction(QString("New Range Filter"), this, SLOT(slotAddRangeFilter())); + menu.addAction(QString("Slice I Filter"), this, SLOT(slotAddSliceFilterI())); + menu.addAction(QString("Slice J Filter"), this, SLOT(slotAddSliceFilterJ())); + menu.addAction(QString("Slice K Filter"), this, SLOT(slotAddSliceFilterK())); + menu.exec(event->globalPos()); + } + else if (dynamic_cast(uiItem->dataObject().p())) + { + QMenu menu; + menu.addAction(QString("Insert Range Filter"), this, SLOT(slotAddRangeFilter())); + menu.addAction(QString("Slice I Filter"), this, SLOT(slotAddSliceFilterI())); + menu.addAction(QString("Slice J Filter"), this, SLOT(slotAddSliceFilterJ())); + menu.addAction(QString("Slice K Filter"), this, SLOT(slotAddSliceFilterK())); + menu.addSeparator(); + menu.addAction(QString("Delete"), this, SLOT(slotDeleteRangeFilter())); + + menu.exec(event->globalPos()); + } + else if (dynamic_cast(uiItem->dataObject().p())) + { + + QMenu menu; + menu.addAction(QString("New Property Filter"), this, SLOT(slotAddPropertyFilter())); + menu.exec(event->globalPos()); + } + else if (dynamic_cast(uiItem->dataObject().p())) + { + + QMenu menu; + menu.addAction(QString("Insert Property Filter"), this, SLOT(slotAddPropertyFilter())); + menu.addSeparator(); + menu.addAction(QString("Delete"), this, SLOT(slotDeletePropertyFilter())); + menu.exec(event->globalPos()); + } + else if (dynamic_cast(uiItem->dataObject().p())) + { + RIApplication* app = RIApplication::instance(); + + QMenu menu; + { + QAction* action = menu.addAction(QString("Edit"), this, SLOT(slotEditScript())); + if (app->scriptEditorPath().isEmpty()) + { + action->setEnabled(false); + } + } + menu.addAction(QString("New"), this, SLOT(slotNewScript())); + //menu.addAction(QString("ReadFromFile"), this, SLOT(slotReadScriptContentFromFile())); + menu.addSeparator(); + + { + QAction* action = menu.addAction(QString("Execute"), this, SLOT(slotExecuteScript())); + if (app->octavePath().isEmpty()) + { + action->setEnabled(false); + } + } + + menu.exec(event->globalPos()); + } + else if (dynamic_cast(uiItem->dataObject().p())) + { + QMenu menu; + menu.addAction(QString("Add Input Property"), this, SLOT(slotAddInputProperty())); + menu.exec(event->globalPos()); + } + else if (dynamic_cast(uiItem->dataObject().p())) + { + QMenu menu; + menu.addAction(QString("Delete"), this, SLOT(slotDeleteObjectFromContainer())); + menu.addAction(QString("Write"), this, SLOT(slotWriteInputProperty())); + menu.exec(event->globalPos()); + } + else if (dynamic_cast(uiItem->dataObject().p())) + { + QMenu menu; + menu.addAction(QString("Write"), this, SLOT(slotWriteBinaryResultAsInputProperty())); + menu.exec(event->globalPos()); + } + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimUiTreeView::slotAddChildItem() +{ + + QModelIndex index = currentIndex(); + QAbstractItemModel* myModel = model(); + + // Insert a single row at the end of the collection of items + int itemCount = myModel->rowCount(index); + if (!myModel->insertRow(itemCount, index)) + return; + + selectionModel()->setCurrentIndex(myModel->index(0, 0, index), QItemSelectionModel::ClearAndSelect); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimUiTreeView::slotDeleteItem() +{ + QModelIndex index = currentIndex(); + QAbstractItemModel* myModel = model(); + + if (!myModel->removeRow(index.row(), index.parent())) + return; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimUiTreeView::slotShowWindow() +{ + QModelIndex index = currentIndex(); + RimUiTreeModelPdm* myModel = dynamic_cast(model()); + caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(currentIndex()); + RimReservoirView * riv = NULL; + if (riv = dynamic_cast(uiItem->dataObject().p())) + { + riv->showWindow = true; + bool generateDisplayModel = (riv->viewer() == NULL); + riv->updateViewerWidget(); + if (generateDisplayModel) + { + riv->createDisplayModelAndRedraw(); + } + + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimUiTreeView::slotDeletePropertyFilter() +{ + RimUiTreeModelPdm* myModel = dynamic_cast(model()); + if (myModel) + { + myModel->deletePropertyFilter(currentIndex()); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimUiTreeView::slotDeleteRangeFilter() +{ + RimUiTreeModelPdm* myModel = dynamic_cast(model()); + if (myModel) + { + myModel->deleteRangeFilter(currentIndex()); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimUiTreeView::slotAddPropertyFilter() +{ + RimUiTreeModelPdm* myModel = dynamic_cast(model()); + if (myModel) + { + QModelIndex insertedIndex; + RimCellPropertyFilter* propFilter = myModel->addPropertyFilter(currentIndex(), insertedIndex); + setCurrentIndex(insertedIndex); + if (propFilter) + { + propFilter->parentContainer()->reservoirView()->createDisplayModelAndRedraw(); + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimUiTreeView::slotAddRangeFilter() +{ + RimUiTreeModelPdm* myModel = dynamic_cast(model()); + if (myModel) + { + QModelIndex insertedIndex; + RimCellRangeFilter* newFilter = myModel->addRangeFilter(currentIndex(), insertedIndex); + setCurrentIndex(insertedIndex); + + if (newFilter && newFilter->parentContainer()) + { + newFilter->parentContainer()->reservoirView()->createDisplayModelAndRedraw(); + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimUiTreeView::slotAddSliceFilterI() +{ + RimUiTreeModelPdm* myModel = dynamic_cast(model()); + if (myModel) + { + QModelIndex insertedIndex; + RimCellRangeFilter* rangeFilter = myModel->addRangeFilter(currentIndex(), insertedIndex); + + RimCellRangeFilterCollection* rangeFilterCollection = rangeFilter->parentContainer(); + rangeFilter->name = QString("Slice I (%1)").arg(rangeFilterCollection->rangeFilters().size()); + rangeFilter->cellCountI = 1; + + rangeFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::RANGE_FILTERED); + rangeFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::RANGE_FILTERED_INACTIVE); + + rangeFilterCollection->reservoirView()->createDisplayModelAndRedraw(); + + setCurrentIndex(insertedIndex); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimUiTreeView::slotAddSliceFilterJ() +{ + RimUiTreeModelPdm* myModel = dynamic_cast(model()); + if (myModel) + { + QModelIndex insertedIndex; + RimCellRangeFilter* rangeFilter = myModel->addRangeFilter(currentIndex(), insertedIndex); + + RimCellRangeFilterCollection* rangeFilterCollection = rangeFilter->parentContainer(); + rangeFilter->name = QString("Slice J (%1)").arg(rangeFilterCollection->rangeFilters().size()); + rangeFilter->cellCountJ = 1; + + rangeFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::RANGE_FILTERED); + rangeFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::RANGE_FILTERED_INACTIVE); + + rangeFilterCollection->reservoirView()->createDisplayModelAndRedraw(); + + setCurrentIndex(insertedIndex); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimUiTreeView::slotAddSliceFilterK() +{ + RimUiTreeModelPdm* myModel = dynamic_cast(model()); + if (myModel) + { + QModelIndex insertedIndex; + RimCellRangeFilter* rangeFilter = myModel->addRangeFilter(currentIndex(), insertedIndex); + + RimCellRangeFilterCollection* rangeFilterCollection = rangeFilter->parentContainer(); + rangeFilter->name = QString("Slice K (%1)").arg(rangeFilterCollection->rangeFilters().size()); + rangeFilter->cellCountK = 1; + + rangeFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::RANGE_FILTERED); + rangeFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::RANGE_FILTERED_INACTIVE); + + rangeFilterCollection->reservoirView()->createDisplayModelAndRedraw(); + + setCurrentIndex(insertedIndex); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimUiTreeView::slotReadScriptContentFromFile() +{ + QModelIndex index = currentIndex(); + RimUiTreeModelPdm* myModel = dynamic_cast(model()); + caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(currentIndex()); + if (uiItem) + { + RimCalcScript* calcScript = dynamic_cast(uiItem->dataObject().p()); + if (calcScript) + { + calcScript->readContentFromFile(); + } + } + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimUiTreeView::slotEditScript() +{ + QModelIndex index = currentIndex(); + RimUiTreeModelPdm* myModel = dynamic_cast(model()); + caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(currentIndex()); + if (uiItem) + { + RimCalcScript* calcScript = dynamic_cast(uiItem->dataObject().p()); + + RIApplication* app = RIApplication::instance(); + QString scriptEditor = app->scriptEditorPath(); + if (!scriptEditor.isEmpty()) + { + QStringList arguments; + arguments << calcScript->absolutePath; + + QProcess* myProcess = new QProcess(this); + myProcess->start(scriptEditor, arguments); + + if (!myProcess->waitForStarted(1000)) + { + QMessageBox::warning(RIMainWindow::instance(), "Script editor", "Failed to start script editor executable\n" + scriptEditor); + } + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimUiTreeView::slotNewScript() +{ + QModelIndex index = currentIndex(); + RimUiTreeModelPdm* myModel = dynamic_cast(model()); + caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(currentIndex()); + RimCalcScript* calcScript = NULL; + RimScriptCollection * scriptColl = NULL; + + calcScript = dynamic_cast(uiItem->dataObject().p()); + scriptColl = dynamic_cast(uiItem->dataObject().p()); + QString fullPathNewScript; + + if (calcScript ) + { + QFileInfo existingScriptFileInfo(calcScript->absolutePath()); + fullPathNewScript = existingScriptFileInfo.absolutePath(); + } + else if (scriptColl) + { + fullPathNewScript = scriptColl->directory(); + } + else + { + return; + } + + QString fullPathFilenameNewScript; + + fullPathFilenameNewScript = fullPathNewScript + "/untitled.m"; + int num= 1; + while (QFileInfo(fullPathFilenameNewScript).exists()) + { + fullPathFilenameNewScript = fullPathNewScript + "/untitled" + QString::number(num) + ".m"; + num++; + } + + RIApplication* app = RIApplication::instance(); + QString scriptEditor = app->scriptEditorPath(); + if (!scriptEditor.isEmpty()) + { + QStringList arguments; + arguments << fullPathFilenameNewScript; + + QProcess* myProcess = new QProcess(this); + myProcess->start(scriptEditor, arguments); + + if (!myProcess->waitForStarted(1000)) + { + QMessageBox::warning(RIMainWindow::instance(), "Script editor", "Failed to start script editor executable\n" + scriptEditor); + } + } +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimUiTreeView::slotExecuteScript() +{ + QModelIndex index = currentIndex(); + RimUiTreeModelPdm* myModel = dynamic_cast(model()); + caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(currentIndex()); + if (uiItem) + { + RimCalcScript* calcScript = dynamic_cast(uiItem->dataObject().p()); + + RIApplication* app = RIApplication::instance(); + QString octavePath = app->octavePath(); + if (!octavePath.isEmpty()) + { + QStringList arguments; + arguments.append("-q"); + arguments << calcScript->absolutePath(); + + if (!RIApplication::instance()->launchProcess(octavePath, arguments)) + { + QMessageBox::warning(RIMainWindow::instance(), "Script execution", "Failed to start script executable located at\n" + octavePath); + } + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimUiTreeView::slotAddView() +{ + QModelIndex index = currentIndex(); + RimUiTreeModelPdm* myModel = dynamic_cast(model()); + caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(currentIndex()); + + RimReservoirView* rimView = dynamic_cast(uiItem->dataObject().p()); + if (rimView) + { + QModelIndex insertedIndex; + myModel->addReservoirView(index, insertedIndex); + } + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimUiTreeView::slotDeleteView() +{ + RimUiTreeModelPdm* myModel = dynamic_cast(model()); + if (myModel) + { + myModel->deleteReservoirView(currentIndex()); + + RIApplication* app = RIApplication::instance(); + app->setActiveReservoirView(NULL); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimUiTreeView::slotSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected) +{ + caf::PdmObject* pdmObject = NULL; + + if (selected.indexes().size() == 1) + { + QModelIndex mi = selected.indexes()[0]; + if (mi.isValid()) + { + RimUiTreeModelPdm* myModel = dynamic_cast(model()); + if (myModel) + { + caf::PdmUiTreeItem* treeItem = myModel->getTreeItemFromIndex(mi); + if (treeItem && treeItem->dataObject()) + { + pdmObject = treeItem->dataObject(); + } + } + } + } + + emit selectedObjectChanged(pdmObject); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimUiTreeView::setModel(QAbstractItemModel* model) +{ + QTreeView::setModel(model); + + if (selectionModel()) + { + connect(selectionModel(), SIGNAL(selectionChanged( const QItemSelection & , const QItemSelection & )), SLOT(slotSelectionChanged( const QItemSelection & , const QItemSelection & ))); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimUiTreeView::slotAddInputProperty() +{ + QStringList fileNames = QFileDialog::getOpenFileNames(this, "Select Eclipse Input Property Files", NULL, "All Files (*.* *)"); + if (fileNames.isEmpty()) return; + + QModelIndex index = currentIndex(); + RimUiTreeModelPdm* myModel = dynamic_cast(model()); + caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(currentIndex()); + + RimInputPropertyCollection* inputPropertyCollection = dynamic_cast(uiItem->dataObject().p()); + if (inputPropertyCollection) + { + myModel->addInputProperty(index, fileNames); + + setCurrentIndex(index); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimUiTreeView::slotDeleteObjectFromContainer() +{ + QModelIndex index = currentIndex(); + if (!index.isValid()) return; + + RimUiTreeModelPdm* myModel = dynamic_cast(model()); + if (myModel) myModel->deleteInputProperty(index); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimUiTreeView::slotWriteInputProperty() +{ + QModelIndex index = currentIndex(); + RimUiTreeModelPdm* myModel = dynamic_cast(model()); + caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(currentIndex()); + + RimInputProperty* inputProperty = dynamic_cast(uiItem->dataObject().p()); + if (!inputProperty) return; + + { + bool isResolved = false; + if (inputProperty->resolvedState == RimInputProperty::RESOLVED || inputProperty->resolvedState == RimInputProperty::RESOLVED_NOT_SAVED) + { + isResolved = true; + } + + if (!isResolved) + { + QMessageBox::warning(RIMainWindow::instance(), "Export failure", "Property is not resolved, and then it is not possible to export the property."); + + return; + } + } + + RimExportInputSettings exportSettings; + exportSettings.eclipseKeyword = inputProperty->eclipseKeyword; + + // Find input reservoir for this property + RimInputReservoir* inputReservoir = NULL; + { + std::vector parentObjects; + inputProperty->parentObjects(parentObjects); + CVF_ASSERT(parentObjects.size() == 1); + + RimInputPropertyCollection* inputPropertyCollection = dynamic_cast(parentObjects[0]); + if (!inputPropertyCollection) return; + + std::vector parentObjects2; + inputPropertyCollection->parentObjects(parentObjects2); + CVF_ASSERT(parentObjects2.size() == 1); + + inputReservoir = dynamic_cast(parentObjects2[0]); + } + + if (!inputReservoir) return; + + { + QString projectFolder; + + RIApplication* app = RIApplication::instance(); + QString projectFileName = app->currentProjectFileName(); + if (!projectFileName.isEmpty()) + { + QFileInfo fi(projectFileName); + projectFolder = fi.absolutePath(); + } + else + { + projectFolder = inputReservoir->locationOnDisc(); + } + + QString outputFileName = projectFolder + "/" + inputProperty->eclipseKeyword; + + exportSettings.fileName = outputFileName; + } + + RIPreferencesDialog preferencesDialog(this, &exportSettings, "Export Eclipse Property to Text File"); + if (preferencesDialog.exec() == QDialog::Accepted) + { + bool isOk = RifEclipseInputFileTools::writePropertyToTextFile(exportSettings.fileName, inputReservoir->reservoirData(), 0, inputProperty->resultName, exportSettings.eclipseKeyword); + if (isOk) + { + inputProperty->fileName = exportSettings.fileName; + inputProperty->eclipseKeyword = exportSettings.eclipseKeyword; + inputProperty->resolvedState = RimInputProperty::RESOLVED; + + inputProperty->updateConnectedEditors(); + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimUiTreeView::slotWriteBinaryResultAsInputProperty() +{ + QModelIndex index = currentIndex(); + RimUiTreeModelPdm* myModel = dynamic_cast(model()); + caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(currentIndex()); + + RimResultSlot* resultSlot = dynamic_cast(uiItem->dataObject().p()); + if (!resultSlot) return; + if (!resultSlot->reservoirView()) return; + if (!resultSlot->reservoirView()->eclipseCase()) return; + if (!resultSlot->reservoirView()->eclipseCase()->reservoirData()) return; + + RimBinaryExportSettings exportSettings; + exportSettings.eclipseKeyword = resultSlot->resultVariable; + + { + QString projectFolder; + + RIApplication* app = RIApplication::instance(); + QString projectFileName = app->currentProjectFileName(); + if (!projectFileName.isEmpty()) + { + QFileInfo fi(projectFileName); + projectFolder = fi.absolutePath(); + } + else + { + projectFolder = resultSlot->reservoirView()->eclipseCase()->locationOnDisc(); + } + + QString outputFileName = projectFolder + "/" + resultSlot->resultVariable; + + exportSettings.fileName = outputFileName; + } + + RIPreferencesDialog preferencesDialog(this, &exportSettings, "Export Binary Eclipse Data to Text File"); + if (preferencesDialog.exec() == QDialog::Accepted) + { + size_t timeStep = resultSlot->reservoirView()->currentTimeStep(); + bool isOk = RifEclipseInputFileTools::writeBinaryResultToTextFile(exportSettings.fileName, resultSlot->reservoirView()->eclipseCase()->reservoirData(), timeStep, resultSlot->resultVariable, exportSettings.eclipseKeyword, exportSettings.undefinedValue); + if (!isOk) + { + QMessageBox::critical(NULL, "File export", "Failed to exported current result to " + exportSettings.fileName); + } + } +} + diff --git a/ApplicationCode/ProjectDataModel/RimUiTreeView.h b/ApplicationCode/ProjectDataModel/RimUiTreeView.h new file mode 100644 index 0000000000..b694faaf7f --- /dev/null +++ b/ApplicationCode/ProjectDataModel/RimUiTreeView.h @@ -0,0 +1,77 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafPdmObject.h" + +#include + +class QItemSelection; + +//================================================================================================== +/// +/// +//================================================================================================== +class RimUiTreeView : public QTreeView +{ + Q_OBJECT + +public: + RimUiTreeView(QWidget *parent = 0); + + virtual void setModel(QAbstractItemModel* model); + +protected: + void contextMenuEvent(QContextMenuEvent* event); + +private slots: + void slotAddChildItem(); + void slotDeleteItem(); + void slotShowWindow(); + + void slotAddRangeFilter(); + void slotAddSliceFilterI(); + void slotAddSliceFilterJ(); + void slotAddSliceFilterK(); + void slotDeleteRangeFilter(); + + void slotAddPropertyFilter(); + void slotDeletePropertyFilter(); + + void slotReadScriptContentFromFile(); + void slotEditScript(); + void slotNewScript(); + void slotExecuteScript(); + + void slotAddView(); + void slotDeleteView(); + + void slotAddInputProperty(); + void slotDeleteObjectFromContainer(); + void slotWriteInputProperty(); + void slotWriteBinaryResultAsInputProperty(); + + void slotSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected); + +signals: + void selectedObjectChanged( caf::PdmObject* pdmObject ); +}; + + + diff --git a/ApplicationCode/ProjectDataModel/RimWell.cpp b/ApplicationCode/ProjectDataModel/RimWell.cpp index e57448dbdb..2dfc2f1b05 100644 --- a/ApplicationCode/ProjectDataModel/RimWell.cpp +++ b/ApplicationCode/ProjectDataModel/RimWell.cpp @@ -49,7 +49,8 @@ RimWell::RimWell() - name.setHidden(true); + name.setUiHidden(true); + name.setUiReadOnly(true); m_reservoirView = NULL; } diff --git a/ApplicationCode/ProjectDataModel/RimWellCollection.cpp b/ApplicationCode/ProjectDataModel/RimWellCollection.cpp index b2272eba67..8e115ecde6 100644 --- a/ApplicationCode/ProjectDataModel/RimWellCollection.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellCollection.cpp @@ -66,7 +66,10 @@ RimWellCollection::RimWellCollection() CAF_PDM_InitField(&wellHeadScaleFactor, "WellHeadScale", 1.0, " Well head scale", "", "", ""); CAF_PDM_InitField(&wellPipeVisibility, "GlobalWellPipeVisibility", WellVisibilityEnum(ALL_ON), "Global well pipe visibility", "", "", ""); - CAF_PDM_InitField(&pipeRadiusScaleFactor, "WellPipeRadiusScale", 0.1, " Pipe radius scale", "", "", ""); + + CAF_PDM_InitField(&pipeRadiusScaleFactor, "WellPipeRadiusScale", 0.1, " Pipe radius scale", "", "", ""); + CAF_PDM_InitField(&pipeCrossSectionVertexCount, "WellPipeVertexCount", 12, "Pipe vertex count", "", "", ""); + pipeCrossSectionVertexCount.setUiHidden(true); CAF_PDM_InitField(&wellCellVisibility, "GlobalWellCellVisibility", WellVisibilityEnum(FORCE_ALL_OFF), "Add cells to range filter", "", "", ""); CAF_PDM_InitField(&showWellCellFences, "ShowWellFences", false, " Use well fence", "", "", ""); @@ -74,6 +77,8 @@ RimWellCollection::RimWellCollection() CAF_PDM_InitField(&wellCellTransparencyLevel, "WellCellTransparency", 0.5, "Well cell transparency", "", "", ""); + CAF_PDM_InitField(&isAutoDetectingBranches, "IsAutoDetectingBranches", true, "Geometry based branch detection", "", "Toggle wether the well pipe visualization will try to detect when a part of the well \nis really a branch, and thus is starting from wellhead", ""); + CAF_PDM_InitFieldNoDefault(&wells, "Wells", "Wells", "", "", ""); m_reservoirView = NULL; @@ -84,7 +89,7 @@ RimWellCollection::RimWellCollection() //-------------------------------------------------------------------------------------------------- RimWellCollection::~RimWellCollection() { - wells.deleteChildren(); + wells.deleteAllChildObjects(); } //-------------------------------------------------------------------------------------------------- @@ -199,7 +204,11 @@ void RimWellCollection::fieldChangedByUi(const caf::PdmFieldHandle* changedField m_reservoirView->createDisplayModelAndRedraw(); } } - else if (&pipeRadiusScaleFactor == changedField || &wellHeadScaleFactor == changedField || &showWellHead == changedField) + else if ( &pipeCrossSectionVertexCount == changedField + || &pipeRadiusScaleFactor == changedField + || &wellHeadScaleFactor == changedField + || &showWellHead == changedField + || &isAutoDetectingBranches == changedField) { if (m_reservoirView) { diff --git a/ApplicationCode/ProjectDataModel/RimWellCollection.h b/ApplicationCode/ProjectDataModel/RimWellCollection.h index 745665fa6a..5f9c04f192 100644 --- a/ApplicationCode/ProjectDataModel/RimWellCollection.h +++ b/ApplicationCode/ProjectDataModel/RimWellCollection.h @@ -68,9 +68,13 @@ public: caf::PdmField wellPipeVisibility; caf::PdmField pipeRadiusScaleFactor; + caf::PdmField pipeCrossSectionVertexCount; + caf::PdmField wellHeadScaleFactor; caf::PdmField showWellHead; + caf::PdmField isAutoDetectingBranches; + caf::PdmPointersField wells; RimWell* findWell(QString name); diff --git a/ApplicationCode/RIStdInclude.h b/ApplicationCode/RIStdInclude.h index 0440e69584..a4427d82f8 100644 --- a/ApplicationCode/RIStdInclude.h +++ b/ApplicationCode/RIStdInclude.h @@ -32,6 +32,5 @@ #include #include -#include #endif // USE_PRECOMPILED_HEADERS diff --git a/ApplicationCode/ReservoirDataModel/RigGridBase.cpp b/ApplicationCode/ReservoirDataModel/RigGridBase.cpp index 3634bb723f..4dbf2cdb0d 100644 --- a/ApplicationCode/ReservoirDataModel/RigGridBase.cpp +++ b/ApplicationCode/ReservoirDataModel/RigGridBase.cpp @@ -250,8 +250,15 @@ double RigGridBase::cellScalar(size_t timeStepIndex, size_t scalarSetIndex, size //-------------------------------------------------------------------------------------------------- double RigGridBase::cellScalar(size_t timeStepIndex, size_t scalarSetIndex, size_t cellIndex) const { - size_t resultIndex = cell(cellIndex).globalActiveIndex(); // !! Assumes results are given for active cells only !! - if (resultIndex == cvf::UNDEFINED_SIZE_T) return HUGE_VAL; + size_t resultIndex = cellIndex; + + bool useGlobalActiveIndex = m_mainGrid->results()->isUsingGlobalActiveIndex(scalarSetIndex); + if (useGlobalActiveIndex) + { + resultIndex = cell(cellIndex).globalActiveIndex(); + if (resultIndex == cvf::UNDEFINED_SIZE_T) return HUGE_VAL; + } + const std::vector< std::vector >& scalarResult = m_mainGrid->results()->cellScalarResults(scalarSetIndex); if (!(timeStepIndex < scalarResult.size() && resultIndex < scalarResult[timeStepIndex].size())) return HUGE_VAL; diff --git a/ApplicationCode/ReservoirDataModel/RigMainGrid.cpp b/ApplicationCode/ReservoirDataModel/RigMainGrid.cpp index 2832e91e1d..29b6333c81 100644 --- a/ApplicationCode/ReservoirDataModel/RigMainGrid.cpp +++ b/ApplicationCode/ReservoirDataModel/RigMainGrid.cpp @@ -31,7 +31,7 @@ RigMainGrid::RigMainGrid(void) m_validCellPositionMax(cvf::Vec3st::UNDEFINED), m_activeCellCount(cvf::UNDEFINED_SIZE_T) { - m_results = new RigReservoirCellResults; + m_results = new RigReservoirCellResults(this); m_activeCellsBoundingBox.add(cvf::Vec3d::ZERO); m_gridIndex = 0; diff --git a/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp b/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp index 702d3ed00e..d24de29abf 100644 --- a/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp +++ b/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp @@ -22,6 +22,11 @@ #include "RigReservoir.h" +/* rand example: guess the number */ +#include +#include +#include + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -250,6 +255,28 @@ void RigReservoirBuilderMock::setWorldCoordinates(cvf::Vec3d minWorldCoordinate, m_maxWorldCoordinate = maxWorldCoordinate; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RigReservoirBuilderMock::inputProperty(RigReservoir* reservoir, const QString& propertyName, std::vector* values) +{ + size_t k; + + /* initialize random seed: */ + srand ( time(NULL) ); + + /* generate secret number: */ + int iSecret = rand() % 20 + 1; + + for (k = 0; k < reservoir->mainGrid()->cellCount(); k++) + { + values->push_back(k * iSecret); + } + + return true; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.h b/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.h index eb474720f4..2d802b03d5 100644 --- a/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.h +++ b/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.h @@ -24,7 +24,6 @@ #include "cvfVector3.h" #include "RigCell.h" #include "RigReservoir.h" -#include "RifReaderInterface.h" class LocalGridRefinement { @@ -58,6 +57,7 @@ public: void populateReservoir(RigReservoir* reservoir); + bool inputProperty(RigReservoir* reservoir, const QString& propertyName, std::vector* values ); bool staticResult(RigReservoir* reservoir, const QString& result, std::vector* values ); bool dynamicResult(RigReservoir* reservoir, const QString& result, size_t stepIndex, std::vector* values ); diff --git a/ApplicationCode/ReservoirDataModel/RigReservoirCellResults.cpp b/ApplicationCode/ReservoirDataModel/RigReservoirCellResults.cpp index 9a936e1457..e97a8423b4 100644 --- a/ApplicationCode/ReservoirDataModel/RigReservoirCellResults.cpp +++ b/ApplicationCode/ReservoirDataModel/RigReservoirCellResults.cpp @@ -20,14 +20,18 @@ #include "RigReservoirCellResults.h" #include "RifReaderInterface.h" +#include "RigMainGrid.h" + +#include //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RigReservoirCellResults::RigReservoirCellResults() +RigReservoirCellResults::RigReservoirCellResults(RigMainGrid* ownerGrid) { - + CVF_ASSERT(ownerGrid != NULL); + m_ownerMainGrid = ownerGrid; } //-------------------------------------------------------------------------------------------------- @@ -117,21 +121,6 @@ void RigReservoirCellResults::minMaxCellScalarValues(size_t scalarResultIndex, s m_maxMinValuesPrTs[scalarResultIndex][timeStepIndex].second= max; } -//-------------------------------------------------------------------------------------------------- -/// Allocates resultCount of result containers and allocates -/// timeStepCount entries for last result container -//-------------------------------------------------------------------------------------------------- -void RigReservoirCellResults::initialize( size_t resultCount, size_t timeStepCount ) -{ - m_cellScalarResults.resize(resultCount); - - if (m_cellScalarResults.size() > 0) - { - m_cellScalarResults[resultCount - 1].resize(timeStepCount); - } - -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -173,74 +162,55 @@ const std::vector< std::vector >& RigReservoirCellResults::cellScalarRes //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -size_t RigReservoirCellResults::loadResultIntoGrid(RimDefines::ResultCatType type, const QString& resultName) +size_t RigReservoirCellResults::findOrLoadScalarResult(RimDefines::ResultCatType type, const QString& resultName) { size_t resultGridIndex = cvf::UNDEFINED_SIZE_T; - resultGridIndex = findGridScalarIndex(type, resultName); - if (resultGridIndex != cvf::UNDEFINED_SIZE_T) return resultGridIndex; + resultGridIndex = findScalarResultIndex(type, resultName); + + if (resultGridIndex == cvf::UNDEFINED_SIZE_T) return cvf::UNDEFINED_SIZE_T; + + if (cellScalarResults(resultGridIndex).size()) return resultGridIndex; + + // Generated and Input properties should always be loaded up front. + CVF_ASSERT(type == RimDefines::STATIC_NATIVE || type == RimDefines::DYNAMIC_NATIVE); if (m_readerInterface.notNull()) { // Add one more result to result container - resultGridIndex = resultCount(); - size_t timeStepCount = m_readerInterface->numTimeSteps(); + size_t timeStepCount = m_resultInfos[resultGridIndex].m_timeStepDates.size(); bool resultLoadingSucess = true; if (type == RimDefines::DYNAMIC_NATIVE && timeStepCount > 0) { - initialize(resultGridIndex + 1, timeStepCount); - if (m_readerInterface->dynamicResults().indexOf(resultName) >= 0) + m_cellScalarResults[resultGridIndex].resize(timeStepCount); + + size_t i; + for (i = 0; i < timeStepCount; i++) { - size_t i; - for (i = 0; i < timeStepCount; i++) - { - std::vector& values = m_cellScalarResults[resultGridIndex][i]; - if (!m_readerInterface->dynamicResult(resultName, i, &values)) - { - resultLoadingSucess = false; - } - } - } - else - { - resultLoadingSucess = false; - } - } - else if (type == RimDefines::STATIC_NATIVE) - { - initialize(resultGridIndex + 1, 1); - - if (m_readerInterface->staticResults().indexOf(resultName) >= 0) - { - std::vector& values = m_cellScalarResults[resultGridIndex][0]; - if (!m_readerInterface->staticResult(resultName, &values)) + std::vector& values = m_cellScalarResults[resultGridIndex][i]; + if (!m_readerInterface->dynamicResult(resultName, i, &values)) { resultLoadingSucess = false; } } - else + } + else if (type == RimDefines::STATIC_NATIVE) + { + m_cellScalarResults[resultGridIndex].resize(1); + + std::vector& values = m_cellScalarResults[resultGridIndex][0]; + if (!m_readerInterface->staticResult(resultName, &values)) { resultLoadingSucess = false; } } - else - { - resultLoadingSucess = false; - } - if (resultLoadingSucess) - { - ResultMapper mapper(type, resultName, resultGridIndex); - m_resultMap.push_back(mapper); - } - else + if (!resultLoadingSucess) { // Remove last scalar result because loading of result failed - m_cellScalarResults.resize(resultGridIndex); - - resultGridIndex = cvf::UNDEFINED_SIZE_T; + m_cellScalarResults[resultGridIndex].clear(); } } @@ -258,10 +228,10 @@ void RigReservoirCellResults::setReaderInterface(RifReaderInterface* readerInter //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -size_t RigReservoirCellResults::findGridScalarIndex(RimDefines::ResultCatType type, const QString& resultName) const +size_t RigReservoirCellResults::findScalarResultIndex(RimDefines::ResultCatType type, const QString& resultName) const { - std::list::const_iterator it; - for (it = m_resultMap.begin(); it != m_resultMap.end(); it++) + std::vector::const_iterator it; + for (it = m_resultInfos.begin(); it != m_resultInfos.end(); it++) { if (it->m_resultType == type && it->m_resultName == resultName) { @@ -272,23 +242,50 @@ size_t RigReservoirCellResults::findGridScalarIndex(RimDefines::ResultCatType ty return cvf::UNDEFINED_SIZE_T; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +size_t RigReservoirCellResults::findScalarResultIndex(const QString& resultName) const +{ + size_t scalarResultIndex = cvf::UNDEFINED_SIZE_T; + + scalarResultIndex = this->findScalarResultIndex(RimDefines::STATIC_NATIVE, resultName); + + if (scalarResultIndex == cvf::UNDEFINED_SIZE_T) + { + scalarResultIndex = this->findScalarResultIndex(RimDefines::DYNAMIC_NATIVE, resultName); + } + + if (scalarResultIndex == cvf::UNDEFINED_SIZE_T) + { + scalarResultIndex = this->findScalarResultIndex(RimDefines::GENERATED, resultName); + } + + if (scalarResultIndex == cvf::UNDEFINED_SIZE_T) + { + scalarResultIndex = this->findScalarResultIndex(RimDefines::INPUT_PROPERTY, resultName); + } + + return scalarResultIndex; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RigReservoirCellResults::loadOrComputeSOIL() { - size_t resultGridIndex = loadResultIntoGrid(RimDefines::DYNAMIC_NATIVE, "SOIL"); + size_t resultGridIndex = findOrLoadScalarResult(RimDefines::DYNAMIC_NATIVE, "SOIL"); if (resultGridIndex == cvf::UNDEFINED_SIZE_T) { - size_t scalarIndexSWAT = loadResultIntoGrid(RimDefines::DYNAMIC_NATIVE, "SWAT"); - size_t scalarIndexSGAS = loadResultIntoGrid(RimDefines::DYNAMIC_NATIVE, "SGAS"); + size_t scalarIndexSWAT = findOrLoadScalarResult(RimDefines::DYNAMIC_NATIVE, "SWAT"); + size_t scalarIndexSGAS = findOrLoadScalarResult(RimDefines::DYNAMIC_NATIVE, "SGAS"); if (scalarIndexSGAS != cvf::UNDEFINED_SIZE_T && scalarIndexSWAT != cvf::UNDEFINED_SIZE_T) { - resultGridIndex = resultCount(); - size_t timeStepCount = m_readerInterface->numTimeSteps(); - initialize(resultGridIndex + 1, timeStepCount); + size_t timeStepCount = m_resultInfos[scalarIndexSWAT].m_timeStepDates.size(); + resultGridIndex = addEmptyScalarResult(RimDefines::DYNAMIC_NATIVE, "SOIL"); + m_cellScalarResults[resultGridIndex].resize(timeStepCount); const std::vector< std::vector >& sgas = cellScalarResults(scalarIndexSGAS); const std::vector< std::vector >& swat = cellScalarResults(scalarIndexSWAT); @@ -307,10 +304,6 @@ void RigReservoirCellResults::loadOrComputeSOIL() soil[timeStepIdx][idx] = 1.0 - sgas[timeStepIdx][idx] - swat[timeStepIdx][idx]; } } - - QString resName = "SOIL"; - ResultMapper mapper(RimDefines::DYNAMIC_NATIVE, resName, resultGridIndex); - m_resultMap.push_back(mapper); } } } @@ -322,15 +315,21 @@ size_t RigReservoirCellResults::findOrLoadScalarResult(const QString& resultName { size_t scalarResultIndex = cvf::UNDEFINED_SIZE_T; - scalarResultIndex = this->loadResultIntoGrid(RimDefines::STATIC_NATIVE, resultName); + scalarResultIndex = this->findOrLoadScalarResult(RimDefines::STATIC_NATIVE, resultName); + if (scalarResultIndex == cvf::UNDEFINED_SIZE_T) { - scalarResultIndex = this->loadResultIntoGrid(RimDefines::DYNAMIC_NATIVE, resultName); + scalarResultIndex = this->findOrLoadScalarResult(RimDefines::DYNAMIC_NATIVE, resultName); } if (scalarResultIndex == cvf::UNDEFINED_SIZE_T) { - scalarResultIndex = this->findGridScalarIndex(RimDefines::GENERATED, resultName); + scalarResultIndex = this->findScalarResultIndex(RimDefines::GENERATED, resultName); + } + + if (scalarResultIndex == cvf::UNDEFINED_SIZE_T) + { + scalarResultIndex = this->findScalarResultIndex(RimDefines::INPUT_PROPERTY, resultName); } return scalarResultIndex; @@ -344,13 +343,13 @@ size_t RigReservoirCellResults::addEmptyScalarResult(RimDefines::ResultCatType t { size_t scalarResultIndex = cvf::UNDEFINED_SIZE_T; - scalarResultIndex = this->findGridScalarIndex(type, resultName); + scalarResultIndex = this->findScalarResultIndex(type, resultName); if (scalarResultIndex == cvf::UNDEFINED_SIZE_T) { scalarResultIndex = this->resultCount(); m_cellScalarResults.push_back(std::vector >()); - ResultMapper mapper(type, resultName, scalarResultIndex); - m_resultMap.push_back(mapper); + ResultInfo resInfo(type, resultName, scalarResultIndex); + m_resultInfos.push_back(resInfo); } return scalarResultIndex; @@ -359,11 +358,11 @@ size_t RigReservoirCellResults::addEmptyScalarResult(RimDefines::ResultCatType t //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -QStringList RigReservoirCellResults::resultNames(RimDefines::ResultCatType resType) +QStringList RigReservoirCellResults::resultNames(RimDefines::ResultCatType resType) const { QStringList varList; - std::list::const_iterator it; - for (it = m_resultMap.begin(); it != m_resultMap.end(); it++) + std::vector::const_iterator it; + for (it = m_resultInfos.begin(); it != m_resultInfos.end(); it++) { if (it->m_resultType == resType ) { @@ -391,3 +390,88 @@ void RigReservoirCellResults::recalculateMinMax(size_t scalarResultIndex) m_maxMinValuesPrTs[scalarResultIndex].clear(); } } + +//-------------------------------------------------------------------------------------------------- +/// Returns whether the result data in question is addressed by Active Cell Index +//-------------------------------------------------------------------------------------------------- +bool RigReservoirCellResults::isUsingGlobalActiveIndex(size_t scalarResultIndex) const +{ + CVF_TIGHT_ASSERT(scalarResultIndex < m_cellScalarResults.size()); + + if (!m_cellScalarResults[scalarResultIndex].size()) return true; + if (m_cellScalarResults[scalarResultIndex][0].size() == m_ownerMainGrid->numActiveCells()) return true; + if (m_cellScalarResults[scalarResultIndex][0].size() == m_ownerMainGrid->cellCount()) return false; + + CVF_TIGHT_ASSERT(false); // Wrong number of results + + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QList RigReservoirCellResults::timeStepDates(size_t scalarResultIndex) const +{ + if (scalarResultIndex < m_resultInfos.size() ) + return m_resultInfos[scalarResultIndex].m_timeStepDates; + else + return QList(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigReservoirCellResults::setTimeStepDates(size_t scalarResultIndex, const QList& dates) +{ + CVF_ASSERT(scalarResultIndex < m_resultInfos.size() ); + + m_resultInfos[scalarResultIndex].m_timeStepDates = dates; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +size_t RigReservoirCellResults::maxTimeStepCount() const +{ + size_t maxTsCount = 0; + for (size_t i = 0; i < m_cellScalarResults.size(); ++i) + { + maxTsCount = m_cellScalarResults[i].size() > maxTsCount ? m_cellScalarResults[i].size() : maxTsCount; + } + return maxTsCount; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RigReservoirCellResults::makeResultNameUnique(const QString& resultNameProposal) const +{ + QString newResultName = resultNameProposal; + size_t resultIndex = cvf::UNDEFINED_SIZE_T; + int nameNum = 1; + int stringLength = newResultName.size(); + while (true) + { + resultIndex = this->findScalarResultIndex(newResultName); + if (resultIndex == cvf::UNDEFINED_SIZE_T) break; + + newResultName.truncate(stringLength); + newResultName += "_" + QString::number(nameNum); + ++nameNum; + } + + return newResultName; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigReservoirCellResults::removeResult(const QString& resultName) +{ + size_t resultIdx = findScalarResultIndex(resultName); + if (resultIdx == cvf::UNDEFINED_SIZE_T) return; + + m_cellScalarResults[resultIdx].clear(); + + m_resultInfos[resultIdx].m_resultType = RimDefines::REMOVED; +} diff --git a/ApplicationCode/ReservoirDataModel/RigReservoirCellResults.h b/ApplicationCode/ReservoirDataModel/RigReservoirCellResults.h index 2ee23f7c60..acbd2ac81e 100644 --- a/ApplicationCode/ReservoirDataModel/RigReservoirCellResults.h +++ b/ApplicationCode/ReservoirDataModel/RigReservoirCellResults.h @@ -19,24 +19,11 @@ #pragma once #include "RimDefines.h" +#include +#include - -class ResultMapper -{ -public: - ResultMapper(RimDefines::ResultCatType resultType, QString resultName, size_t gridScalarResultIndex) - : m_resultType(resultType), - m_resultName(resultName), - m_gridScalarResultIndex(gridScalarResultIndex) - { - } - -public: - RimDefines::ResultCatType m_resultType; - QString m_resultName; - size_t m_gridScalarResultIndex; -}; - +class RifReaderInterface; +class RigMainGrid; //================================================================================================== /// Class containing the results for the complete number of active cells. Both main grid and LGR's @@ -44,36 +31,61 @@ public: class RigReservoirCellResults : public cvf::Object { public: - RigReservoirCellResults(); + RigReservoirCellResults(RigMainGrid* ownerGrid); - void setReaderInterface(RifReaderInterface* readerInterface); - void minMaxCellScalarValues(size_t scalarResultIndex, double& min, double& max); - void minMaxCellScalarValues(size_t scalarResultIndex, size_t timeStepIndex, double& min, double& max); + void setReaderInterface(RifReaderInterface* readerInterface); - size_t resultCount() const; - size_t timeStepCount(size_t scalarResultIndex) const; ///< This one must be modified to ask for a specific resultIndex + // Max and min values of the results + void recalculateMinMax(size_t scalarResultIndex); + void minMaxCellScalarValues(size_t scalarResultIndex, double& min, double& max); + void minMaxCellScalarValues(size_t scalarResultIndex, size_t timeStepIndex, double& min, double& max); - void loadOrComputeSOIL(); - size_t loadResultIntoGrid(RimDefines::ResultCatType type, const QString& resultName); - size_t addEmptyScalarResult(RimDefines::ResultCatType type, const QString& resultName); - QStringList resultNames(RimDefines::ResultCatType type); - size_t findOrLoadScalarResult(const QString& resultName); ///< Simplified search. Assumes unique names across types. - size_t findGridScalarIndex(RimDefines::ResultCatType type, const QString& resultName) const; + // Access meta-information about the results + size_t resultCount() const; + size_t timeStepCount(size_t scalarResultIndex) const; + size_t maxTimeStepCount() const; + QStringList resultNames(RimDefines::ResultCatType type) const; + bool isUsingGlobalActiveIndex(size_t scalarResultIndex) const; + QList timeStepDates(size_t scalarResultIndex) const; + void setTimeStepDates(size_t scalarResultIndex, const QList& dates); - void recalculateMinMax(size_t scalarResultIndex); + // Find or create a slot for the results + size_t findOrLoadScalarResult(RimDefines::ResultCatType type, const QString& resultName); + size_t findOrLoadScalarResult(const QString& resultName); ///< Simplified search. Assumes unique names across types. + size_t findScalarResultIndex(RimDefines::ResultCatType type, const QString& resultName) const; + size_t findScalarResultIndex(const QString& resultName) const; + size_t addEmptyScalarResult(RimDefines::ResultCatType type, const QString& resultName); + QString makeResultNameUnique(const QString& resultNameProposal) const; - std::vector< std::vector > & cellScalarResults(size_t scalarResultIndex); - const std::vector< std::vector >& cellScalarResults(size_t scalarResultIndex) const; + void removeResult(const QString& resultName); -private: - void initialize(size_t resultCount, size_t timeStepCount); + void loadOrComputeSOIL(); + + // Access the results data + std::vector< std::vector > & cellScalarResults(size_t scalarResultIndex); + const std::vector< std::vector >& cellScalarResults(size_t scalarResultIndex) const; private: std::vector< std::vector< std::vector > > m_cellScalarResults; ///< Scalar results for each timestep for each Result index (ResultVariable) std::vector< std::pair > m_maxMinValues; ///< Max min values for each Result index std::vector< std::vector< std::pair > > m_maxMinValuesPrTs; ///< Max min values for each timestep and Result index - std::list m_resultMap; - cvf::ref m_readerInterface; + class ResultInfo + { + public: + ResultInfo(RimDefines::ResultCatType resultType, QString resultName, size_t gridScalarResultIndex) + : m_resultType(resultType), m_resultName(resultName), m_gridScalarResultIndex(gridScalarResultIndex) { } + + public: + RimDefines::ResultCatType m_resultType; + QString m_resultName; + size_t m_gridScalarResultIndex; + QList m_timeStepDates; + }; + + std::vector m_resultInfos; + cvf::ref m_readerInterface; + RigMainGrid* m_ownerMainGrid; + }; diff --git a/ApplicationCode/ReservoirDataModel/RigWellResults.cpp b/ApplicationCode/ReservoirDataModel/RigWellResults.cpp index dd44228cb5..e577d2dc6d 100644 --- a/ApplicationCode/ReservoirDataModel/RigWellResults.cpp +++ b/ApplicationCode/ReservoirDataModel/RigWellResults.cpp @@ -105,25 +105,6 @@ size_t RigWellResults::firstResultTimeStep() const return cvf::UNDEFINED_SIZE_T; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -class cellId -{ -public: - cellId() : - gridIndex(cvf::UNDEFINED_SIZE_T), - cellIndex(cvf::UNDEFINED_SIZE_T) - { } - - cellId(size_t gidx, size_t cIdx) : - gridIndex(gidx), - cellIndex(cIdx) - { } - - size_t gridIndex; - size_t cellIndex; -}; //-------------------------------------------------------------------------------------------------- /// @@ -132,7 +113,7 @@ void RigWellResults::computeStaticWellCellPath() { if (m_wellCellsTimeSteps.size() == 0) return; - std::map < size_t, std::list< cellId > > staticWellBranches; + std::map < size_t, std::list< RigWellResultCell > > staticWellBranches; // Add ResultCell data from the first timestep to the final result. @@ -140,15 +121,12 @@ void RigWellResults::computeStaticWellCellPath() { size_t branchNumber = m_wellCellsTimeSteps[0].m_wellResultBranches[bIdx].m_branchNumber; std::vector& frameCells = m_wellCellsTimeSteps[0].m_wellResultBranches[bIdx].m_wellCells; - - std::list< cellId >& branch = staticWellBranches[branchNumber]; + + std::list< RigWellResultCell >& branch = staticWellBranches[branchNumber]; for(size_t cIdx = 0; cIdx < frameCells.size(); ++cIdx) { - cellId cId; - cId.gridIndex = frameCells[cIdx].m_gridIndex; - cId.cellIndex = frameCells[cIdx].m_gridCellIndex; - branch.push_back(cId); + branch.push_back(frameCells[cIdx]); } } @@ -163,10 +141,10 @@ void RigWellResults::computeStaticWellCellPath() size_t branchNumber = m_wellCellsTimeSteps[tIdx].m_wellResultBranches[bIdx].m_branchNumber; std::vector& resBranch = m_wellCellsTimeSteps[tIdx].m_wellResultBranches[bIdx].m_wellCells; - std::list< cellId >& stBranch = staticWellBranches[branchNumber]; - std::list< cellId >::iterator it; - std::list< cellId >::iterator sStartIt; - std::list< cellId >::iterator sEndIt; + std::list< RigWellResultCell >& stBranch = staticWellBranches[branchNumber]; + std::list< RigWellResultCell >::iterator it; + std::list< RigWellResultCell >::iterator sStartIt; + std::list< RigWellResultCell >::iterator sEndIt; size_t rStartIdx; size_t rEndIdx; @@ -179,17 +157,19 @@ void RigWellResults::computeStaticWellCellPath() // First detect if we have cells on the start of the result frame, that is not in the static frame { sEndIt = stBranch.begin(); - - sGridIdx = sEndIt->gridIndex; - sCellIdx = sEndIt->cellIndex; - bool found = false; - for (rEndIdx = 0; !found && rEndIdx < resBranch.size(); ++rEndIdx) + if (stBranch.size()) { - rGridIdx = resBranch[rEndIdx].m_gridIndex; - rCellIdx = resBranch[rEndIdx].m_gridCellIndex; + sGridIdx = sEndIt->m_gridIndex; + sCellIdx = sEndIt->m_gridCellIndex; - if (sGridIdx == rGridIdx && sCellIdx == rCellIdx) { found = true; break; } + for (rEndIdx = 0; !found && rEndIdx < resBranch.size(); ++rEndIdx) + { + rGridIdx = resBranch[rEndIdx].m_gridIndex; + rCellIdx = resBranch[rEndIdx].m_gridCellIndex; + + if (sGridIdx == rGridIdx && sCellIdx == rCellIdx) { found = true; break; } + } } if (found) @@ -199,9 +179,7 @@ void RigWellResults::computeStaticWellCellPath() // Found cells in start, merge them in for (size_t cIdx = 0; cIdx < rEndIdx; ++cIdx) { - rGridIdx = resBranch[cIdx].m_gridIndex; - rCellIdx = resBranch[cIdx].m_gridCellIndex; - stBranch.insert(sEndIt, cellId(rGridIdx, rCellIdx)); + stBranch.insert(sEndIt, resBranch[cIdx]); } } } @@ -222,10 +200,11 @@ void RigWellResults::computeStaticWellCellPath() // strange ways. A geometric test could make this more robust, but we will // not solve before we see that it actually ends up as a problem - for ( ++sEndIt; sEndIt != stBranch.end() ; ++sEndIt) + if (sEndIt != stBranch.end()) ++sEndIt; + for ( ; sEndIt != stBranch.end() ; ++sEndIt) { - sGridIdx = sEndIt->gridIndex; - sCellIdx = sEndIt->cellIndex; + sGridIdx = sEndIt->m_gridIndex; + sCellIdx = sEndIt->m_gridCellIndex; bool found = false; for (rEndIdx += 1; !found && rEndIdx < resBranch.size(); ++rEndIdx) @@ -243,9 +222,7 @@ void RigWellResults::computeStaticWellCellPath() // Found cell range in result that we do not have in the static result, merge them in for (size_t cIdx = rStartIdx + 1; cIdx < rEndIdx; ++cIdx) { - rGridIdx = resBranch[cIdx].m_gridIndex; - rCellIdx = resBranch[cIdx].m_gridCellIndex; - stBranch.insert(sEndIt, cellId(rGridIdx, rCellIdx)); + stBranch.insert(sEndIt, resBranch[cIdx]); } } } @@ -262,35 +239,31 @@ void RigWellResults::computeStaticWellCellPath() // Then add cells from the end of the resultpath not present in the static path for (size_t cIdx = rEndIdx + 1; cIdx < resBranch.size(); ++cIdx) { - rGridIdx = resBranch[cIdx].m_gridIndex; - rCellIdx = resBranch[cIdx].m_gridCellIndex; - stBranch.push_back(cellId(rGridIdx, rCellIdx)); + stBranch.push_back(resBranch[cIdx]); } } } // Populate the static well info - std::map < size_t, std::list< cellId > >::iterator bIt; + std::map < size_t, std::list< RigWellResultCell > >::iterator bIt; m_staticWellCells.m_wellResultBranches.clear(); m_staticWellCells.m_wellHead = m_wellCellsTimeSteps[0].m_wellHead; - for (bIt= staticWellBranches.begin(); bIt != staticWellBranches.end(); ++bIt) + for (bIt = staticWellBranches.begin(); bIt != staticWellBranches.end(); ++bIt) { RigWellResultBranch rigBranch; rigBranch.m_branchNumber = bIt->first; - std::list< cellId >& branch = bIt->second; - std::list< cellId >::iterator cIt; + std::list< RigWellResultCell >& branch = bIt->second; + std::list< RigWellResultCell >::iterator cIt; for (cIt = branch.begin(); cIt != branch.end(); ++cIt) { - RigWellResultCell rwc; - rwc.m_gridIndex = cIt->gridIndex; - rwc.m_gridCellIndex = cIt->cellIndex; - - rigBranch.m_wellCells.push_back(rwc); + RigWellResultCell rwc = *cIt; + rwc.m_isOpen = false; // Reset the dynamic property + rigBranch.m_wellCells.push_back(*cIt); } m_staticWellCells.m_wellResultBranches.push_back(rigBranch); diff --git a/ApplicationCode/ReservoirDataModel/RigWellResults.h b/ApplicationCode/ReservoirDataModel/RigWellResults.h index 378c88f7eb..9c247c4cf9 100644 --- a/ApplicationCode/ReservoirDataModel/RigWellResults.h +++ b/ApplicationCode/ReservoirDataModel/RigWellResults.h @@ -26,14 +26,17 @@ struct RigWellResultCell RigWellResultCell() : m_gridIndex(cvf::UNDEFINED_SIZE_T), m_gridCellIndex(cvf::UNDEFINED_SIZE_T), - m_isOpen(false), - m_isTemporarilyOut(false) + m_branchId(-1), + m_segmentId(-1), + m_isOpen(false) { } size_t m_gridIndex; size_t m_gridCellIndex; //< Index to cell which is included in the well + int m_branchId; + int m_segmentId; + bool m_isOpen; //< Marks the well as open or closed as of Eclipse simulation - bool m_isTemporarilyOut; //< Marks the cell as not member of the well at the current time step, (but it is a member at some other time step) }; struct RigWellResultBranch @@ -57,6 +60,28 @@ public: m_productionType(UNDEFINED_PRODUCTION_TYPE) { } + const RigWellResultCell* findResultCell(size_t gridIndex, size_t gridCellIndex) const + { + if (m_wellHead.m_gridCellIndex == gridCellIndex && m_wellHead.m_gridIndex == gridIndex ) + { + return &m_wellHead; + } + + for (size_t wb = 0; wb < m_wellResultBranches.size(); ++wb) + { + for (size_t wc = 0; wc < m_wellResultBranches[wb].m_wellCells.size(); ++wc) + { + if ( m_wellResultBranches[wb].m_wellCells[wc].m_gridCellIndex == gridCellIndex + && m_wellResultBranches[wb].m_wellCells[wc].m_gridIndex == gridIndex ) + { + return &(m_wellResultBranches[wb].m_wellCells[wc]); + } + } + } + + return NULL; + } + WellProductionType m_productionType; bool m_isOpen; RigWellResultCell m_wellHead; diff --git a/ApplicationCode/Resources/EclipseInput48x48.png b/ApplicationCode/Resources/EclipseInput48x48.png new file mode 100644 index 0000000000..690cca641c Binary files /dev/null and b/ApplicationCode/Resources/EclipseInput48x48.png differ diff --git a/ApplicationCode/Resources/ResInsight.qrc b/ApplicationCode/Resources/ResInsight.qrc index b90681e527..2028c1cff5 100644 --- a/ApplicationCode/Resources/ResInsight.qrc +++ b/ApplicationCode/Resources/ResInsight.qrc @@ -22,7 +22,8 @@ WellCollection.png octave.png Folder.png - + EclipseInput48x48.png + fs_CellFace.glsl vs_CellFace.glsl diff --git a/ApplicationCode/Resources/vs_CellFace.glsl b/ApplicationCode/Resources/vs_CellFace.glsl index 0ef2462fb1..026f690ddc 100644 --- a/ApplicationCode/Resources/vs_CellFace.glsl +++ b/ApplicationCode/Resources/vs_CellFace.glsl @@ -31,12 +31,12 @@ varying vec3 v_ecPosition; varying vec3 v_ecNormal; // End native vz stuff -#define POS_I 0 -#define NEG_I 1 -#define POS_J 2 -#define NEG_J 3 -#define POS_K 4 -#define NEG_K 5 +#define POS_I 0.0 +#define NEG_I 1.0 +#define POS_J 2.0 +#define NEG_J 3.0 +#define POS_K 4.0 +#define NEG_K 5.0 // // 7---------6 @@ -60,7 +60,7 @@ varying vec3 v_ecNormal; vec4 getColorFromTextureCoord(float textureCoord, vec4 cellColor) { - if (textureCoord < 0) + if (textureCoord < 0.0) return cellColor; else return texture2D(u_edgeTexture2D, vec2(textureCoord, 0.5f )); @@ -73,7 +73,7 @@ void main() { v_localCoord = a_localCoord; - if ( a_colorCell < 0) + if ( a_colorCell < 0.0) v_cellColor = vec4(0.75, 0.75, 0.75, 1); // Light grayish else v_cellColor = texture2D(u_cellTexture2D, vec2( a_colorCell, 0.5f)); diff --git a/ApplicationCode/SocketInterface/RiaSocketServer.cpp b/ApplicationCode/SocketInterface/RiaSocketServer.cpp index 8c4c2395cb..6c95df0b28 100644 --- a/ApplicationCode/SocketInterface/RiaSocketServer.cpp +++ b/ApplicationCode/SocketInterface/RiaSocketServer.cpp @@ -30,6 +30,9 @@ #include "RigReservoir.h" #include "RigReservoirCellResults.h" #include +#include "RimInputProperty.h" +#include "RimInputReservoir.h" +#include "RimUiTreeModelPdm.h" //-------------------------------------------------------------------------------------------------- /// @@ -118,6 +121,7 @@ void RiaSocketServer::handleClientConnection(QTcpSocket* clientToHandle) m_currentTimeStepToRead = 0; m_currentReservoir = NULL; m_currentScalarIndex = cvf::UNDEFINED_SIZE_T; + m_currentPropertyName = ""; connect(m_currentClient, SIGNAL(disconnected()), this, SLOT(slotCurrentClientDisconnected())); @@ -211,8 +215,9 @@ void RiaSocketServer::slotReadCommand() bool isGetProperty = args[0] == "GetProperty"; // GetProperty [casename/index] PropertyName bool isSetProperty = args[0] == "SetProperty"; // SetProperty [casename/index] PropertyName bool isGetCellInfo = args[0] == "GetActiveCellInfo"; // GetActiveCellInfo [casename/index] + bool isGetGridDim = args[0] == "GetMainGridDimensions"; // GetMainGridDimensions [casename/index] - if (!(isGetProperty || isSetProperty || isGetCellInfo)) + if (!(isGetProperty || isSetProperty || isGetCellInfo || isGetGridDim)) { m_errorMessageDialog->showMessage(tr("ResInsight SocketServer: \n") + tr("Unknown command: %1").arg(args[0].data())); return; @@ -236,7 +241,7 @@ void RiaSocketServer::slotReadCommand() propertyName = args[2]; } } - else if (isGetCellInfo) + else if (isGetCellInfo || isGetGridDim) { if (args.size() > 1) { @@ -272,6 +277,7 @@ void RiaSocketServer::slotReadCommand() { scalarResultFrames = &(reservoir->reservoirData()->mainGrid()->results()->cellScalarResults(scalarResultIndex)); m_currentScalarIndex = scalarResultIndex; + m_currentPropertyName = propertyName; } } @@ -374,6 +380,23 @@ void RiaSocketServer::slotReadCommand() #endif } } + else if (isGetGridDim) + { + // Write data back to octave: I, J, K dimensions + + size_t iCount = 0; + size_t jCount = 0; + size_t kCount = 0; + + if (reservoir && reservoir->reservoirData() && reservoir->reservoirData()->mainGrid()) + { + iCount = reservoir->reservoirData()->mainGrid()->cellCountI(); + jCount = reservoir->reservoirData()->mainGrid()->cellCountJ(); + kCount = reservoir->reservoirData()->mainGrid()->cellCountK(); + } + + socketStream << (quint64)iCount << (quint64)jCount << (quint64)kCount; + } } //-------------------------------------------------------------------------------------------------- @@ -402,20 +425,23 @@ void RiaSocketServer::slotReadPropertyData() // Check if a complete timestep is available, return and whait for readyRead() if not if (m_currentClient->bytesAvailable() < (int)m_bytesPerTimeStepToRead) return; - size_t activeCellCount = m_bytesPerTimeStepToRead / sizeof(double); + size_t cellCountFromOctave = m_bytesPerTimeStepToRead / sizeof(double); size_t gridActiveCellCount = m_currentReservoir->reservoirData()->mainGrid()->numActiveCells(); - if (gridActiveCellCount != activeCellCount) + size_t gridTotalCellCount = m_currentReservoir->reservoirData()->mainGrid()->cellCount(); + + if (cellCountFromOctave != gridActiveCellCount && cellCountFromOctave != gridTotalCellCount) { - m_errorMessageDialog->showMessage(tr("ResInsight SocketServer: \n") + tr("The number of active cells in the data coming from octave does not match the case") + ":\"" + m_currentReservoir->caseName() + "\"\n" - " Octave: " + QString::number(activeCellCount) + "\n" - " " + m_currentReservoir->caseName() + ": " + QString::number(gridActiveCellCount)); + m_errorMessageDialog->showMessage(tr("ResInsight SocketServer: \n") + + tr("The number of cells in the data coming from octave does not match the case") + ":\"" + m_currentReservoir->caseName() + "\"\n" + " Octave: " + QString::number(cellCountFromOctave) + "\n" + " " + m_currentReservoir->caseName() + ": Active cell count: " + QString::number(gridActiveCellCount) + " Total cell count: " + QString::number(gridTotalCellCount)) ; - activeCellCount = 0; - m_invalidActiveCellCountDetected = true; - m_currentClient->abort(); + cellCountFromOctave = 0; + m_invalidActiveCellCountDetected = true; + m_currentClient->abort(); - return; + return; } // Make sure the size of the retreiving container is correct. @@ -423,7 +449,7 @@ void RiaSocketServer::slotReadPropertyData() m_scalarResultsToAdd->resize(m_timeStepCountToRead); for (size_t tIdx = 0; tIdx < m_timeStepCountToRead; ++tIdx) { - m_scalarResultsToAdd->at(tIdx).resize(activeCellCount, HUGE_VAL); + m_scalarResultsToAdd->at(tIdx).resize(cellCountFromOctave, HUGE_VAL); } // Read available complete timestepdata @@ -435,7 +461,7 @@ void RiaSocketServer::slotReadPropertyData() #if 1 // Use raw data transfer. Faster. bytesRead = m_currentClient->read((char*)(internalMatrixData), m_bytesPerTimeStepToRead); #else - for (size_t cIdx = 0; cIdx < activeCellCount; ++cIdx) + for (size_t cIdx = 0; cIdx < cellCountFromOctave; ++cIdx) { socketStream >> internalMatrixData[cIdx]; @@ -456,6 +482,25 @@ void RiaSocketServer::slotReadPropertyData() { if (m_currentReservoir != NULL) { + // Create a new input property if we have an input reservoir + RimInputReservoir* inputRes = dynamic_cast(m_currentReservoir); + if (inputRes) + { + RimInputProperty* inputProperty = NULL; + inputProperty = inputRes->m_inputPropertyCollection->findInputProperty(m_currentPropertyName); + if (!inputProperty) + { + inputProperty = new RimInputProperty; + inputProperty->resultName = m_currentPropertyName; + inputProperty->eclipseKeyword = ""; + inputProperty->fileName = ""; + inputRes->m_inputPropertyCollection->inputProperties.push_back(inputProperty); + RimUiTreeModelPdm* treeModel = RIMainWindow::instance()->uiPdmModel(); + treeModel->rebuildUiSubTree(inputRes->m_inputPropertyCollection()); + } + inputProperty->resolvedState = RimInputProperty::RESOLVED_NOT_SAVED; + } + if( m_currentScalarIndex != cvf::UNDEFINED_SIZE_T && m_currentReservoir->reservoirData() && m_currentReservoir->reservoirData()->mainGrid() && @@ -501,6 +546,7 @@ void RiaSocketServer::slotCurrentClientDisconnected() m_currentTimeStepToRead = 0; m_currentReservoir = NULL; m_currentScalarIndex = cvf::UNDEFINED_SIZE_T; + m_currentPropertyName = ""; m_invalidActiveCellCountDetected = false; QTcpSocket *newClient = m_tcpServer->nextPendingConnection(); diff --git a/ApplicationCode/SocketInterface/RiaSocketServer.h b/ApplicationCode/SocketInterface/RiaSocketServer.h index d32fae07a1..86519b94c9 100644 --- a/ApplicationCode/SocketInterface/RiaSocketServer.h +++ b/ApplicationCode/SocketInterface/RiaSocketServer.h @@ -62,6 +62,7 @@ private: std::vector< std::vector >* m_scalarResultsToAdd; RimReservoir* m_currentReservoir; size_t m_currentScalarIndex; + QString m_currentPropertyName; bool m_invalidActiveCellCountDetected; }; diff --git a/ApplicationCode/UserInterface/RIMainWindow.cpp b/ApplicationCode/UserInterface/RIMainWindow.cpp index c425c67992..22a29523ca 100644 --- a/ApplicationCode/UserInterface/RIMainWindow.cpp +++ b/ApplicationCode/UserInterface/RIMainWindow.cpp @@ -27,21 +27,19 @@ #include "RIPreferences.h" #include "RIPreferencesDialog.h" -#include "RifReaderInterface.h" #include "RigReservoir.h" +#include "RigReservoirCellResults.h" #include "RimReservoir.h" #include "RimUiTreeModelPdm.h" #include "cvfqtBasicAboutDialog.h" #include "cafUtils.h" -#include "cafUiPropertyCreatorPdm.h" #include "cafFrameAnimationControl.h" #include "cafAnimationToolBar.h" -#include "qttreepropertybrowser.h" -#include "qtbuttonpropertybrowser.h" -#include "qtgroupboxpropertybrowser.h" +#include "cafPdmUiPropertyView.h" +#include "RimUiTreeView.h" @@ -61,7 +59,6 @@ RIMainWindow* RIMainWindow::sm_mainWindowInstance = NULL; //-------------------------------------------------------------------------------------------------- RIMainWindow::RIMainWindow() : m_treeView(NULL), - m_uiManagerPdm(NULL), m_pdmRoot(NULL), m_mainViewer(NULL), m_windowMenu(NULL) @@ -133,6 +130,11 @@ void RIMainWindow::cleanupGuiBeforeProjectClose() { setPdmRoot(NULL); setResultInfo(""); + + if (m_pdmUiPropertyView) + { + m_pdmUiPropertyView->showProperties(NULL); + } m_processMonitor->startMonitorWorkProcess(NULL); } @@ -179,12 +181,14 @@ void RIMainWindow::createActions() { // File actions m_openAction = new QAction(QIcon(":/AppLogo48x48.png"), "&Open Eclipse Case", this); + m_openInputEclipseFileAction= new QAction(QIcon(":/EclipseInput48x48.png"), "&Open Input Eclipse Case", this); m_openProjectAction = new QAction(style()->standardIcon(QStyle::SP_DirOpenIcon), "&Open Project", this); m_openLastUsedProjectAction = new QAction("Open &Last Used Project", this); m_mockModelAction = new QAction("&Mock Model", this); m_mockResultsModelAction = new QAction("Mock Model With &Results", this); m_mockLargeResultsModelAction = new QAction("Large Mock Model", this); + m_mockInputModelAction = new QAction("Input Mock Model", this); m_saveProjectAction = new QAction(QIcon(":/Save.png"), "&Save Project", this); m_saveProjectAsAction = new QAction(QIcon(":/Save.png"), "Save Project &As", this); @@ -192,13 +196,15 @@ void RIMainWindow::createActions() m_closeAction = new QAction("&Close", this); m_exitAction = new QAction("E&xit", this); - connect(m_openAction, SIGNAL(triggered()), SLOT(slotOpenFile())); + connect(m_openAction, SIGNAL(triggered()), SLOT(slotOpenBinaryGridFiles())); + connect(m_openInputEclipseFileAction,SIGNAL(triggered()), SLOT(slotOpenInputFiles())); connect(m_openProjectAction, SIGNAL(triggered()), SLOT(slotOpenProject())); connect(m_openLastUsedProjectAction,SIGNAL(triggered()), SLOT(slotOpenLastUsedProject())); connect(m_mockModelAction, SIGNAL(triggered()), SLOT(slotMockModel())); connect(m_mockResultsModelAction, SIGNAL(triggered()), SLOT(slotMockResultsModel())); connect(m_mockLargeResultsModelAction, SIGNAL(triggered()), SLOT(slotMockLargeResultsModel())); + connect(m_mockInputModelAction, SIGNAL(triggered()), SLOT(slotInputMockModel())); connect(m_saveProjectAction, SIGNAL(triggered()), SLOT(slotSaveProject())); connect(m_saveProjectAsAction, SIGNAL(triggered()), SLOT(slotSaveProjectAs())); @@ -245,6 +251,8 @@ void RIMainWindow::createActions() m_performanceHud->setCheckable(true); connect(m_performanceHud, SIGNAL(triggered(bool)), SLOT(slotShowPerformanceInfo(bool))); + m_newPropertyView = new QAction("New Property View", this); + connect(m_newPropertyView, SIGNAL(triggered()), SLOT(slotNewObjectPropertyView())); // Help actions m_aboutAction = new QAction("&About", this); @@ -260,6 +268,7 @@ void RIMainWindow::createMenus() // File menu QMenu* fileMenu = menuBar()->addMenu("&File"); fileMenu->addAction(m_openAction); + fileMenu->addAction(m_openInputEclipseFileAction); fileMenu->addAction(m_openProjectAction); fileMenu->addAction(m_openLastUsedProjectAction); @@ -298,9 +307,11 @@ void RIMainWindow::createMenus() debugMenu->addAction(m_mockModelAction); debugMenu->addAction(m_mockResultsModelAction); debugMenu->addAction(m_mockLargeResultsModelAction); + debugMenu->addAction(m_mockInputModelAction); debugMenu->addSeparator(); debugMenu->addAction(m_debugUseShaders); debugMenu->addAction(m_performanceHud); + debugMenu->addAction(m_newPropertyView); connect(debugMenu, SIGNAL(aboutToShow()), SLOT(slotRefreshDebugActions())); @@ -323,6 +334,7 @@ void RIMainWindow::createToolBars() m_standardToolBar->setObjectName(m_standardToolBar->windowTitle()); m_standardToolBar->addAction(m_openAction); + m_standardToolBar->addAction(m_openInputEclipseFileAction); m_standardToolBar->addAction(m_openProjectAction); //m_standardToolBar->addAction(m_openLastUsedProjectAction); m_standardToolBar->addAction(m_saveProjectAction); @@ -352,42 +364,19 @@ void RIMainWindow::createToolBars() void RIMainWindow::createDockPanels() { - m_uiManagerPdm = new RimUiPropertyCreatorPdm(this); - { QDockWidget* dockWidget = new QDockWidget("Project", this); dockWidget->setObjectName("dockWidget"); dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - m_treeView = new RimTreeView(dockWidget); + m_treeView = new RimUiTreeView(dockWidget); + m_treeView->setModel(m_treeModelPdm); + dockWidget->setWidget(m_treeView); addDockWidget(Qt::LeftDockWidgetArea, dockWidget); } - { - QDockWidget* dockWidget = new QDockWidget("Properties", this); - dockWidget->setObjectName("dockWidget"); - dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - -#if 0 - QtButtonPropertyBrowser* treePropertyBrowser = new QtButtonPropertyBrowser(dockWidget); -#elif 1 - QtGroupBoxPropertyBrowser * treePropertyBrowser = new QtGroupBoxPropertyBrowser (dockWidget); - -#else - QtTreePropertyBrowser* treePropertyBrowser = new QtTreePropertyBrowser(dockWidget); - treePropertyBrowser->setPropertiesWithoutValueMarked(true); - treePropertyBrowser->setRootIsDecorated(true); - treePropertyBrowser->setResizeMode(QtTreePropertyBrowser::ResizeToContents); -#endif - m_uiManagerPdm->setPropertyBrowser(treePropertyBrowser); - - dockWidget->setWidget(treePropertyBrowser); - - addDockWidget(Qt::LeftDockWidgetArea, dockWidget); - } - { QDockWidget* dockPanel = new QDockWidget("Result Info", this); dockPanel->setObjectName("dockResultInfoPanel"); @@ -408,6 +397,19 @@ void RIMainWindow::createDockPanels() addDockWidget(Qt::BottomDockWidgetArea, dockPanel); } + { + QDockWidget* dockWidget = new QDockWidget("Properties", this); + dockWidget->setObjectName("dockWidget"); + dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + + m_pdmUiPropertyView = new caf::PdmUiPropertyView(dockWidget); + dockWidget->setWidget(m_pdmUiPropertyView); + + connect(m_treeView, SIGNAL(selectedObjectChanged( caf::PdmObject* )), m_pdmUiPropertyView, SLOT(showProperties( caf::PdmObject* ))); + + addDockWidget(Qt::LeftDockWidgetArea, dockWidget); + } + setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); setCorner(Qt::BottomRightCorner, Qt::BottomDockWidgetArea); } @@ -534,13 +536,18 @@ void RIMainWindow::refreshAnimationActions() { enableAnimControls = true; - if (app->activeReservoirView()->eclipseCase() && app->activeReservoirView()->eclipseCase()->fileInterface()) + if (app->activeReservoirView()->gridCellResults()) { if (app->activeReservoirView()->cellResult()->hasDynamicResult() || app->activeReservoirView()->propertyFilterCollection()->hasActiveDynamicFilters() || app->activeReservoirView()->wellCollection()->hasVisibleWellPipes()) { - timeStepStrings = app->activeReservoirView()->eclipseCase()->fileInterface()->timeStepText(); + QList timeStepDates = app->activeReservoirView()->gridCellResults()->timeStepDates(0); + int i; + for (i = 0; i < timeStepDates.size(); i++) + { + timeStepStrings += timeStepDates[i].toString("dd.MMM yyyy"); + } currentTimeStepIndex = RIApplication::instance()->activeReservoirView()->currentTimeStep(); } else @@ -594,24 +601,49 @@ void RIMainWindow::slotAbout() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RIMainWindow::slotOpenFile() +void RIMainWindow::slotOpenBinaryGridFiles() { if (checkForDocumentModifications()) { #ifdef USE_ECL_LIB - QString fileName = QFileDialog::getOpenFileName(this, "Open Eclipse File", NULL, "Eclipse Grid Files (*.GRID *.EGRID)"); + QStringList fileNames = QFileDialog::getOpenFileNames(this, "Open Eclipse File", NULL, "Eclipse Grid Files (*.GRID *.EGRID)"); #else - QString fileName = "dummy"; + QStringList fileNames; + fileNames << "dummy"; #endif - if (fileName.isEmpty()) return; - RIApplication* app = RIApplication::instance(); - app->openEclipseCaseFromFile(fileName); - } - //m_mainViewer->setDefaultView(); + int i; + for (i = 0; i < fileNames.size(); i++) + { + QString fileName = fileNames[i]; + + if (!fileNames.isEmpty()) + { + app->openEclipseCaseFromFile(fileName); + } + } + } } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RIMainWindow::slotOpenInputFiles() +{ + if (checkForDocumentModifications()) + { + QStringList fileNames = QFileDialog::getOpenFileNames(this, "Open Eclipse Input Files", NULL, "Eclipse Input Files and Input Properties (*.GRDECL *)"); + + if (fileNames.isEmpty()) return; + + RIApplication* app = RIApplication::instance(); + app->openInputEclipseCase("Eclipse Input Files", fileNames); + } +} + + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -671,6 +703,16 @@ void RIMainWindow::slotMockLargeResultsModel() } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RIMainWindow::slotInputMockModel() +{ + RIApplication* app = RIApplication::instance(); + app->createInputMockModel(); +} + + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -805,21 +847,11 @@ void RIMainWindow::setPdmRoot(caf::PdmObject* pdmRoot) caf::PdmUiTreeItem* treeItemRoot = caf::UiTreeItemBuilderPdm::buildViewItems(NULL, -1, m_pdmRoot); m_treeModelPdm->setRoot(treeItemRoot); - m_treeView->setModel(m_treeModelPdm); m_treeView->expandAll(); - if (treeItemRoot) + if (treeItemRoot && m_treeView->selectionModel()) { - m_uiManagerPdm->setModel(m_treeModelPdm, m_treeView->selectionModel()); - - if (m_treeView->selectionModel()) - { - connect(m_treeView->selectionModel(), SIGNAL(currentChanged ( const QModelIndex & , const QModelIndex & )), SLOT(slotCurrentChanged( const QModelIndex & , const QModelIndex & ))); - } - } - else - { - m_uiManagerPdm->setModel(NULL, NULL); + connect(m_treeView->selectionModel(), SIGNAL(currentChanged ( const QModelIndex & , const QModelIndex & )), SLOT(slotCurrentChanged( const QModelIndex & , const QModelIndex & ))); } } @@ -1014,7 +1046,7 @@ void RIMainWindow::slotRefreshDebugActions() void RIMainWindow::slotEditPreferences() { RIApplication* app = RIApplication::instance(); - RIPreferencesDialog preferencesDialog(this, app->preferences()); + RIPreferencesDialog preferencesDialog(this, app->preferences(), "Preferences"); if (preferencesDialog.exec() == QDialog::Accepted) { // Write preferences using QSettings and apply them to the application @@ -1116,3 +1148,43 @@ void RIMainWindow::slotCurrentChanged(const QModelIndex & current, const QModelI tmp = tmp.parent(); } } + + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RIMainWindow::slotNewObjectPropertyView() +{ + if (!m_treeModelPdm) return; + + RimUiTreeView* treeView = NULL; + + { + QDockWidget* dockWidget = new QDockWidget("Project", this); + dockWidget->setObjectName("dockWidget"); + dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + + treeView = new RimUiTreeView(dockWidget); + dockWidget->setWidget(treeView); + + addDockWidget(Qt::RightDockWidgetArea, dockWidget); + } + + treeView->setModel(m_treeModelPdm); + treeView->expandAll(); + + + { + QDockWidget* dockWidget = new QDockWidget("Properties", this); + dockWidget->setObjectName("dockWidget"); + dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + + caf::PdmUiPropertyView* propView = new caf::PdmUiPropertyView(dockWidget); + dockWidget->setWidget(propView); + + addDockWidget(Qt::RightDockWidgetArea, dockWidget); + + connect(treeView, SIGNAL(selectedObjectChanged( caf::PdmObject* )), propView, SLOT(showProperties( caf::PdmObject* ))); + } +} diff --git a/ApplicationCode/UserInterface/RIMainWindow.h b/ApplicationCode/UserInterface/RIMainWindow.h index f01afdd196..e3724ed931 100644 --- a/ApplicationCode/UserInterface/RIMainWindow.h +++ b/ApplicationCode/UserInterface/RIMainWindow.h @@ -30,6 +30,7 @@ class QMdiSubWindow; class QComboBox; class QLabel; class QLineEdit; +class QItemSelection; class RIViewer; class RIResultInfoPanel; @@ -43,6 +44,7 @@ namespace caf class PdmObject; class FrameAnimationControl; class AnimationToolBar; + class PdmUiPropertyView; } //================================================================================================== @@ -101,11 +103,13 @@ private: private: // File actions QAction* m_openAction; + QAction* m_openInputEclipseFileAction; QAction* m_openProjectAction; QAction* m_openLastUsedProjectAction; QAction* m_mockModelAction; QAction* m_mockResultsModelAction; QAction* m_mockLargeResultsModelAction; + QAction* m_mockInputModelAction; QAction* m_saveProjectAction; QAction* m_saveProjectAsAction; QAction* m_closeAction; @@ -126,6 +130,7 @@ private: // Debug actions QAction* m_debugUseShaders; QAction* m_performanceHud; + QAction* m_newPropertyView; // Help actions QAction* m_aboutAction; @@ -151,13 +156,15 @@ private: private slots: // File slots - void slotOpenFile(); + void slotOpenBinaryGridFiles(); + void slotOpenInputFiles(); void slotOpenProject(); void slotOpenLastUsedProject(); void slotMockModel(); void slotMockResultsModel(); void slotMockLargeResultsModel(); + void slotInputMockModel(); void slotSaveProject(); void slotSaveProjectAs(); @@ -183,6 +190,7 @@ private slots: void slotRefreshDebugActions(); void slotUseShaders(bool enable); void slotShowPerformanceInfo(bool enable); + void slotNewObjectPropertyView(); // Windows slots void slotBuildWindowActions(); @@ -202,10 +210,8 @@ public: void setPdmRoot(caf::PdmObject* pdmRoot); private: - QTreeView* m_treeView; - caf::UiPropertyCreatorPdm* m_uiManagerPdm; - RimUiTreeModelPdm* m_treeModelPdm; - caf::PdmObject* m_pdmRoot; - - + QTreeView* m_treeView; + RimUiTreeModelPdm* m_treeModelPdm; + caf::PdmObject* m_pdmRoot; + caf::PdmUiPropertyView* m_pdmUiPropertyView; }; diff --git a/ApplicationCode/UserInterface/RIPreferencesDialog.cpp b/ApplicationCode/UserInterface/RIPreferencesDialog.cpp index eece2807d2..c77785a99d 100644 --- a/ApplicationCode/UserInterface/RIPreferencesDialog.cpp +++ b/ApplicationCode/UserInterface/RIPreferencesDialog.cpp @@ -23,19 +23,20 @@ #include "cafPdmObject.h" #include "RimUiTreeModelPdm.h" -#include "qtgroupboxpropertybrowser.h" +#include "cafPdmUiPropertyView.h" //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RIPreferencesDialog::RIPreferencesDialog(QWidget* parent, caf::PdmObject* object) +RIPreferencesDialog::RIPreferencesDialog(QWidget* parent, caf::PdmObject* object, const QString& windowTitle) : QDialog(parent) { CVF_ASSERT(object); m_pdmObject = object; + m_windowTitle = windowTitle; setupUi(); } @@ -45,18 +46,15 @@ RIPreferencesDialog::RIPreferencesDialog(QWidget* parent, caf::PdmObject* object //-------------------------------------------------------------------------------------------------- void RIPreferencesDialog::setupUi() { - setWindowTitle("Preferences"); + setWindowTitle(m_windowTitle); - m_uiManagerPdm = new RimUiPropertyCreatorPdm(this); + m_pdmUiPropertyView = new caf::PdmUiPropertyView(this); QVBoxLayout* dialogLayout = new QVBoxLayout; setLayout(dialogLayout); - QtGroupBoxPropertyBrowser* groupPropertyBrowser = new QtGroupBoxPropertyBrowser(); - m_uiManagerPdm->setPropertyBrowser(groupPropertyBrowser); - m_uiManagerPdm->createAndShowPropertiesForObject(m_pdmObject); - dialogLayout->addWidget(groupPropertyBrowser); - + dialogLayout->addWidget(m_pdmUiPropertyView); + m_pdmUiPropertyView->showProperties(m_pdmObject); // Buttons QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); diff --git a/ApplicationCode/UserInterface/RIPreferencesDialog.h b/ApplicationCode/UserInterface/RIPreferencesDialog.h index 934a1b9829..b33c4924d2 100644 --- a/ApplicationCode/UserInterface/RIPreferencesDialog.h +++ b/ApplicationCode/UserInterface/RIPreferencesDialog.h @@ -23,7 +23,7 @@ namespace caf { class PdmObject; - class UiPropertyCreatorPdm; + class PdmUiPropertyView; } @@ -37,12 +37,13 @@ class RIPreferencesDialog : public QDialog Q_OBJECT public: - RIPreferencesDialog(QWidget* parent, caf::PdmObject* object); + RIPreferencesDialog(QWidget* parent, caf::PdmObject* object, const QString& windowTitle); private: void setupUi(); private: + QString m_windowTitle; caf::PdmObject* m_pdmObject; - caf::UiPropertyCreatorPdm* m_uiManagerPdm; + caf::PdmUiPropertyView* m_pdmUiPropertyView; }; diff --git a/ApplicationCode/UserInterface/RIViewer.cpp b/ApplicationCode/UserInterface/RIViewer.cpp index bf45dc9488..fc32d2b5ac 100644 --- a/ApplicationCode/UserInterface/RIViewer.cpp +++ b/ApplicationCode/UserInterface/RIViewer.cpp @@ -78,12 +78,11 @@ RIViewer::~RIViewer() //-------------------------------------------------------------------------------------------------- void RIViewer::setColorLegend1(cvf::OverlayColorLegend* legend) { - if (m_legend1.notNull() && legend == NULL) - { - m_mainRendering->removeOverlayItem(m_legend1.p()); - } + m_mainRendering->removeOverlayItem(m_legend1.p()); m_legend1 = legend; + + this->updateLegends(); } @@ -92,14 +91,34 @@ void RIViewer::setColorLegend1(cvf::OverlayColorLegend* legend) //-------------------------------------------------------------------------------------------------- void RIViewer::setColorLegend2(cvf::OverlayColorLegend* legend) { - if (m_legend2.notNull() && legend == NULL) - { - m_mainRendering->removeOverlayItem(m_legend2.p()); - } + m_mainRendering->removeOverlayItem(m_legend2.p()); m_legend2 = legend; + + this->updateLegends(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RIViewer::updateLegends() +{ + cvf::Rendering* firstRendering = m_renderingSequence->firstRendering(); + CVF_ASSERT(firstRendering); + + firstRendering->removeOverlayItem(m_legend1.p()); + firstRendering->removeOverlayItem(m_legend2.p()); + + if (m_legend1.notNull()) + { + firstRendering->addOverlayItem(m_legend1.p(), cvf::OverlayItem::BOTTOM_LEFT, cvf::OverlayItem::VERTICAL); + } + + if (m_legend2.notNull()) + { + firstRendering->addOverlayItem(m_legend2.p(), cvf::OverlayItem::BOTTOM_LEFT, cvf::OverlayItem::VERTICAL); + } +} //-------------------------------------------------------------------------------------------------- /// @@ -133,8 +152,7 @@ void RIViewer::setDefaultView() } } - m_mainCamera->fitView(bb, cvf::Vec3d::Y_AXIS, cvf::Vec3d::Z_AXIS); - // m_trackball->setRotationPoint(bb.center()); + m_mainCamera->fitView(bb, -cvf::Vec3d::Z_AXIS, cvf::Vec3d::Y_AXIS); } @@ -247,21 +265,10 @@ void RIViewer::slotSetCurrentFrame(int frameIndex) cvf::Rendering* firstRendering = m_renderingSequence->firstRendering(); CVF_ASSERT(firstRendering); - firstRendering->removeOverlayItem(m_legend1.p()); - firstRendering->removeOverlayItem(m_legend2.p()); - - if (m_legend1.notNull()) - { - firstRendering->addOverlayItem(m_legend1.p(), cvf::OverlayItem::BOTTOM_LEFT, cvf::OverlayItem::VERTICAL); - } - - if (m_legend2.notNull()) - { - firstRendering->addOverlayItem(m_legend2.p(), cvf::OverlayItem::BOTTOM_LEFT, cvf::OverlayItem::VERTICAL); - } - if (m_reservoirView) m_reservoirView->setCurrentTimeStep(frameIndex); + this->updateLegends(); + caf::Viewer::slotSetCurrentFrame(frameIndex); } diff --git a/ApplicationCode/UserInterface/RIViewer.h b/ApplicationCode/UserInterface/RIViewer.h index 5860fc18ac..c0bda1ad9c 100644 --- a/ApplicationCode/UserInterface/RIViewer.h +++ b/ApplicationCode/UserInterface/RIViewer.h @@ -58,13 +58,14 @@ public slots: virtual void slotEndAnimation(); protected: - void keyPressEvent(QKeyEvent* event); - void mouseReleaseEvent(QMouseEvent* event); + void keyPressEvent(QKeyEvent* event); + void mouseReleaseEvent(QMouseEvent* event); - void handlePickAction(int winPosX, int winPosY); - cvf::Part* pickPointAndFace(int winPosX, int winPosY, uint* faceHit, cvf::Vec3d* localIntersectionPoint); + void handlePickAction(int winPosX, int winPosY); + cvf::Part* pickPointAndFace(int winPosX, int winPosY, uint* faceHit, cvf::Vec3d* localIntersectionPoint); private: + void updateLegends(); caf::QtMouseState m_mouseState; cvf::ref m_legend1; diff --git a/CMakeLists.txt b/CMakeLists.txt index 268aa9a5ed..9343c3d504 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp") # set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g1") ELSE() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp -DUSE_ECL_LIB") ENDIF() @@ -33,8 +33,8 @@ ENDIF() ################################################################################ set(CMAKE_MAJOR_VERSION 0) -set(CMAKE_MINOR_VERSION 4) -set(CMAKE_PATCH_VERSION 8) +set(CMAKE_MINOR_VERSION 8) +set(CMAKE_PATCH_VERSION 0) set(PRODUCTVER ${CMAKE_MAJOR_VERSION},${CMAKE_MINOR_VERSION},0,${CMAKE_PATCH_VERSION}) set(STRPRODUCTVER ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}) @@ -74,17 +74,11 @@ include_directories( ################################################################################ add_subdirectory(cafProjectDataModel) -add_subdirectory(cafPdmCvf) add_subdirectory(CommonCode) -add_subdirectory(QtPropertyBrowser) add_subdirectory(cafAnimControl) add_subdirectory(cafViewer) - -include_directories( - ${QtPropertyBrowser_SOURCE_DIR} -) - add_subdirectory(cafUserInterface) +add_subdirectory(cafPdmCvf) include_directories( ${cafUserInterface_SOURCE_DIR} @@ -109,6 +103,7 @@ set (CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/Install/) ################################################################################ add_subdirectory(ApplicationCode) add_subdirectory(OctavePlugin) +# ################################################################################ # Unit tests @@ -117,8 +112,8 @@ add_subdirectory(ApplicationCode/ReservoirDataModel/ReservoirDataModel_UnitTests add_subdirectory(ApplicationCode/FileInterface/FileInterface_UnitTests) add_subdirectory(ApplicationCode/ModelVisualization/ModelVisualization_UnitTests) -#add_subdirectory(cafTests/cafProjectDataModel_UnitTests) -#add_subdirectory(cafTests/cafTestApplication) + + diff --git a/OctavePlugin/CMakeLists.txt b/OctavePlugin/CMakeLists.txt index 933f435f3b..c935e92f3b 100644 --- a/OctavePlugin/CMakeLists.txt +++ b/OctavePlugin/CMakeLists.txt @@ -4,6 +4,7 @@ set(CPP_SOURCES riGetActiveCellProperty.cpp riSetActiveCellProperty.cpp riGetActiveCellInfo.cpp + riGetMainGridDimensions.cpp ) if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") @@ -48,7 +49,12 @@ else() #add_custom_target(oct-files ALL DEPENDS "${OCTAVE_BINARY_OCT_FILES}") - add_custom_target(octave_plugins ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/riGetActiveCellProperty.oct" "${CMAKE_CURRENT_BINARY_DIR}/riSetActiveCellProperty.oct" "${CMAKE_CURRENT_BINARY_DIR}/riGetActiveCellInfo.oct") + add_custom_target(octave_plugins ALL DEPENDS + "${CMAKE_CURRENT_BINARY_DIR}/riGetActiveCellProperty.oct" + "${CMAKE_CURRENT_BINARY_DIR}/riSetActiveCellProperty.oct" + "${CMAKE_CURRENT_BINARY_DIR}/riGetActiveCellInfo.oct" + "${CMAKE_CURRENT_BINARY_DIR}/riGetMainGridDimensions.oct" + ) endif() install(FILES ${OCTAVE_BINARY_OCT_FILES} DESTINATION ${RESINSIGHT_FINAL_NAME}) diff --git a/OctavePlugin/OctaveScripts/InputPropTest.m b/OctavePlugin/OctaveScripts/InputPropTest.m new file mode 100644 index 0000000000..811528b89d --- /dev/null +++ b/OctavePlugin/OctaveScripts/InputPropTest.m @@ -0,0 +1,12 @@ +addpath("/home/builder/Projects/ResInsightBuildDir/OctavePlugin"); +PORO = riGetActiveCellProperty("PORO"); +PERMX = riGetActiveCellProperty("PERMX"); +IJK = riGetMainGridDimensions(); + +GENERATED = PORO .* PERMX; + +GENERATED(10:IJK(1):IJK(1)*IJK(2)*IJK(3)) = 100; +GENERATED(10*IJK(1):1:11*IJK(1)) = 100; +GENERATED(11*IJK(1):1:12*IJK(1)) = 100; +GENERATED(12*IJK(1):1:13*IJK(1)) = 100; +riSetActiveCellProperty(GENERATED, "PORO*PERMX"); \ No newline at end of file diff --git a/OctavePlugin/riGetMainGridDimensions.cpp b/OctavePlugin/riGetMainGridDimensions.cpp new file mode 100644 index 0000000000..103783d6d0 --- /dev/null +++ b/OctavePlugin/riGetMainGridDimensions.cpp @@ -0,0 +1,114 @@ +#include +#include + + +void getMainGridDimensions(int32NDArray& gridDimensions, const QString &hostName, quint16 port, QString caseName) +{ + QString serverName = hostName; + quint16 serverPort = port; + + const int Timeout = 5 * 1000; + + QTcpSocket socket; + socket.connectToHost(serverName, serverPort); + + if (!socket.waitForConnected(Timeout)) + { + error((("Connection: ") + socket.errorString()).toLatin1().data()); + return; + } + + // Create command and send it: + + QString command("GetMainGridDimensions "); + command += caseName; + QByteArray cmdBytes = command.toLatin1(); + + QDataStream socketStream(&socket); + socketStream.setVersion(QDataStream::Qt_4_0); + + socketStream << (qint64)(cmdBytes.size()); + socket.write(cmdBytes); + + // Get response. First wait for the header + + while (socket.bytesAvailable() < (int)(3*sizeof(quint64))) + { + if (!socket.waitForReadyRead(Timeout)) + { + error((("Wating for header: ") + socket.errorString()).toLatin1().data()); + return; + } + } + + // Read timestep count and blocksize + + quint64 iCount; + quint64 jCount; + quint64 kCount; + + socketStream >> iCount; + socketStream >> jCount; + socketStream >> kCount; + + dim_vector dv (1); + dv(0) = 3; + + gridDimensions.resize(dv); + gridDimensions(0) = iCount; + gridDimensions(1) = jCount; + gridDimensions(2) = kCount; + + + QString tmp = QString("riGetMainGridDimensions : Read main grid dimensions"); + if (caseName.isEmpty()) + { + tmp += QString(" from active case."); + } + else + { + tmp += QString(" from %1.").arg(caseName); + } + octave_stdout << tmp.toStdString() << " Dimensions: " << iCount << ", " << jCount << ", " << kCount << std::endl; + + return; +} + + + +DEFUN_DLD (riGetMainGridDimensions, args, nargout, + "Usage:\n" + "\n" + " riGetMainGridDimensions( [CaseName/CaseIndex])\n" + "\n" + "Returns a vector of size 3: [ICount, JCount, KCount] \n" + "Containing the dimentions of the main grid in the requested case.\n" + "If the Eclipse Case is not defined, the active View in ResInsight is used." + ) +{ + int nargin = args.length (); + if (nargin > 1) + { + error("riGetActiveCellInfo: Too many arguments. Only the name or index of the case is valid input.\n"); + print_usage(); + } + else if (nargout < 1) + { + error("riGetActiveCellInfo: Missing output argument.\n"); + print_usage(); + } + else + { + int32NDArray propertyFrames; + + if (nargin > 0) + getMainGridDimensions(propertyFrames, "127.0.0.1", 40001, args(0).char_matrix_value().row_as_string(0).c_str()); + else + getMainGridDimensions(propertyFrames, "127.0.0.1", 40001, ""); + + return octave_value(propertyFrames); + } + + return octave_value_list (); +} + diff --git a/OctavePlugin/riGetMainGridDimensions.o b/OctavePlugin/riGetMainGridDimensions.o new file mode 100644 index 0000000000..b9dd196948 Binary files /dev/null and b/OctavePlugin/riGetMainGridDimensions.o differ diff --git a/QtPropertyBrowser/CMakeLists.txt b/QtPropertyBrowser/CMakeLists.txt deleted file mode 100644 index 79029fab49..0000000000 --- a/QtPropertyBrowser/CMakeLists.txt +++ /dev/null @@ -1,46 +0,0 @@ -cmake_minimum_required (VERSION 2.8) - -project ( QtPropertyBrowser ) - - -if (CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-overloaded-virtual") # do not display warning related to hiding of overloaded virtual method -endif() - - -find_package (Qt4 COMPONENTS QtCore QtGui QtMain REQUIRED) -include (${QT_USE_FILE}) -include( ${QtPropertyBrowser_SOURCE_DIR}/qtadditions_cmake.txt ) - -# Qt MOC -# ============================================================================== -file( GLOB_RECURSE HEADER_FILES *.h ) -set ( QT_MOC_HEADERS ${HEADER_FILES} ) - -qt4_wrap_cpp( MOC_FILES_CPP ${QT_MOC_HEADERS} ) - -# Special handling of cpp files with internal Qt classes that must be MOCed. -# The file base name is given, and .moc is appended -set( EXTRA_MOC_FILES qteditorfactory qtpropertymanager qttreepropertybrowser ) -foreach (it ${EXTRA_MOC_FILES}) - qt4_generate_moc(${it}.cpp ${it}.moc) - set( MOC_FILES_CPP ${MOC_FILES_CPP} ${it}.moc ) -endforeach(it) - - -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) - -set_source_files_properties(${MOC_FILES_CPP} PROPERTIES HEADER_FILE_ONLY TRUE) - -add_library ( ${PROJECT_NAME} - qtbuttonpropertybrowser.cpp - qteditorfactory.cpp - qtgroupboxpropertybrowser.cpp - qtpropertybrowser.cpp - qtpropertybrowserutils.cpp - qtpropertymanager.cpp - qttreepropertybrowser.cpp - qtvariantproperty.cpp - - ${MOC_FILES_CPP} -) diff --git a/QtPropertyBrowser/qtadditions_cmake.txt b/QtPropertyBrowser/qtadditions_cmake.txt deleted file mode 100644 index 1fe3d28778..0000000000 --- a/QtPropertyBrowser/qtadditions_cmake.txt +++ /dev/null @@ -1,14 +0,0 @@ - -MACRO (QT4_WRAP_CPP_PREFIX prefix outfiles ) - # get include dirs - QT4_GET_MOC_FLAGS(moc_flags) - QT4_EXTRACT_OPTIONS(moc_files moc_options ${ARGN}) - - FOREACH (it ${moc_files}) - GET_FILENAME_COMPONENT(it ${it} ABSOLUTE) - QT4_MAKE_OUTPUT_FILE(${it} ${prefix} tst outfile) - QT4_CREATE_MOC_COMMAND(${it} ${outfile} "${moc_flags}" "${moc_options}") - SET(${outfiles} ${${outfiles}} ${outfile}) - ENDFOREACH(it) - -ENDMACRO (QT4_WRAP_CPP_PREFIX) diff --git a/QtPropertyBrowser/qtbuttonpropertybrowser.cpp b/QtPropertyBrowser/qtbuttonpropertybrowser.cpp deleted file mode 100644 index d5ebd4fc2b..0000000000 --- a/QtPropertyBrowser/qtbuttonpropertybrowser.cpp +++ /dev/null @@ -1,676 +0,0 @@ -/**************************************************************************** -** -** This file is part of a Qt Solutions component. -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Solutions Commercial License Agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** Please note Third Party Software included with Qt Solutions may impose -** additional restrictions and it is the user's responsibility to ensure -** that they have met the licensing requirements of the GPL, LGPL, or Qt -** Solutions Commercial license and the relevant license of the Third -** Party Software they are using. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qtbuttonpropertybrowser.h" -#include -#include -#include -#include -#include -#include -#include - -#if QT_VERSION >= 0x040400 -QT_BEGIN_NAMESPACE -#endif - -class QtButtonPropertyBrowserPrivate -{ - QtButtonPropertyBrowser *q_ptr; - Q_DECLARE_PUBLIC(QtButtonPropertyBrowser) -public: - - void init(QWidget *parent); - - void propertyInserted(QtBrowserItem *index, QtBrowserItem *afterIndex); - void propertyRemoved(QtBrowserItem *index); - void propertyChanged(QtBrowserItem *index); - QWidget *createEditor(QtProperty *property, QWidget *parent) const - { return q_ptr->createEditor(property, parent); } - - void slotEditorDestroyed(); - void slotUpdate(); - void slotToggled(bool checked); - - struct WidgetItem - { - WidgetItem() : widget(0), label(0), widgetLabel(0), - button(0), container(0), layout(0), /*line(0), */parent(0), expanded(false) { } - QWidget *widget; // can be null - QLabel *label; // main label with property name - QLabel *widgetLabel; // label substitute showing the current value if there is no widget - QToolButton *button; // expandable button for items with children - QWidget *container; // container which is expanded when the button is clicked - QGridLayout *layout; // layout in container - WidgetItem *parent; - QList children; - bool expanded; - }; -private: - void updateLater(); - void updateItem(WidgetItem *item); - void insertRow(QGridLayout *layout, int row) const; - void removeRow(QGridLayout *layout, int row) const; - int gridRow(WidgetItem *item) const; - int gridSpan(WidgetItem *item) const; - void setExpanded(WidgetItem *item, bool expanded); - QToolButton *createButton(QWidget *panret = 0) const; - - QMap m_indexToItem; - QMap m_itemToIndex; - QMap m_widgetToItem; - QMap m_buttonToItem; - QGridLayout *m_mainLayout; - QList m_children; - QList m_recreateQueue; -}; - -QToolButton *QtButtonPropertyBrowserPrivate::createButton(QWidget *parent) const -{ - QToolButton *button = new QToolButton(parent); - button->setCheckable(true); - button->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed)); - button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - button->setArrowType(Qt::DownArrow); - button->setIconSize(QSize(3, 16)); - /* - QIcon icon; - icon.addPixmap(q_ptr->style()->standardPixmap(QStyle::SP_ArrowDown), QIcon::Normal, QIcon::Off); - icon.addPixmap(q_ptr->style()->standardPixmap(QStyle::SP_ArrowUp), QIcon::Normal, QIcon::On); - button->setIcon(icon); - */ - return button; -} - -int QtButtonPropertyBrowserPrivate::gridRow(WidgetItem *item) const -{ - QList siblings; - if (item->parent) - siblings = item->parent->children; - else - siblings = m_children; - - int row = 0; - QListIterator it(siblings); - while (it.hasNext()) { - WidgetItem *sibling = it.next(); - if (sibling == item) - return row; - row += gridSpan(sibling); - } - return -1; -} - -int QtButtonPropertyBrowserPrivate::gridSpan(WidgetItem *item) const -{ - if (item->container && item->expanded) - return 2; - return 1; -} - -void QtButtonPropertyBrowserPrivate::init(QWidget *parent) -{ - m_mainLayout = new QGridLayout(); - parent->setLayout(m_mainLayout); - QLayoutItem *item = new QSpacerItem(0, 0, - QSizePolicy::Fixed, QSizePolicy::Expanding); - m_mainLayout->addItem(item, 0, 0); -} - -void QtButtonPropertyBrowserPrivate::slotEditorDestroyed() -{ - QWidget *editor = qobject_cast(q_ptr->sender()); - if (!editor) - return; - if (!m_widgetToItem.contains(editor)) - return; - m_widgetToItem[editor]->widget = 0; - m_widgetToItem.remove(editor); -} - -void QtButtonPropertyBrowserPrivate::slotUpdate() -{ - QListIterator itItem(m_recreateQueue); - while (itItem.hasNext()) { - WidgetItem *item = itItem.next(); - - WidgetItem *parent = item->parent; - QWidget *w = 0; - QGridLayout *l = 0; - const int oldRow = gridRow(item); - if (parent) { - w = parent->container; - l = parent->layout; - } else { - w = q_ptr; - l = m_mainLayout; - } - - int span = 1; - if (!item->widget && !item->widgetLabel) - span = 2; - item->label = new QLabel(w); - item->label->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); - l->addWidget(item->label, oldRow, 0, 1, span); - - updateItem(item); - } - m_recreateQueue.clear(); -} - -void QtButtonPropertyBrowserPrivate::setExpanded(WidgetItem *item, bool expanded) -{ - if (item->expanded == expanded) - return; - - if (!item->container) - return; - - item->expanded = expanded; - const int row = gridRow(item); - WidgetItem *parent = item->parent; - QGridLayout *l = 0; - if (parent) - l = parent->layout; - else - l = m_mainLayout; - - if (expanded) { - insertRow(l, row + 1); - l->addWidget(item->container, row + 1, 0, 1, 2); - item->container->show(); - } else { - l->removeWidget(item->container); - item->container->hide(); - removeRow(l, row + 1); - } - - item->button->setChecked(expanded); - item->button->setArrowType(expanded ? Qt::UpArrow : Qt::DownArrow); -} - -void QtButtonPropertyBrowserPrivate::slotToggled(bool checked) -{ - WidgetItem *item = m_buttonToItem.value(q_ptr->sender()); - if (!item) - return; - - setExpanded(item, checked); - - if (checked) - emit q_ptr->expanded(m_itemToIndex.value(item)); - else - emit q_ptr->collapsed(m_itemToIndex.value(item)); -} - -void QtButtonPropertyBrowserPrivate::updateLater() -{ - QTimer::singleShot(0, q_ptr, SLOT(slotUpdate())); -} - -void QtButtonPropertyBrowserPrivate::propertyInserted(QtBrowserItem *index, QtBrowserItem *afterIndex) -{ - WidgetItem *afterItem = m_indexToItem.value(afterIndex); - WidgetItem *parentItem = m_indexToItem.value(index->parent()); - - WidgetItem *newItem = new WidgetItem(); - newItem->parent = parentItem; - - QGridLayout *layout = 0; - QWidget *parentWidget = 0; - int row = -1; - if (!afterItem) { - row = 0; - if (parentItem) - parentItem->children.insert(0, newItem); - else - m_children.insert(0, newItem); - } else { - row = gridRow(afterItem) + gridSpan(afterItem); - if (parentItem) - parentItem->children.insert(parentItem->children.indexOf(afterItem) + 1, newItem); - else - m_children.insert(m_children.indexOf(afterItem) + 1, newItem); - } - - if (!parentItem) { - layout = m_mainLayout; - parentWidget = q_ptr; - } else { - if (!parentItem->container) { - m_recreateQueue.removeAll(parentItem); - WidgetItem *grandParent = parentItem->parent; - QWidget *w = 0; - QGridLayout *l = 0; - const int oldRow = gridRow(parentItem); - if (grandParent) { - w = grandParent->container; - l = grandParent->layout; - } else { - w = q_ptr; - l = m_mainLayout; - } - QFrame *container = new QFrame(); - container->setFrameShape(QFrame::Panel); - container->setFrameShadow(QFrame::Raised); - parentItem->container = container; - parentItem->button = createButton(); - m_buttonToItem[parentItem->button] = parentItem; - q_ptr->connect(parentItem->button, SIGNAL(toggled(bool)), q_ptr, SLOT(slotToggled(bool))); - parentItem->layout = new QGridLayout(); - container->setLayout(parentItem->layout); - if (parentItem->label) { - l->removeWidget(parentItem->label); - delete parentItem->label; - parentItem->label = 0; - } - int span = 1; - if (!parentItem->widget && !parentItem->widgetLabel) - span = 2; - l->addWidget(parentItem->button, oldRow, 0, 1, span); - updateItem(parentItem); - } - layout = parentItem->layout; - parentWidget = parentItem->container; - } - - newItem->label = new QLabel(parentWidget); - newItem->label->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); - newItem->widget = createEditor(index->property(), parentWidget); - if (newItem->widget) { - QObject::connect(newItem->widget, SIGNAL(destroyed()), q_ptr, SLOT(slotEditorDestroyed())); - m_widgetToItem[newItem->widget] = newItem; - } else if (index->property()->hasValue()) { - newItem->widgetLabel = new QLabel(parentWidget); - newItem->widgetLabel->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed)); - } - - insertRow(layout, row); - int span = 1; - if (newItem->widget) - layout->addWidget(newItem->widget, row, 1); - else if (newItem->widgetLabel) - layout->addWidget(newItem->widgetLabel, row, 1); - else - span = 2; - layout->addWidget(newItem->label, row, 0, span, 1); - - m_itemToIndex[newItem] = index; - m_indexToItem[index] = newItem; - - updateItem(newItem); -} - -void QtButtonPropertyBrowserPrivate::propertyRemoved(QtBrowserItem *index) -{ - WidgetItem *item = m_indexToItem.value(index); - - m_indexToItem.remove(index); - m_itemToIndex.remove(item); - - WidgetItem *parentItem = item->parent; - - const int row = gridRow(item); - - if (parentItem) - parentItem->children.removeAt(parentItem->children.indexOf(item)); - else - m_children.removeAt(m_children.indexOf(item)); - - const int colSpan = gridSpan(item); - - m_buttonToItem.remove(item->button); - - if (item->widget) - delete item->widget; - if (item->label) - delete item->label; - if (item->widgetLabel) - delete item->widgetLabel; - if (item->button) - delete item->button; - if (item->container) - delete item->container; - - if (!parentItem) { - removeRow(m_mainLayout, row); - if (colSpan > 1) - removeRow(m_mainLayout, row); - } else if (parentItem->children.count() != 0) { - removeRow(parentItem->layout, row); - if (colSpan > 1) - removeRow(parentItem->layout, row); - } else { - const WidgetItem *grandParent = parentItem->parent; - QGridLayout *l = 0; - if (grandParent) { - l = grandParent->layout; - } else { - l = m_mainLayout; - } - - const int parentRow = gridRow(parentItem); - const int parentSpan = gridSpan(parentItem); - - l->removeWidget(parentItem->button); - l->removeWidget(parentItem->container); - delete parentItem->button; - delete parentItem->container; - parentItem->button = 0; - parentItem->container = 0; - parentItem->layout = 0; - if (!m_recreateQueue.contains(parentItem)) - m_recreateQueue.append(parentItem); - if (parentSpan > 1) - removeRow(l, parentRow + 1); - - updateLater(); - } - m_recreateQueue.removeAll(item); - - delete item; -} - -void QtButtonPropertyBrowserPrivate::insertRow(QGridLayout *layout, int row) const -{ - QMap itemToPos; - int idx = 0; - while (idx < layout->count()) { - int r, c, rs, cs; - layout->getItemPosition(idx, &r, &c, &rs, &cs); - if (r >= row) { - itemToPos[layout->takeAt(idx)] = QRect(r + 1, c, rs, cs); - } else { - idx++; - } - } - - const QMap::ConstIterator icend = itemToPos.constEnd(); - for(QMap::ConstIterator it = itemToPos.constBegin(); it != icend; ++it) { - const QRect r = it.value(); - layout->addItem(it.key(), r.x(), r.y(), r.width(), r.height()); - } -} - -void QtButtonPropertyBrowserPrivate::removeRow(QGridLayout *layout, int row) const -{ - QMap itemToPos; - int idx = 0; - while (idx < layout->count()) { - int r, c, rs, cs; - layout->getItemPosition(idx, &r, &c, &rs, &cs); - if (r > row) { - itemToPos[layout->takeAt(idx)] = QRect(r - 1, c, rs, cs); - } else { - idx++; - } - } - - const QMap::ConstIterator icend = itemToPos.constEnd(); - for(QMap::ConstIterator it = itemToPos.constBegin(); it != icend; ++it) { - const QRect r = it.value(); - layout->addItem(it.key(), r.x(), r.y(), r.width(), r.height()); - } -} - -void QtButtonPropertyBrowserPrivate::propertyChanged(QtBrowserItem *index) -{ - WidgetItem *item = m_indexToItem.value(index); - - updateItem(item); -} - -void QtButtonPropertyBrowserPrivate::updateItem(WidgetItem *item) -{ - QtProperty *property = m_itemToIndex[item]->property(); - if (item->button) { - QFont font = item->button->font(); - font.setUnderline(property->isModified()); - item->button->setFont(font); - item->button->setText(property->propertyName()); - item->button->setToolTip(property->toolTip()); - item->button->setStatusTip(property->statusTip()); - item->button->setWhatsThis(property->whatsThis()); - item->button->setEnabled(property->isEnabled()); - } - if (item->label) { - QFont font = item->label->font(); - font.setUnderline(property->isModified()); - item->label->setFont(font); - item->label->setText(property->propertyName()); - item->label->setToolTip(property->toolTip()); - item->label->setStatusTip(property->statusTip()); - item->label->setWhatsThis(property->whatsThis()); - item->label->setEnabled(property->isEnabled()); - } - if (item->widgetLabel) { - QFont font = item->widgetLabel->font(); - font.setUnderline(false); - item->widgetLabel->setFont(font); - item->widgetLabel->setText(property->valueText()); - item->widgetLabel->setToolTip(property->valueText()); - item->widgetLabel->setEnabled(property->isEnabled()); - } - if (item->widget) { - QFont font = item->widget->font(); - font.setUnderline(false); - item->widget->setFont(font); - item->widget->setEnabled(property->isEnabled()); - item->widget->setToolTip(property->valueText()); - } -} - - - -/*! - \class QtButtonPropertyBrowser - - \brief The QtButtonPropertyBrowser class provides a drop down QToolButton - based property browser. - - A property browser is a widget that enables the user to edit a - given set of properties. Each property is represented by a label - specifying the property's name, and an editing widget (e.g. a line - edit or a combobox) holding its value. A property can have zero or - more subproperties. - - QtButtonPropertyBrowser provides drop down button for all nested - properties, i.e. subproperties are enclosed by a container associated with - the drop down button. The parent property's name is displayed as button text. For example: - - \image qtbuttonpropertybrowser.png - - Use the QtAbstractPropertyBrowser API to add, insert and remove - properties from an instance of the QtButtonPropertyBrowser - class. The properties themselves are created and managed by - implementations of the QtAbstractPropertyManager class. - - \sa QtTreePropertyBrowser, QtAbstractPropertyBrowser -*/ - -/*! - \fn void QtButtonPropertyBrowser::collapsed(QtBrowserItem *item) - - This signal is emitted when the \a item is collapsed. - - \sa expanded(), setExpanded() -*/ - -/*! - \fn void QtButtonPropertyBrowser::expanded(QtBrowserItem *item) - - This signal is emitted when the \a item is expanded. - - \sa collapsed(), setExpanded() -*/ - -/*! - Creates a property browser with the given \a parent. -*/ -QtButtonPropertyBrowser::QtButtonPropertyBrowser(QWidget *parent) - : QtAbstractPropertyBrowser(parent) -{ - d_ptr = new QtButtonPropertyBrowserPrivate; - d_ptr->q_ptr = this; - - d_ptr->init(this); -} - -/*! - Destroys this property browser. - - Note that the properties that were inserted into this browser are - \e not destroyed since they may still be used in other - browsers. The properties are owned by the manager that created - them. - - \sa QtProperty, QtAbstractPropertyManager -*/ -QtButtonPropertyBrowser::~QtButtonPropertyBrowser() -{ - const QMap::ConstIterator icend = d_ptr->m_itemToIndex.constEnd(); - for (QMap::ConstIterator it = d_ptr->m_itemToIndex.constBegin(); it != icend; ++it) - delete it.key(); - delete d_ptr; -} - -/*! - \reimp -*/ -void QtButtonPropertyBrowser::itemInserted(QtBrowserItem *item, QtBrowserItem *afterItem) -{ - d_ptr->propertyInserted(item, afterItem); -} - -/*! - \reimp -*/ -void QtButtonPropertyBrowser::itemRemoved(QtBrowserItem *item) -{ - d_ptr->propertyRemoved(item); -} - -/*! - \reimp -*/ -void QtButtonPropertyBrowser::itemChanged(QtBrowserItem *item) -{ - d_ptr->propertyChanged(item); -} - -/*! - Sets the \a item to either collapse or expanded, depending on the value of \a expanded. - - \sa isExpanded(), expanded(), collapsed() -*/ - -void QtButtonPropertyBrowser::setExpanded(QtBrowserItem *item, bool expanded) -{ - QtButtonPropertyBrowserPrivate::WidgetItem *itm = d_ptr->m_indexToItem.value(item); - if (itm) - d_ptr->setExpanded(itm, expanded); -} - -/*! - Returns true if the \a item is expanded; otherwise returns false. - - \sa setExpanded() -*/ - -bool QtButtonPropertyBrowser::isExpanded(QtBrowserItem *item) const -{ - QtButtonPropertyBrowserPrivate::WidgetItem *itm = d_ptr->m_indexToItem.value(item); - if (itm) - return itm->expanded; - return false; -} - -#if QT_VERSION >= 0x040400 -QT_END_NAMESPACE -#endif - -#include "moc_qtbuttonpropertybrowser.cxx" diff --git a/QtPropertyBrowser/qtbuttonpropertybrowser.h b/QtPropertyBrowser/qtbuttonpropertybrowser.h deleted file mode 100644 index 518e047e86..0000000000 --- a/QtPropertyBrowser/qtbuttonpropertybrowser.h +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** -** -** This file is part of a Qt Solutions component. -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Solutions Commercial License Agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** Please note Third Party Software included with Qt Solutions may impose -** additional restrictions and it is the user's responsibility to ensure -** that they have met the licensing requirements of the GPL, LGPL, or Qt -** Solutions Commercial license and the relevant license of the Third -** Party Software they are using. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTBUTTONPROPERTYBROWSER_H -#define QTBUTTONPROPERTYBROWSER_H - -#include "qtpropertybrowser.h" - -#if QT_VERSION >= 0x040400 -QT_BEGIN_NAMESPACE -#endif - -class QtButtonPropertyBrowserPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtButtonPropertyBrowser : public QtAbstractPropertyBrowser -{ - Q_OBJECT -public: - - QtButtonPropertyBrowser(QWidget *parent = 0); - ~QtButtonPropertyBrowser(); - - void setExpanded(QtBrowserItem *item, bool expanded); - bool isExpanded(QtBrowserItem *item) const; - -Q_SIGNALS: - - void collapsed(QtBrowserItem *item); - void expanded(QtBrowserItem *item); - -protected: - virtual void itemInserted(QtBrowserItem *item, QtBrowserItem *afterItem); - virtual void itemRemoved(QtBrowserItem *item); - virtual void itemChanged(QtBrowserItem *item); - -private: - - QtButtonPropertyBrowserPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtButtonPropertyBrowser) - Q_DISABLE_COPY(QtButtonPropertyBrowser) - Q_PRIVATE_SLOT(d_func(), void slotUpdate()) - Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed()) - Q_PRIVATE_SLOT(d_func(), void slotToggled(bool)) - -}; - -#if QT_VERSION >= 0x040400 -QT_END_NAMESPACE -#endif - -#endif diff --git a/QtPropertyBrowser/qteditorfactory.cpp b/QtPropertyBrowser/qteditorfactory.cpp deleted file mode 100644 index 8401a31b61..0000000000 --- a/QtPropertyBrowser/qteditorfactory.cpp +++ /dev/null @@ -1,2617 +0,0 @@ -/**************************************************************************** -** -** This file is part of a Qt Solutions component. -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Solutions Commercial License Agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** Please note Third Party Software included with Qt Solutions may impose -** additional restrictions and it is the user's responsibility to ensure -** that they have met the licensing requirements of the GPL, LGPL, or Qt -** Solutions Commercial license and the relevant license of the Third -** Party Software they are using. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qteditorfactory.h" -#include "qtpropertybrowserutils_p.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(Q_CC_MSVC) -# pragma warning(disable: 4786) /* MS VS 6: truncating debug info after 255 characters */ -#endif - -#if QT_VERSION >= 0x040400 -QT_BEGIN_NAMESPACE -#endif - -// Set a hard coded left margin to account for the indentation -// of the tree view icon when switching to an editor - -static inline void setupTreeViewEditorMargin(QLayout *lt) -{ - enum { DecorationMargin = 4 }; - if (QApplication::layoutDirection() == Qt::LeftToRight) - lt->setContentsMargins(DecorationMargin, 0, 0, 0); - else - lt->setContentsMargins(0, 0, DecorationMargin, 0); -} - -// ---------- EditorFactoryPrivate : -// Base class for editor factory private classes. Manages mapping of properties to editors and vice versa. - -template -class EditorFactoryPrivate -{ -public: - - typedef QList EditorList; - typedef QMap PropertyToEditorListMap; - typedef QMap EditorToPropertyMap; - - Editor *createEditor(QtProperty *property, QWidget *parent); - void initializeEditor(QtProperty *property, Editor *e); - void slotEditorDestroyed(QObject *object); - - PropertyToEditorListMap m_createdEditors; - EditorToPropertyMap m_editorToProperty; -}; - -template -Editor *EditorFactoryPrivate::createEditor(QtProperty *property, QWidget *parent) -{ - Editor *editor = new Editor(parent); - initializeEditor(property, editor); - return editor; -} - -template -void EditorFactoryPrivate::initializeEditor(QtProperty *property, Editor *editor) -{ - Q_TYPENAME PropertyToEditorListMap::iterator it = m_createdEditors.find(property); - if (it == m_createdEditors.end()) - it = m_createdEditors.insert(property, EditorList()); - it.value().append(editor); - m_editorToProperty.insert(editor, property); -} - -template -void EditorFactoryPrivate::slotEditorDestroyed(QObject *object) -{ - const Q_TYPENAME EditorToPropertyMap::iterator ecend = m_editorToProperty.end(); - for (Q_TYPENAME EditorToPropertyMap::iterator itEditor = m_editorToProperty.begin(); itEditor != ecend; ++itEditor) { - if (itEditor.key() == object) { - Editor *editor = itEditor.key(); - QtProperty *property = itEditor.value(); - const Q_TYPENAME PropertyToEditorListMap::iterator pit = m_createdEditors.find(property); - if (pit != m_createdEditors.end()) { - pit.value().removeAll(editor); - if (pit.value().empty()) - m_createdEditors.erase(pit); - } - m_editorToProperty.erase(itEditor); - return; - } - } -} - -// ------------ QtSpinBoxFactory - -class QtSpinBoxFactoryPrivate : public EditorFactoryPrivate -{ - QtSpinBoxFactory *q_ptr; - Q_DECLARE_PUBLIC(QtSpinBoxFactory) -public: - - void slotPropertyChanged(QtProperty *property, int value); - void slotRangeChanged(QtProperty *property, int min, int max); - void slotSingleStepChanged(QtProperty *property, int step); - void slotSetValue(int value); -}; - -void QtSpinBoxFactoryPrivate::slotPropertyChanged(QtProperty *property, int value) -{ - if (!m_createdEditors.contains(property)) - return; - QListIterator itEditor(m_createdEditors[property]); - while (itEditor.hasNext()) { - QSpinBox *editor = itEditor.next(); - if (editor->value() != value) { - editor->blockSignals(true); - editor->setValue(value); - editor->blockSignals(false); - } - } -} - -void QtSpinBoxFactoryPrivate::slotRangeChanged(QtProperty *property, int min, int max) -{ - if (!m_createdEditors.contains(property)) - return; - - QtIntPropertyManager *manager = q_ptr->propertyManager(property); - if (!manager) - return; - - QListIterator itEditor(m_createdEditors[property]); - while (itEditor.hasNext()) { - QSpinBox *editor = itEditor.next(); - editor->blockSignals(true); - editor->setRange(min, max); - editor->setValue(manager->value(property)); - editor->blockSignals(false); - } -} - -void QtSpinBoxFactoryPrivate::slotSingleStepChanged(QtProperty *property, int step) -{ - if (!m_createdEditors.contains(property)) - return; - QListIterator itEditor(m_createdEditors[property]); - while (itEditor.hasNext()) { - QSpinBox *editor = itEditor.next(); - editor->blockSignals(true); - editor->setSingleStep(step); - editor->blockSignals(false); - } -} - -void QtSpinBoxFactoryPrivate::slotSetValue(int value) -{ - QObject *object = q_ptr->sender(); - const QMap::ConstIterator ecend = m_editorToProperty.constEnd(); - for (QMap::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) { - if (itEditor.key() == object) { - QtProperty *property = itEditor.value(); - QtIntPropertyManager *manager = q_ptr->propertyManager(property); - if (!manager) - return; - manager->setValue(property, value); - return; - } - } -} - -/*! - \class QtSpinBoxFactory - - \brief The QtSpinBoxFactory class provides QSpinBox widgets for - properties created by QtIntPropertyManager objects. - - \sa QtAbstractEditorFactory, QtIntPropertyManager -*/ - -/*! - Creates a factory with the given \a parent. -*/ -QtSpinBoxFactory::QtSpinBoxFactory(QObject *parent) - : QtAbstractEditorFactory(parent) -{ - d_ptr = new QtSpinBoxFactoryPrivate(); - d_ptr->q_ptr = this; - -} - -/*! - Destroys this factory, and all the widgets it has created. -*/ -QtSpinBoxFactory::~QtSpinBoxFactory() -{ - qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtSpinBoxFactory::connectPropertyManager(QtIntPropertyManager *manager) -{ - connect(manager, SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotPropertyChanged(QtProperty *, int))); - connect(manager, SIGNAL(rangeChanged(QtProperty *, int, int)), - this, SLOT(slotRangeChanged(QtProperty *, int, int))); - connect(manager, SIGNAL(singleStepChanged(QtProperty *, int)), - this, SLOT(slotSingleStepChanged(QtProperty *, int))); -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -QWidget *QtSpinBoxFactory::createEditor(QtIntPropertyManager *manager, QtProperty *property, - QWidget *parent) -{ - QSpinBox *editor = d_ptr->createEditor(property, parent); - editor->setSingleStep(manager->singleStep(property)); - editor->setRange(manager->minimum(property), manager->maximum(property)); - editor->setValue(manager->value(property)); - editor->setKeyboardTracking(false); - - connect(editor, SIGNAL(valueChanged(int)), this, SLOT(slotSetValue(int))); - connect(editor, SIGNAL(destroyed(QObject *)), - this, SLOT(slotEditorDestroyed(QObject *))); - return editor; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtSpinBoxFactory::disconnectPropertyManager(QtIntPropertyManager *manager) -{ - disconnect(manager, SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotPropertyChanged(QtProperty *, int))); - disconnect(manager, SIGNAL(rangeChanged(QtProperty *, int, int)), - this, SLOT(slotRangeChanged(QtProperty *, int, int))); - disconnect(manager, SIGNAL(singleStepChanged(QtProperty *, int)), - this, SLOT(slotSingleStepChanged(QtProperty *, int))); -} - -// QtSliderFactory - -class QtSliderFactoryPrivate : public EditorFactoryPrivate -{ - QtSliderFactory *q_ptr; - Q_DECLARE_PUBLIC(QtSliderFactory) -public: - void slotPropertyChanged(QtProperty *property, int value); - void slotRangeChanged(QtProperty *property, int min, int max); - void slotSingleStepChanged(QtProperty *property, int step); - void slotSetValue(int value); -}; - -void QtSliderFactoryPrivate::slotPropertyChanged(QtProperty *property, int value) -{ - if (!m_createdEditors.contains(property)) - return; - QListIterator itEditor(m_createdEditors[property]); - while (itEditor.hasNext()) { - QSlider *editor = itEditor.next(); - editor->blockSignals(true); - editor->setValue(value); - editor->blockSignals(false); - } -} - -void QtSliderFactoryPrivate::slotRangeChanged(QtProperty *property, int min, int max) -{ - if (!m_createdEditors.contains(property)) - return; - - QtIntPropertyManager *manager = q_ptr->propertyManager(property); - if (!manager) - return; - - QListIterator itEditor(m_createdEditors[property]); - while (itEditor.hasNext()) { - QSlider *editor = itEditor.next(); - editor->blockSignals(true); - editor->setRange(min, max); - editor->setValue(manager->value(property)); - editor->blockSignals(false); - } -} - -void QtSliderFactoryPrivate::slotSingleStepChanged(QtProperty *property, int step) -{ - if (!m_createdEditors.contains(property)) - return; - QListIterator itEditor(m_createdEditors[property]); - while (itEditor.hasNext()) { - QSlider *editor = itEditor.next(); - editor->blockSignals(true); - editor->setSingleStep(step); - editor->blockSignals(false); - } -} - -void QtSliderFactoryPrivate::slotSetValue(int value) -{ - QObject *object = q_ptr->sender(); - const QMap::ConstIterator ecend = m_editorToProperty.constEnd(); - for (QMap::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor ) { - if (itEditor.key() == object) { - QtProperty *property = itEditor.value(); - QtIntPropertyManager *manager = q_ptr->propertyManager(property); - if (!manager) - return; - manager->setValue(property, value); - return; - } - } -} - -/*! - \class QtSliderFactory - - \brief The QtSliderFactory class provides QSlider widgets for - properties created by QtIntPropertyManager objects. - - \sa QtAbstractEditorFactory, QtIntPropertyManager -*/ - -/*! - Creates a factory with the given \a parent. -*/ -QtSliderFactory::QtSliderFactory(QObject *parent) - : QtAbstractEditorFactory(parent) -{ - d_ptr = new QtSliderFactoryPrivate(); - d_ptr->q_ptr = this; - -} - -/*! - Destroys this factory, and all the widgets it has created. -*/ -QtSliderFactory::~QtSliderFactory() -{ - qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtSliderFactory::connectPropertyManager(QtIntPropertyManager *manager) -{ - connect(manager, SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotPropertyChanged(QtProperty *, int))); - connect(manager, SIGNAL(rangeChanged(QtProperty *, int, int)), - this, SLOT(slotRangeChanged(QtProperty *, int, int))); - connect(manager, SIGNAL(singleStepChanged(QtProperty *, int)), - this, SLOT(slotSingleStepChanged(QtProperty *, int))); -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -QWidget *QtSliderFactory::createEditor(QtIntPropertyManager *manager, QtProperty *property, - QWidget *parent) -{ - QSlider *editor = new QSlider(Qt::Horizontal, parent); - d_ptr->initializeEditor(property, editor); - editor->setSingleStep(manager->singleStep(property)); - editor->setRange(manager->minimum(property), manager->maximum(property)); - editor->setValue(manager->value(property)); - - connect(editor, SIGNAL(valueChanged(int)), this, SLOT(slotSetValue(int))); - connect(editor, SIGNAL(destroyed(QObject *)), - this, SLOT(slotEditorDestroyed(QObject *))); - return editor; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtSliderFactory::disconnectPropertyManager(QtIntPropertyManager *manager) -{ - disconnect(manager, SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotPropertyChanged(QtProperty *, int))); - disconnect(manager, SIGNAL(rangeChanged(QtProperty *, int, int)), - this, SLOT(slotRangeChanged(QtProperty *, int, int))); - disconnect(manager, SIGNAL(singleStepChanged(QtProperty *, int)), - this, SLOT(slotSingleStepChanged(QtProperty *, int))); -} - -// QtSliderFactory - -class QtScrollBarFactoryPrivate : public EditorFactoryPrivate -{ - QtScrollBarFactory *q_ptr; - Q_DECLARE_PUBLIC(QtScrollBarFactory) -public: - void slotPropertyChanged(QtProperty *property, int value); - void slotRangeChanged(QtProperty *property, int min, int max); - void slotSingleStepChanged(QtProperty *property, int step); - void slotSetValue(int value); -}; - -void QtScrollBarFactoryPrivate::slotPropertyChanged(QtProperty *property, int value) -{ - if (!m_createdEditors.contains(property)) - return; - - QListIterator itEditor( m_createdEditors[property]); - while (itEditor.hasNext()) { - QScrollBar *editor = itEditor.next(); - editor->blockSignals(true); - editor->setValue(value); - editor->blockSignals(false); - } -} - -void QtScrollBarFactoryPrivate::slotRangeChanged(QtProperty *property, int min, int max) -{ - if (!m_createdEditors.contains(property)) - return; - - QtIntPropertyManager *manager = q_ptr->propertyManager(property); - if (!manager) - return; - - QListIterator itEditor( m_createdEditors[property]); - while (itEditor.hasNext()) { - QScrollBar *editor = itEditor.next(); - editor->blockSignals(true); - editor->setRange(min, max); - editor->setValue(manager->value(property)); - editor->blockSignals(false); - } -} - -void QtScrollBarFactoryPrivate::slotSingleStepChanged(QtProperty *property, int step) -{ - if (!m_createdEditors.contains(property)) - return; - QListIterator itEditor(m_createdEditors[property]); - while (itEditor.hasNext()) { - QScrollBar *editor = itEditor.next(); - editor->blockSignals(true); - editor->setSingleStep(step); - editor->blockSignals(false); - } -} - -void QtScrollBarFactoryPrivate::slotSetValue(int value) -{ - QObject *object = q_ptr->sender(); - const QMap::ConstIterator ecend = m_editorToProperty.constEnd(); - for (QMap::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) - if (itEditor.key() == object) { - QtProperty *property = itEditor.value(); - QtIntPropertyManager *manager = q_ptr->propertyManager(property); - if (!manager) - return; - manager->setValue(property, value); - return; - } -} - -/*! - \class QtScrollBarFactory - - \brief The QtScrollBarFactory class provides QScrollBar widgets for - properties created by QtIntPropertyManager objects. - - \sa QtAbstractEditorFactory, QtIntPropertyManager -*/ - -/*! - Creates a factory with the given \a parent. -*/ -QtScrollBarFactory::QtScrollBarFactory(QObject *parent) - : QtAbstractEditorFactory(parent) -{ - d_ptr = new QtScrollBarFactoryPrivate(); - d_ptr->q_ptr = this; - -} - -/*! - Destroys this factory, and all the widgets it has created. -*/ -QtScrollBarFactory::~QtScrollBarFactory() -{ - qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtScrollBarFactory::connectPropertyManager(QtIntPropertyManager *manager) -{ - connect(manager, SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotPropertyChanged(QtProperty *, int))); - connect(manager, SIGNAL(rangeChanged(QtProperty *, int, int)), - this, SLOT(slotRangeChanged(QtProperty *, int, int))); - connect(manager, SIGNAL(singleStepChanged(QtProperty *, int)), - this, SLOT(slotSingleStepChanged(QtProperty *, int))); -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -QWidget *QtScrollBarFactory::createEditor(QtIntPropertyManager *manager, QtProperty *property, - QWidget *parent) -{ - QScrollBar *editor = new QScrollBar(Qt::Horizontal, parent); - d_ptr->initializeEditor(property, editor); - editor->setSingleStep(manager->singleStep(property)); - editor->setRange(manager->minimum(property), manager->maximum(property)); - editor->setValue(manager->value(property)); - connect(editor, SIGNAL(valueChanged(int)), this, SLOT(slotSetValue(int))); - connect(editor, SIGNAL(destroyed(QObject *)), - this, SLOT(slotEditorDestroyed(QObject *))); - return editor; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtScrollBarFactory::disconnectPropertyManager(QtIntPropertyManager *manager) -{ - disconnect(manager, SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotPropertyChanged(QtProperty *, int))); - disconnect(manager, SIGNAL(rangeChanged(QtProperty *, int, int)), - this, SLOT(slotRangeChanged(QtProperty *, int, int))); - disconnect(manager, SIGNAL(singleStepChanged(QtProperty *, int)), - this, SLOT(slotSingleStepChanged(QtProperty *, int))); -} - -// QtCheckBoxFactory - -class QtCheckBoxFactoryPrivate : public EditorFactoryPrivate -{ - QtCheckBoxFactory *q_ptr; - Q_DECLARE_PUBLIC(QtCheckBoxFactory) -public: - void slotPropertyChanged(QtProperty *property, bool value); - void slotSetValue(bool value); -}; - -void QtCheckBoxFactoryPrivate::slotPropertyChanged(QtProperty *property, bool value) -{ - if (!m_createdEditors.contains(property)) - return; - - QListIterator itEditor(m_createdEditors[property]); - while (itEditor.hasNext()) { - QtBoolEdit *editor = itEditor.next(); - editor->blockCheckBoxSignals(true); - editor->setChecked(value); - editor->blockCheckBoxSignals(false); - } -} - -void QtCheckBoxFactoryPrivate::slotSetValue(bool value) -{ - QObject *object = q_ptr->sender(); - - const QMap::ConstIterator ecend = m_editorToProperty.constEnd(); - for (QMap::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) - if (itEditor.key() == object) { - QtProperty *property = itEditor.value(); - QtBoolPropertyManager *manager = q_ptr->propertyManager(property); - if (!manager) - return; - manager->setValue(property, value); - return; - } -} - -/*! - \class QtCheckBoxFactory - - \brief The QtCheckBoxFactory class provides QCheckBox widgets for - properties created by QtBoolPropertyManager objects. - - \sa QtAbstractEditorFactory, QtBoolPropertyManager -*/ - -/*! - Creates a factory with the given \a parent. -*/ -QtCheckBoxFactory::QtCheckBoxFactory(QObject *parent) - : QtAbstractEditorFactory(parent) -{ - d_ptr = new QtCheckBoxFactoryPrivate(); - d_ptr->q_ptr = this; - -} - -/*! - Destroys this factory, and all the widgets it has created. -*/ -QtCheckBoxFactory::~QtCheckBoxFactory() -{ - qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtCheckBoxFactory::connectPropertyManager(QtBoolPropertyManager *manager) -{ - connect(manager, SIGNAL(valueChanged(QtProperty *, bool)), - this, SLOT(slotPropertyChanged(QtProperty *, bool))); -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -QWidget *QtCheckBoxFactory::createEditor(QtBoolPropertyManager *manager, QtProperty *property, - QWidget *parent) -{ - QtBoolEdit *editor = d_ptr->createEditor(property, parent); - editor->setChecked(manager->value(property)); - editor->setTextVisible(false); - - connect(editor, SIGNAL(toggled(bool)), this, SLOT(slotSetValue(bool))); - connect(editor, SIGNAL(destroyed(QObject *)), - this, SLOT(slotEditorDestroyed(QObject *))); - return editor; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtCheckBoxFactory::disconnectPropertyManager(QtBoolPropertyManager *manager) -{ - disconnect(manager, SIGNAL(valueChanged(QtProperty *, bool)), - this, SLOT(slotPropertyChanged(QtProperty *, bool))); -} - -// QtDoubleSpinBoxFactory - -class QtDoubleSpinBoxFactoryPrivate : public EditorFactoryPrivate -{ - QtDoubleSpinBoxFactory *q_ptr; - Q_DECLARE_PUBLIC(QtDoubleSpinBoxFactory) -public: - - void slotPropertyChanged(QtProperty *property, double value); - void slotRangeChanged(QtProperty *property, double min, double max); - void slotSingleStepChanged(QtProperty *property, double step); - void slotDecimalsChanged(QtProperty *property, int prec); - void slotSetValue(double value); -}; - -void QtDoubleSpinBoxFactoryPrivate::slotPropertyChanged(QtProperty *property, double value) -{ - QList editors = m_createdEditors[property]; - QListIterator itEditor(m_createdEditors[property]); - while (itEditor.hasNext()) { - QDoubleSpinBox *editor = itEditor.next(); - if (editor->value() != value) { - editor->blockSignals(true); - editor->setValue(value); - editor->blockSignals(false); - } - } -} - -void QtDoubleSpinBoxFactoryPrivate::slotRangeChanged(QtProperty *property, - double min, double max) -{ - if (!m_createdEditors.contains(property)) - return; - - QtDoublePropertyManager *manager = q_ptr->propertyManager(property); - if (!manager) - return; - - QList editors = m_createdEditors[property]; - QListIterator itEditor(editors); - while (itEditor.hasNext()) { - QDoubleSpinBox *editor = itEditor.next(); - editor->blockSignals(true); - editor->setRange(min, max); - editor->setValue(manager->value(property)); - editor->blockSignals(false); - } -} - -void QtDoubleSpinBoxFactoryPrivate::slotSingleStepChanged(QtProperty *property, double step) -{ - if (!m_createdEditors.contains(property)) - return; - - QtDoublePropertyManager *manager = q_ptr->propertyManager(property); - if (!manager) - return; - - QList editors = m_createdEditors[property]; - QListIterator itEditor(editors); - while (itEditor.hasNext()) { - QDoubleSpinBox *editor = itEditor.next(); - editor->blockSignals(true); - editor->setSingleStep(step); - editor->blockSignals(false); - } -} - -void QtDoubleSpinBoxFactoryPrivate::slotDecimalsChanged(QtProperty *property, int prec) -{ - if (!m_createdEditors.contains(property)) - return; - - QtDoublePropertyManager *manager = q_ptr->propertyManager(property); - if (!manager) - return; - - QList editors = m_createdEditors[property]; - QListIterator itEditor(editors); - while (itEditor.hasNext()) { - QDoubleSpinBox *editor = itEditor.next(); - editor->blockSignals(true); - editor->setDecimals(prec); - editor->setValue(manager->value(property)); - editor->blockSignals(false); - } -} - -void QtDoubleSpinBoxFactoryPrivate::slotSetValue(double value) -{ - QObject *object = q_ptr->sender(); - const QMap::ConstIterator itcend = m_editorToProperty.constEnd(); - for (QMap::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != itcend; ++itEditor) { - if (itEditor.key() == object) { - QtProperty *property = itEditor.value(); - QtDoublePropertyManager *manager = q_ptr->propertyManager(property); - if (!manager) - return; - manager->setValue(property, value); - return; - } - } -} - -/*! \class QtDoubleSpinBoxFactory - - \brief The QtDoubleSpinBoxFactory class provides QDoubleSpinBox - widgets for properties created by QtDoublePropertyManager objects. - - \sa QtAbstractEditorFactory, QtDoublePropertyManager -*/ - -/*! - Creates a factory with the given \a parent. -*/ -QtDoubleSpinBoxFactory::QtDoubleSpinBoxFactory(QObject *parent) - : QtAbstractEditorFactory(parent) -{ - d_ptr = new QtDoubleSpinBoxFactoryPrivate(); - d_ptr->q_ptr = this; - -} - -/*! - Destroys this factory, and all the widgets it has created. -*/ -QtDoubleSpinBoxFactory::~QtDoubleSpinBoxFactory() -{ - qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtDoubleSpinBoxFactory::connectPropertyManager(QtDoublePropertyManager *manager) -{ - connect(manager, SIGNAL(valueChanged(QtProperty *, double)), - this, SLOT(slotPropertyChanged(QtProperty *, double))); - connect(manager, SIGNAL(rangeChanged(QtProperty *, double, double)), - this, SLOT(slotRangeChanged(QtProperty *, double, double))); - connect(manager, SIGNAL(singleStepChanged(QtProperty *, double)), - this, SLOT(slotSingleStepChanged(QtProperty *, double))); - connect(manager, SIGNAL(decimalsChanged(QtProperty *, int)), - this, SLOT(slotDecimalsChanged(QtProperty *, int))); -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -QWidget *QtDoubleSpinBoxFactory::createEditor(QtDoublePropertyManager *manager, - QtProperty *property, QWidget *parent) -{ - QDoubleSpinBox *editor = d_ptr->createEditor(property, parent); - editor->setSingleStep(manager->singleStep(property)); - editor->setDecimals(manager->decimals(property)); - editor->setRange(manager->minimum(property), manager->maximum(property)); - editor->setValue(manager->value(property)); - editor->setKeyboardTracking(false); - - connect(editor, SIGNAL(valueChanged(double)), this, SLOT(slotSetValue(double))); - connect(editor, SIGNAL(destroyed(QObject *)), - this, SLOT(slotEditorDestroyed(QObject *))); - return editor; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtDoubleSpinBoxFactory::disconnectPropertyManager(QtDoublePropertyManager *manager) -{ - disconnect(manager, SIGNAL(valueChanged(QtProperty *, double)), - this, SLOT(slotPropertyChanged(QtProperty *, double))); - disconnect(manager, SIGNAL(rangeChanged(QtProperty *, double, double)), - this, SLOT(slotRangeChanged(QtProperty *, double, double))); - disconnect(manager, SIGNAL(singleStepChanged(QtProperty *, double)), - this, SLOT(slotSingleStepChanged(QtProperty *, double))); - disconnect(manager, SIGNAL(decimalsChanged(QtProperty *, int)), - this, SLOT(slotDecimalsChanged(QtProperty *, int))); -} - -// QtLineEditFactory - -class QtLineEditFactoryPrivate : public EditorFactoryPrivate -{ - QtLineEditFactory *q_ptr; - Q_DECLARE_PUBLIC(QtLineEditFactory) -public: - - void slotPropertyChanged(QtProperty *property, const QString &value); - void slotRegExpChanged(QtProperty *property, const QRegExp ®Exp); - void slotSetValue(const QString &value); - void slotEditingFinished(); -}; - -void QtLineEditFactoryPrivate::slotPropertyChanged(QtProperty *property, - const QString &value) -{ - if (!m_createdEditors.contains(property)) - return; - - QListIterator itEditor( m_createdEditors[property]); - while (itEditor.hasNext()) { - QLineEdit *editor = itEditor.next(); - if (editor->text() != value) - editor->setText(value); - } -} - -void QtLineEditFactoryPrivate::slotRegExpChanged(QtProperty *property, - const QRegExp ®Exp) -{ - if (!m_createdEditors.contains(property)) - return; - - QtStringPropertyManager *manager = q_ptr->propertyManager(property); - if (!manager) - return; - - QListIterator itEditor(m_createdEditors[property]); - while (itEditor.hasNext()) { - QLineEdit *editor = itEditor.next(); - editor->blockSignals(true); - const QValidator *oldValidator = editor->validator(); - QValidator *newValidator = 0; - if (regExp.isValid()) { - newValidator = new QRegExpValidator(regExp, editor); - } - editor->setValidator(newValidator); - if (oldValidator) - delete oldValidator; - editor->blockSignals(false); - } -} - -void QtLineEditFactoryPrivate::slotSetValue(const QString &value) -{ - QObject *object = q_ptr->sender(); - const QMap::ConstIterator ecend = m_editorToProperty.constEnd(); - for (QMap::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) - if (itEditor.key() == object) { - QtProperty *property = itEditor.value(); - QtStringPropertyManager *manager = q_ptr->propertyManager(property); - if (!manager) - return; - manager->setValue(property, value); - return; - } -} - -void QtLineEditFactoryPrivate::slotEditingFinished() -{ - QObject *object = q_ptr->sender(); - const QMap::ConstIterator ecend = m_editorToProperty.constEnd(); - for (QMap::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) - { - if (itEditor.key() == object) - { - QLineEdit* sourceLineEdit = itEditor.key(); - - QtProperty *property = itEditor.value(); - QtStringPropertyManager *manager = q_ptr->propertyManager(property); - if (!manager) - return; - QString value = sourceLineEdit->text(); - manager->setValue(property, value); - return; - } - } -} - -/*! - \class QtLineEditFactory - - \brief The QtLineEditFactory class provides QLineEdit widgets for - properties created by QtStringPropertyManager objects. - - \sa QtAbstractEditorFactory, QtStringPropertyManager -*/ - -/*! - Creates a factory with the given \a parent. -*/ -QtLineEditFactory::QtLineEditFactory(QObject *parent) - : QtAbstractEditorFactory(parent) -{ - d_ptr = new QtLineEditFactoryPrivate(); - d_ptr->q_ptr = this; - -} - -/*! - Destroys this factory, and all the widgets it has created. -*/ -QtLineEditFactory::~QtLineEditFactory() -{ - qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtLineEditFactory::connectPropertyManager(QtStringPropertyManager *manager) -{ - connect(manager, SIGNAL(valueChanged(QtProperty *, const QString &)), - this, SLOT(slotPropertyChanged(QtProperty *, const QString &))); - connect(manager, SIGNAL(regExpChanged(QtProperty *, const QRegExp &)), - this, SLOT(slotRegExpChanged(QtProperty *, const QRegExp &))); -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -QWidget *QtLineEditFactory::createEditor(QtStringPropertyManager *manager, - QtProperty *property, QWidget *parent) -{ - - QLineEdit *editor = d_ptr->createEditor(property, parent); - QRegExp regExp = manager->regExp(property); - if (regExp.isValid()) { - QValidator *validator = new QRegExpValidator(regExp, editor); - editor->setValidator(validator); - } - editor->setText(manager->value(property)); - -// connect(editor, SIGNAL(textEdited(const QString &)), -// this, SLOT(slotSetValue(const QString &))); - connect(editor, SIGNAL(destroyed(QObject *)), - this, SLOT(slotEditorDestroyed(QObject *))); - connect(editor, SIGNAL(editingFinished()), - this, SLOT(slotEditingFinished())); - return editor; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtLineEditFactory::disconnectPropertyManager(QtStringPropertyManager *manager) -{ - disconnect(manager, SIGNAL(valueChanged(QtProperty *, const QString &)), - this, SLOT(slotPropertyChanged(QtProperty *, const QString &))); - disconnect(manager, SIGNAL(regExpChanged(QtProperty *, const QRegExp &)), - this, SLOT(slotRegExpChanged(QtProperty *, const QRegExp &))); -} - -// QtDateEditFactory - -class QtDateEditFactoryPrivate : public EditorFactoryPrivate -{ - QtDateEditFactory *q_ptr; - Q_DECLARE_PUBLIC(QtDateEditFactory) -public: - - void slotPropertyChanged(QtProperty *property, const QDate &value); - void slotRangeChanged(QtProperty *property, const QDate &min, const QDate &max); - void slotSetValue(const QDate &value); -}; - -void QtDateEditFactoryPrivate::slotPropertyChanged(QtProperty *property, const QDate &value) -{ - if (!m_createdEditors.contains(property)) - return; - QListIterator itEditor(m_createdEditors[property]); - while (itEditor.hasNext()) { - QDateEdit *editor = itEditor.next(); - editor->blockSignals(true); - editor->setDate(value); - editor->blockSignals(false); - } -} - -void QtDateEditFactoryPrivate::slotRangeChanged(QtProperty *property, - const QDate &min, const QDate &max) -{ - if (!m_createdEditors.contains(property)) - return; - - QtDatePropertyManager *manager = q_ptr->propertyManager(property); - if (!manager) - return; - - QListIterator itEditor(m_createdEditors[property]); - while (itEditor.hasNext()) { - QDateEdit *editor = itEditor.next(); - editor->blockSignals(true); - editor->setDateRange(min, max); - editor->setDate(manager->value(property)); - editor->blockSignals(false); - } -} - -void QtDateEditFactoryPrivate::slotSetValue(const QDate &value) -{ - QObject *object = q_ptr->sender(); - const QMap::ConstIterator ecend = m_editorToProperty.constEnd(); - for (QMap::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) - if (itEditor.key() == object) { - QtProperty *property = itEditor.value(); - QtDatePropertyManager *manager = q_ptr->propertyManager(property); - if (!manager) - return; - manager->setValue(property, value); - return; - } -} - -/*! - \class QtDateEditFactory - - \brief The QtDateEditFactory class provides QDateEdit widgets for - properties created by QtDatePropertyManager objects. - - \sa QtAbstractEditorFactory, QtDatePropertyManager -*/ - -/*! - Creates a factory with the given \a parent. -*/ -QtDateEditFactory::QtDateEditFactory(QObject *parent) - : QtAbstractEditorFactory(parent) -{ - d_ptr = new QtDateEditFactoryPrivate(); - d_ptr->q_ptr = this; - -} - -/*! - Destroys this factory, and all the widgets it has created. -*/ -QtDateEditFactory::~QtDateEditFactory() -{ - qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtDateEditFactory::connectPropertyManager(QtDatePropertyManager *manager) -{ - connect(manager, SIGNAL(valueChanged(QtProperty *, const QDate &)), - this, SLOT(slotPropertyChanged(QtProperty *, const QDate &))); - connect(manager, SIGNAL(rangeChanged(QtProperty *, const QDate &, const QDate &)), - this, SLOT(slotRangeChanged(QtProperty *, const QDate &, const QDate &))); -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -QWidget *QtDateEditFactory::createEditor(QtDatePropertyManager *manager, QtProperty *property, - QWidget *parent) -{ - QDateEdit *editor = d_ptr->createEditor(property, parent); - editor->setCalendarPopup(true); - editor->setDateRange(manager->minimum(property), manager->maximum(property)); - editor->setDate(manager->value(property)); - - connect(editor, SIGNAL(dateChanged(const QDate &)), - this, SLOT(slotSetValue(const QDate &))); - connect(editor, SIGNAL(destroyed(QObject *)), - this, SLOT(slotEditorDestroyed(QObject *))); - return editor; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtDateEditFactory::disconnectPropertyManager(QtDatePropertyManager *manager) -{ - disconnect(manager, SIGNAL(valueChanged(QtProperty *, const QDate &)), - this, SLOT(slotPropertyChanged(QtProperty *, const QDate &))); - disconnect(manager, SIGNAL(rangeChanged(QtProperty *, const QDate &, const QDate &)), - this, SLOT(slotRangeChanged(QtProperty *, const QDate &, const QDate &))); -} - -// QtTimeEditFactory - -class QtTimeEditFactoryPrivate : public EditorFactoryPrivate -{ - QtTimeEditFactory *q_ptr; - Q_DECLARE_PUBLIC(QtTimeEditFactory) -public: - - void slotPropertyChanged(QtProperty *property, const QTime &value); - void slotSetValue(const QTime &value); -}; - -void QtTimeEditFactoryPrivate::slotPropertyChanged(QtProperty *property, const QTime &value) -{ - if (!m_createdEditors.contains(property)) - return; - QListIterator itEditor(m_createdEditors[property]); - while (itEditor.hasNext()) { - QTimeEdit *editor = itEditor.next(); - editor->blockSignals(true); - editor->setTime(value); - editor->blockSignals(false); - } -} - -void QtTimeEditFactoryPrivate::slotSetValue(const QTime &value) -{ - QObject *object = q_ptr->sender(); - const QMap::ConstIterator ecend = m_editorToProperty.constEnd(); - for (QMap::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) - if (itEditor.key() == object) { - QtProperty *property = itEditor.value(); - QtTimePropertyManager *manager = q_ptr->propertyManager(property); - if (!manager) - return; - manager->setValue(property, value); - return; - } -} - -/*! - \class QtTimeEditFactory - - \brief The QtTimeEditFactory class provides QTimeEdit widgets for - properties created by QtTimePropertyManager objects. - - \sa QtAbstractEditorFactory, QtTimePropertyManager -*/ - -/*! - Creates a factory with the given \a parent. -*/ -QtTimeEditFactory::QtTimeEditFactory(QObject *parent) - : QtAbstractEditorFactory(parent) -{ - d_ptr = new QtTimeEditFactoryPrivate(); - d_ptr->q_ptr = this; - -} - -/*! - Destroys this factory, and all the widgets it has created. -*/ -QtTimeEditFactory::~QtTimeEditFactory() -{ - qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtTimeEditFactory::connectPropertyManager(QtTimePropertyManager *manager) -{ - connect(manager, SIGNAL(valueChanged(QtProperty *, const QTime &)), - this, SLOT(slotPropertyChanged(QtProperty *, const QTime &))); -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -QWidget *QtTimeEditFactory::createEditor(QtTimePropertyManager *manager, QtProperty *property, - QWidget *parent) -{ - QTimeEdit *editor = d_ptr->createEditor(property, parent); - editor->setTime(manager->value(property)); - - connect(editor, SIGNAL(timeChanged(const QTime &)), - this, SLOT(slotSetValue(const QTime &))); - connect(editor, SIGNAL(destroyed(QObject *)), - this, SLOT(slotEditorDestroyed(QObject *))); - return editor; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtTimeEditFactory::disconnectPropertyManager(QtTimePropertyManager *manager) -{ - disconnect(manager, SIGNAL(valueChanged(QtProperty *, const QTime &)), - this, SLOT(slotPropertyChanged(QtProperty *, const QTime &))); -} - -// QtDateTimeEditFactory - -class QtDateTimeEditFactoryPrivate : public EditorFactoryPrivate -{ - QtDateTimeEditFactory *q_ptr; - Q_DECLARE_PUBLIC(QtDateTimeEditFactory) -public: - - void slotPropertyChanged(QtProperty *property, const QDateTime &value); - void slotSetValue(const QDateTime &value); - -}; - -void QtDateTimeEditFactoryPrivate::slotPropertyChanged(QtProperty *property, - const QDateTime &value) -{ - if (!m_createdEditors.contains(property)) - return; - - QListIterator itEditor(m_createdEditors[property]); - while (itEditor.hasNext()) { - QDateTimeEdit *editor = itEditor.next(); - editor->blockSignals(true); - editor->setDateTime(value); - editor->blockSignals(false); - } -} - -void QtDateTimeEditFactoryPrivate::slotSetValue(const QDateTime &value) -{ - QObject *object = q_ptr->sender(); - const QMap::ConstIterator ecend = m_editorToProperty.constEnd(); - for (QMap::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) - if (itEditor.key() == object) { - QtProperty *property = itEditor.value(); - QtDateTimePropertyManager *manager = q_ptr->propertyManager(property); - if (!manager) - return; - manager->setValue(property, value); - return; - } -} - -/*! - \class QtDateTimeEditFactory - - \brief The QtDateTimeEditFactory class provides QDateTimeEdit - widgets for properties created by QtDateTimePropertyManager objects. - - \sa QtAbstractEditorFactory, QtDateTimePropertyManager -*/ - -/*! - Creates a factory with the given \a parent. -*/ -QtDateTimeEditFactory::QtDateTimeEditFactory(QObject *parent) - : QtAbstractEditorFactory(parent) -{ - d_ptr = new QtDateTimeEditFactoryPrivate(); - d_ptr->q_ptr = this; - -} - -/*! - Destroys this factory, and all the widgets it has created. -*/ -QtDateTimeEditFactory::~QtDateTimeEditFactory() -{ - qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtDateTimeEditFactory::connectPropertyManager(QtDateTimePropertyManager *manager) -{ - connect(manager, SIGNAL(valueChanged(QtProperty *, const QDateTime &)), - this, SLOT(slotPropertyChanged(QtProperty *, const QDateTime &))); -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -QWidget *QtDateTimeEditFactory::createEditor(QtDateTimePropertyManager *manager, - QtProperty *property, QWidget *parent) -{ - QDateTimeEdit *editor = d_ptr->createEditor(property, parent); - editor->setDateTime(manager->value(property)); - - connect(editor, SIGNAL(dateTimeChanged(const QDateTime &)), - this, SLOT(slotSetValue(const QDateTime &))); - connect(editor, SIGNAL(destroyed(QObject *)), - this, SLOT(slotEditorDestroyed(QObject *))); - return editor; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtDateTimeEditFactory::disconnectPropertyManager(QtDateTimePropertyManager *manager) -{ - disconnect(manager, SIGNAL(valueChanged(QtProperty *, const QDateTime &)), - this, SLOT(slotPropertyChanged(QtProperty *, const QDateTime &))); -} - -// QtKeySequenceEditorFactory - -class QtKeySequenceEditorFactoryPrivate : public EditorFactoryPrivate -{ - QtKeySequenceEditorFactory *q_ptr; - Q_DECLARE_PUBLIC(QtKeySequenceEditorFactory) -public: - - void slotPropertyChanged(QtProperty *property, const QKeySequence &value); - void slotSetValue(const QKeySequence &value); -}; - -void QtKeySequenceEditorFactoryPrivate::slotPropertyChanged(QtProperty *property, - const QKeySequence &value) -{ - if (!m_createdEditors.contains(property)) - return; - - QListIterator itEditor(m_createdEditors[property]); - while (itEditor.hasNext()) { - QtKeySequenceEdit *editor = itEditor.next(); - editor->blockSignals(true); - editor->setKeySequence(value); - editor->blockSignals(false); - } -} - -void QtKeySequenceEditorFactoryPrivate::slotSetValue(const QKeySequence &value) -{ - QObject *object = q_ptr->sender(); - const QMap::ConstIterator ecend = m_editorToProperty.constEnd(); - for (QMap::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) - if (itEditor.key() == object) { - QtProperty *property = itEditor.value(); - QtKeySequencePropertyManager *manager = q_ptr->propertyManager(property); - if (!manager) - return; - manager->setValue(property, value); - return; - } -} - -/*! - \class QtKeySequenceEditorFactory - - \brief The QtKeySequenceEditorFactory class provides editor - widgets for properties created by QtKeySequencePropertyManager objects. - - \sa QtAbstractEditorFactory -*/ - -/*! - Creates a factory with the given \a parent. -*/ -QtKeySequenceEditorFactory::QtKeySequenceEditorFactory(QObject *parent) - : QtAbstractEditorFactory(parent) -{ - d_ptr = new QtKeySequenceEditorFactoryPrivate(); - d_ptr->q_ptr = this; - -} - -/*! - Destroys this factory, and all the widgets it has created. -*/ -QtKeySequenceEditorFactory::~QtKeySequenceEditorFactory() -{ - qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtKeySequenceEditorFactory::connectPropertyManager(QtKeySequencePropertyManager *manager) -{ - connect(manager, SIGNAL(valueChanged(QtProperty *, const QKeySequence &)), - this, SLOT(slotPropertyChanged(QtProperty *, const QKeySequence &))); -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -QWidget *QtKeySequenceEditorFactory::createEditor(QtKeySequencePropertyManager *manager, - QtProperty *property, QWidget *parent) -{ - QtKeySequenceEdit *editor = d_ptr->createEditor(property, parent); - editor->setKeySequence(manager->value(property)); - - connect(editor, SIGNAL(keySequenceChanged(const QKeySequence &)), - this, SLOT(slotSetValue(const QKeySequence &))); - connect(editor, SIGNAL(destroyed(QObject *)), - this, SLOT(slotEditorDestroyed(QObject *))); - return editor; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtKeySequenceEditorFactory::disconnectPropertyManager(QtKeySequencePropertyManager *manager) -{ - disconnect(manager, SIGNAL(valueChanged(QtProperty *, const QKeySequence &)), - this, SLOT(slotPropertyChanged(QtProperty *, const QKeySequence &))); -} - -// QtCharEdit - -class QtCharEdit : public QWidget -{ - Q_OBJECT -public: - QtCharEdit(QWidget *parent = 0); - - QChar value() const; - bool eventFilter(QObject *o, QEvent *e); -public Q_SLOTS: - void setValue(const QChar &value); -Q_SIGNALS: - void valueChanged(const QChar &value); -protected: - void focusInEvent(QFocusEvent *e); - void focusOutEvent(QFocusEvent *e); - void keyPressEvent(QKeyEvent *e); - void keyReleaseEvent(QKeyEvent *e); - bool event(QEvent *e); -private slots: - void slotClearChar(); -private: - void handleKeyEvent(QKeyEvent *e); - - QChar m_value; - QLineEdit *m_lineEdit; -}; - -QtCharEdit::QtCharEdit(QWidget *parent) - : QWidget(parent), m_lineEdit(new QLineEdit(this)) -{ - QHBoxLayout *layout = new QHBoxLayout(this); - layout->addWidget(m_lineEdit); - layout->setMargin(0); - m_lineEdit->installEventFilter(this); - m_lineEdit->setReadOnly(true); - m_lineEdit->setFocusProxy(this); - setFocusPolicy(m_lineEdit->focusPolicy()); - setAttribute(Qt::WA_InputMethodEnabled); -} - -bool QtCharEdit::eventFilter(QObject *o, QEvent *e) -{ - if (o == m_lineEdit && e->type() == QEvent::ContextMenu) { - QContextMenuEvent *c = static_cast(e); - QMenu *menu = m_lineEdit->createStandardContextMenu(); - QList actions = menu->actions(); - QListIterator itAction(actions); - while (itAction.hasNext()) { - QAction *action = itAction.next(); - action->setShortcut(QKeySequence()); - QString actionString = action->text(); - const int pos = actionString.lastIndexOf(QLatin1Char('\t')); - if (pos > 0) - actionString = actionString.remove(pos, actionString.length() - pos); - action->setText(actionString); - } - QAction *actionBefore = 0; - if (actions.count() > 0) - actionBefore = actions[0]; - QAction *clearAction = new QAction(tr("Clear Char"), menu); - menu->insertAction(actionBefore, clearAction); - menu->insertSeparator(actionBefore); - clearAction->setEnabled(!m_value.isNull()); - connect(clearAction, SIGNAL(triggered()), this, SLOT(slotClearChar())); - menu->exec(c->globalPos()); - delete menu; - e->accept(); - return true; - } - - return QWidget::eventFilter(o, e); -} - -void QtCharEdit::slotClearChar() -{ - if (m_value.isNull()) - return; - setValue(QChar()); - emit valueChanged(m_value); -} - -void QtCharEdit::handleKeyEvent(QKeyEvent *e) -{ - const int key = e->key(); - switch (key) { - case Qt::Key_Control: - case Qt::Key_Shift: - case Qt::Key_Meta: - case Qt::Key_Alt: - case Qt::Key_Super_L: - case Qt::Key_Return: - return; - default: - break; - } - - const QString text = e->text(); - if (text.count() != 1) - return; - - const QChar c = text.at(0); - if (!c.isPrint()) - return; - - if (m_value == c) - return; - - m_value = c; - const QString str = m_value.isNull() ? QString() : QString(m_value); - m_lineEdit->setText(str); - e->accept(); - emit valueChanged(m_value); -} - -void QtCharEdit::setValue(const QChar &value) -{ - if (value == m_value) - return; - - m_value = value; - QString str = value.isNull() ? QString() : QString(value); - m_lineEdit->setText(str); -} - -QChar QtCharEdit::value() const -{ - return m_value; -} - -void QtCharEdit::focusInEvent(QFocusEvent *e) -{ - m_lineEdit->event(e); - m_lineEdit->selectAll(); - QWidget::focusInEvent(e); -} - -void QtCharEdit::focusOutEvent(QFocusEvent *e) -{ - m_lineEdit->event(e); - QWidget::focusOutEvent(e); -} - -void QtCharEdit::keyPressEvent(QKeyEvent *e) -{ - handleKeyEvent(e); - e->accept(); -} - -void QtCharEdit::keyReleaseEvent(QKeyEvent *e) -{ - m_lineEdit->event(e); -} - -bool QtCharEdit::event(QEvent *e) -{ - switch(e->type()) { - case QEvent::Shortcut: - case QEvent::ShortcutOverride: - case QEvent::KeyRelease: - e->accept(); - return true; - default: - break; - } - return QWidget::event(e); -} - -// QtCharEditorFactory - -class QtCharEditorFactoryPrivate : public EditorFactoryPrivate -{ - QtCharEditorFactory *q_ptr; - Q_DECLARE_PUBLIC(QtCharEditorFactory) -public: - - void slotPropertyChanged(QtProperty *property, const QChar &value); - void slotSetValue(const QChar &value); - -}; - -void QtCharEditorFactoryPrivate::slotPropertyChanged(QtProperty *property, - const QChar &value) -{ - if (!m_createdEditors.contains(property)) - return; - - QListIterator itEditor(m_createdEditors[property]); - while (itEditor.hasNext()) { - QtCharEdit *editor = itEditor.next(); - editor->blockSignals(true); - editor->setValue(value); - editor->blockSignals(false); - } -} - -void QtCharEditorFactoryPrivate::slotSetValue(const QChar &value) -{ - QObject *object = q_ptr->sender(); - const QMap::ConstIterator ecend = m_editorToProperty.constEnd(); - for (QMap::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) - if (itEditor.key() == object) { - QtProperty *property = itEditor.value(); - QtCharPropertyManager *manager = q_ptr->propertyManager(property); - if (!manager) - return; - manager->setValue(property, value); - return; - } -} - -/*! - \class QtCharEditorFactory - - \brief The QtCharEditorFactory class provides editor - widgets for properties created by QtCharPropertyManager objects. - - \sa QtAbstractEditorFactory -*/ - -/*! - Creates a factory with the given \a parent. -*/ -QtCharEditorFactory::QtCharEditorFactory(QObject *parent) - : QtAbstractEditorFactory(parent) -{ - d_ptr = new QtCharEditorFactoryPrivate(); - d_ptr->q_ptr = this; - -} - -/*! - Destroys this factory, and all the widgets it has created. -*/ -QtCharEditorFactory::~QtCharEditorFactory() -{ - qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtCharEditorFactory::connectPropertyManager(QtCharPropertyManager *manager) -{ - connect(manager, SIGNAL(valueChanged(QtProperty *, const QChar &)), - this, SLOT(slotPropertyChanged(QtProperty *, const QChar &))); -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -QWidget *QtCharEditorFactory::createEditor(QtCharPropertyManager *manager, - QtProperty *property, QWidget *parent) -{ - QtCharEdit *editor = d_ptr->createEditor(property, parent); - editor->setValue(manager->value(property)); - - connect(editor, SIGNAL(valueChanged(const QChar &)), - this, SLOT(slotSetValue(const QChar &))); - connect(editor, SIGNAL(destroyed(QObject *)), - this, SLOT(slotEditorDestroyed(QObject *))); - return editor; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtCharEditorFactory::disconnectPropertyManager(QtCharPropertyManager *manager) -{ - disconnect(manager, SIGNAL(valueChanged(QtProperty *, const QChar &)), - this, SLOT(slotPropertyChanged(QtProperty *, const QChar &))); -} - -// QtEnumEditorFactory - -class QtEnumEditorFactoryPrivate : public EditorFactoryPrivate -{ - QtEnumEditorFactory *q_ptr; - Q_DECLARE_PUBLIC(QtEnumEditorFactory) -public: - - void slotPropertyChanged(QtProperty *property, int value); - void slotEnumNamesChanged(QtProperty *property, const QStringList &); - void slotEnumIconsChanged(QtProperty *property, const QMap &); - void slotSetValue(int value); -}; - -void QtEnumEditorFactoryPrivate::slotPropertyChanged(QtProperty *property, int value) -{ - if (!m_createdEditors.contains(property)) - return; - - QListIterator itEditor(m_createdEditors[property]); - while (itEditor.hasNext()) { - QComboBox *editor = itEditor.next(); - editor->blockSignals(true); - editor->setCurrentIndex(value); - editor->blockSignals(false); - } -} - -void QtEnumEditorFactoryPrivate::slotEnumNamesChanged(QtProperty *property, - const QStringList &enumNames) -{ - if (!m_createdEditors.contains(property)) - return; - - QtEnumPropertyManager *manager = q_ptr->propertyManager(property); - if (!manager) - return; - - QMap enumIcons = manager->enumIcons(property); - - QListIterator itEditor(m_createdEditors[property]); - while (itEditor.hasNext()) { - QComboBox *editor = itEditor.next(); - editor->blockSignals(true); - editor->clear(); - editor->addItems(enumNames); - const int nameCount = enumNames.count(); - for (int i = 0; i < nameCount; i++) - editor->setItemIcon(i, enumIcons.value(i)); - editor->setCurrentIndex(manager->value(property)); - editor->blockSignals(false); - } -} - -void QtEnumEditorFactoryPrivate::slotEnumIconsChanged(QtProperty *property, - const QMap &enumIcons) -{ - if (!m_createdEditors.contains(property)) - return; - - QtEnumPropertyManager *manager = q_ptr->propertyManager(property); - if (!manager) - return; - - const QStringList enumNames = manager->enumNames(property); - QListIterator itEditor(m_createdEditors[property]); - while (itEditor.hasNext()) { - QComboBox *editor = itEditor.next(); - editor->blockSignals(true); - const int nameCount = enumNames.count(); - for (int i = 0; i < nameCount; i++) - editor->setItemIcon(i, enumIcons.value(i)); - editor->setCurrentIndex(manager->value(property)); - editor->blockSignals(false); - } -} - -void QtEnumEditorFactoryPrivate::slotSetValue(int value) -{ - QObject *object = q_ptr->sender(); - const QMap::ConstIterator ecend = m_editorToProperty.constEnd(); - for (QMap::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) - if (itEditor.key() == object) { - QtProperty *property = itEditor.value(); - QtEnumPropertyManager *manager = q_ptr->propertyManager(property); - if (!manager) - return; - manager->setValue(property, value); - return; - } -} - -/*! - \class QtEnumEditorFactory - - \brief The QtEnumEditorFactory class provides QComboBox widgets for - properties created by QtEnumPropertyManager objects. - - \sa QtAbstractEditorFactory, QtEnumPropertyManager -*/ - -/*! - Creates a factory with the given \a parent. -*/ -QtEnumEditorFactory::QtEnumEditorFactory(QObject *parent) - : QtAbstractEditorFactory(parent) -{ - d_ptr = new QtEnumEditorFactoryPrivate(); - d_ptr->q_ptr = this; - -} - -/*! - Destroys this factory, and all the widgets it has created. -*/ -QtEnumEditorFactory::~QtEnumEditorFactory() -{ - qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtEnumEditorFactory::connectPropertyManager(QtEnumPropertyManager *manager) -{ - connect(manager, SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotPropertyChanged(QtProperty *, int))); - connect(manager, SIGNAL(enumNamesChanged(QtProperty *, const QStringList &)), - this, SLOT(slotEnumNamesChanged(QtProperty *, const QStringList &))); -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -QWidget *QtEnumEditorFactory::createEditor(QtEnumPropertyManager *manager, QtProperty *property, - QWidget *parent) -{ - QComboBox *editor = d_ptr->createEditor(property, parent); - editor->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); - editor->view()->setTextElideMode(Qt::ElideRight); - QStringList enumNames = manager->enumNames(property); - editor->addItems(enumNames); - QMap enumIcons = manager->enumIcons(property); - const int enumNamesCount = enumNames.count(); - for (int i = 0; i < enumNamesCount; i++) - editor->setItemIcon(i, enumIcons.value(i)); - editor->setCurrentIndex(manager->value(property)); - - connect(editor, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSetValue(int))); - connect(editor, SIGNAL(destroyed(QObject *)), - this, SLOT(slotEditorDestroyed(QObject *))); - return editor; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtEnumEditorFactory::disconnectPropertyManager(QtEnumPropertyManager *manager) -{ - disconnect(manager, SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotPropertyChanged(QtProperty *, int))); - disconnect(manager, SIGNAL(enumNamesChanged(QtProperty *, const QStringList &)), - this, SLOT(slotEnumNamesChanged(QtProperty *, const QStringList &))); -} - -// QtCursorEditorFactory - -Q_GLOBAL_STATIC(QtCursorDatabase, cursorDatabase) - -class QtCursorEditorFactoryPrivate -{ - QtCursorEditorFactory *q_ptr; - Q_DECLARE_PUBLIC(QtCursorEditorFactory) -public: - QtCursorEditorFactoryPrivate(); - - void slotPropertyChanged(QtProperty *property, const QCursor &cursor); - void slotEnumChanged(QtProperty *property, int value); - void slotEditorDestroyed(QObject *object); - - QtEnumEditorFactory *m_enumEditorFactory; - QtEnumPropertyManager *m_enumPropertyManager; - - QMap m_propertyToEnum; - QMap m_enumToProperty; - QMap > m_enumToEditors; - QMap m_editorToEnum; - bool m_updatingEnum; -}; - -QtCursorEditorFactoryPrivate::QtCursorEditorFactoryPrivate() - : m_updatingEnum(false) -{ - -} - -void QtCursorEditorFactoryPrivate::slotPropertyChanged(QtProperty *property, const QCursor &cursor) -{ - // update enum property - QtProperty *enumProp = m_propertyToEnum.value(property); - if (!enumProp) - return; - - m_updatingEnum = true; - m_enumPropertyManager->setValue(enumProp, cursorDatabase()->cursorToValue(cursor)); - m_updatingEnum = false; -} - -void QtCursorEditorFactoryPrivate::slotEnumChanged(QtProperty *property, int value) -{ - if (m_updatingEnum) - return; - // update cursor property - QtProperty *prop = m_enumToProperty.value(property); - if (!prop) - return; - QtCursorPropertyManager *cursorManager = q_ptr->propertyManager(prop); - if (!cursorManager) - return; -#ifndef QT_NO_CURSOR - cursorManager->setValue(prop, QCursor(cursorDatabase()->valueToCursor(value))); -#endif -} - -void QtCursorEditorFactoryPrivate::slotEditorDestroyed(QObject *object) -{ - // remove from m_editorToEnum map; - // remove from m_enumToEditors map; - // if m_enumToEditors doesn't contains more editors delete enum property; - const QMap::ConstIterator ecend = m_editorToEnum.constEnd(); - for (QMap::ConstIterator itEditor = m_editorToEnum.constBegin(); itEditor != ecend; ++itEditor) - if (itEditor.key() == object) { - QWidget *editor = itEditor.key(); - QtProperty *enumProp = itEditor.value(); - m_editorToEnum.remove(editor); - m_enumToEditors[enumProp].removeAll(editor); - if (m_enumToEditors[enumProp].isEmpty()) { - m_enumToEditors.remove(enumProp); - QtProperty *property = m_enumToProperty.value(enumProp); - m_enumToProperty.remove(enumProp); - m_propertyToEnum.remove(property); - delete enumProp; - } - return; - } -} - -/*! - \class QtCursorEditorFactory - - \brief The QtCursorEditorFactory class provides QComboBox widgets for - properties created by QtCursorPropertyManager objects. - - \sa QtAbstractEditorFactory, QtCursorPropertyManager -*/ - -/*! - Creates a factory with the given \a parent. -*/ -QtCursorEditorFactory::QtCursorEditorFactory(QObject *parent) - : QtAbstractEditorFactory(parent) -{ - d_ptr = new QtCursorEditorFactoryPrivate(); - d_ptr->q_ptr = this; - - d_ptr->m_enumEditorFactory = new QtEnumEditorFactory(this); - d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this); - connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotEnumChanged(QtProperty *, int))); - d_ptr->m_enumEditorFactory->addPropertyManager(d_ptr->m_enumPropertyManager); -} - -/*! - Destroys this factory, and all the widgets it has created. -*/ -QtCursorEditorFactory::~QtCursorEditorFactory() -{ - delete d_ptr; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtCursorEditorFactory::connectPropertyManager(QtCursorPropertyManager *manager) -{ - connect(manager, SIGNAL(valueChanged(QtProperty *, const QCursor &)), - this, SLOT(slotPropertyChanged(QtProperty *, const QCursor &))); -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -QWidget *QtCursorEditorFactory::createEditor(QtCursorPropertyManager *manager, QtProperty *property, - QWidget *parent) -{ - QtProperty *enumProp = 0; - if (d_ptr->m_propertyToEnum.contains(property)) { - enumProp = d_ptr->m_propertyToEnum[property]; - } else { - enumProp = d_ptr->m_enumPropertyManager->addProperty(property->propertyName()); - d_ptr->m_enumPropertyManager->setEnumNames(enumProp, cursorDatabase()->cursorShapeNames()); - d_ptr->m_enumPropertyManager->setEnumIcons(enumProp, cursorDatabase()->cursorShapeIcons()); -#ifndef QT_NO_CURSOR - d_ptr->m_enumPropertyManager->setValue(enumProp, cursorDatabase()->cursorToValue(manager->value(property))); -#endif - d_ptr->m_propertyToEnum[property] = enumProp; - d_ptr->m_enumToProperty[enumProp] = property; - } - QtAbstractEditorFactoryBase *af = d_ptr->m_enumEditorFactory; - QWidget *editor = af->createEditor(enumProp, parent); - d_ptr->m_enumToEditors[enumProp].append(editor); - d_ptr->m_editorToEnum[editor] = enumProp; - connect(editor, SIGNAL(destroyed(QObject *)), - this, SLOT(slotEditorDestroyed(QObject *))); - return editor; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtCursorEditorFactory::disconnectPropertyManager(QtCursorPropertyManager *manager) -{ - disconnect(manager, SIGNAL(valueChanged(QtProperty *, const QCursor &)), - this, SLOT(slotPropertyChanged(QtProperty *, const QCursor &))); -} - -// QtColorEditWidget - -class QtColorEditWidget : public QWidget { - Q_OBJECT - -public: - QtColorEditWidget(QWidget *parent); - - bool eventFilter(QObject *obj, QEvent *ev); - -public Q_SLOTS: - void setValue(const QColor &value); - -private Q_SLOTS: - void buttonClicked(); - -Q_SIGNALS: - void valueChanged(const QColor &value); - -private: - QColor m_color; - QLabel *m_pixmapLabel; - QLabel *m_label; - QToolButton *m_button; -}; - -QtColorEditWidget::QtColorEditWidget(QWidget *parent) : - QWidget(parent), - m_pixmapLabel(new QLabel), - m_label(new QLabel), - m_button(new QToolButton) -{ - QHBoxLayout *lt = new QHBoxLayout(this); - setupTreeViewEditorMargin(lt); - lt->setSpacing(0); - lt->addWidget(m_pixmapLabel); - lt->addWidget(m_label); - lt->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Ignored)); - - m_button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Ignored); - m_button->setFixedWidth(20); - setFocusProxy(m_button); - setFocusPolicy(m_button->focusPolicy()); - m_button->setText(tr("...")); - m_button->installEventFilter(this); - connect(m_button, SIGNAL(clicked()), this, SLOT(buttonClicked())); - lt->addWidget(m_button); - m_pixmapLabel->setPixmap(QtPropertyBrowserUtils::brushValuePixmap(QBrush(m_color))); - m_label->setText(QtPropertyBrowserUtils::colorValueText(m_color)); -} - -void QtColorEditWidget::setValue(const QColor &c) -{ - if (m_color != c) { - m_color = c; - m_pixmapLabel->setPixmap(QtPropertyBrowserUtils::brushValuePixmap(QBrush(c))); - m_label->setText(QtPropertyBrowserUtils::colorValueText(c)); - } -} - -void QtColorEditWidget::buttonClicked() -{ - bool ok = false; - QRgb oldRgba = m_color.rgba(); - QRgb newRgba = QColorDialog::getRgba(oldRgba, &ok, this); - if (ok && newRgba != oldRgba) { - setValue(QColor::fromRgba(newRgba)); - emit valueChanged(m_color); - } -} - -bool QtColorEditWidget::eventFilter(QObject *obj, QEvent *ev) -{ - if (obj == m_button) { - switch (ev->type()) { - case QEvent::KeyPress: - case QEvent::KeyRelease: { // Prevent the QToolButton from handling Enter/Escape meant control the delegate - switch (static_cast(ev)->key()) { - case Qt::Key_Escape: - case Qt::Key_Enter: - case Qt::Key_Return: - ev->ignore(); - return true; - default: - break; - } - } - break; - default: - break; - } - } - return QWidget::eventFilter(obj, ev); -} - -// QtColorEditorFactoryPrivate - -class QtColorEditorFactoryPrivate : public EditorFactoryPrivate -{ - QtColorEditorFactory *q_ptr; - Q_DECLARE_PUBLIC(QtColorEditorFactory) -public: - - void slotPropertyChanged(QtProperty *property, const QColor &value); - void slotSetValue(const QColor &value); -}; - -void QtColorEditorFactoryPrivate::slotPropertyChanged(QtProperty *property, - const QColor &value) -{ - const PropertyToEditorListMap::iterator it = m_createdEditors.find(property); - if (it == m_createdEditors.end()) - return; - QListIterator itEditor(it.value()); - - while (itEditor.hasNext()) - itEditor.next()->setValue(value); -} - -void QtColorEditorFactoryPrivate::slotSetValue(const QColor &value) -{ - QObject *object = q_ptr->sender(); - const EditorToPropertyMap::ConstIterator ecend = m_editorToProperty.constEnd(); - for (EditorToPropertyMap::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) - if (itEditor.key() == object) { - QtProperty *property = itEditor.value(); - QtColorPropertyManager *manager = q_ptr->propertyManager(property); - if (!manager) - return; - manager->setValue(property, value); - return; - } -} - -/*! - \class QtColorEditorFactory - - \brief The QtColorEditorFactory class provides color editing for - properties created by QtColorPropertyManager objects. - - \sa QtAbstractEditorFactory, QtColorPropertyManager -*/ - -/*! - Creates a factory with the given \a parent. -*/ -QtColorEditorFactory::QtColorEditorFactory(QObject *parent) : - QtAbstractEditorFactory(parent), - d_ptr(new QtColorEditorFactoryPrivate()) -{ - d_ptr->q_ptr = this; -} - -/*! - Destroys this factory, and all the widgets it has created. -*/ -QtColorEditorFactory::~QtColorEditorFactory() -{ - qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtColorEditorFactory::connectPropertyManager(QtColorPropertyManager *manager) -{ - connect(manager, SIGNAL(valueChanged(QtProperty*,QColor)), - this, SLOT(slotPropertyChanged(QtProperty*,QColor))); -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -QWidget *QtColorEditorFactory::createEditor(QtColorPropertyManager *manager, - QtProperty *property, QWidget *parent) -{ - QtColorEditWidget *editor = d_ptr->createEditor(property, parent); - editor->setValue(manager->value(property)); - connect(editor, SIGNAL(valueChanged(QColor)), this, SLOT(slotSetValue(QColor))); - connect(editor, SIGNAL(destroyed(QObject *)), this, SLOT(slotEditorDestroyed(QObject *))); - return editor; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtColorEditorFactory::disconnectPropertyManager(QtColorPropertyManager *manager) -{ - disconnect(manager, SIGNAL(valueChanged(QtProperty*,QColor)), this, SLOT(slotPropertyChanged(QtProperty*,QColor))); -} - -// QtFontEditWidget - -class QtFontEditWidget : public QWidget { - Q_OBJECT - -public: - QtFontEditWidget(QWidget *parent); - - bool eventFilter(QObject *obj, QEvent *ev); - -public Q_SLOTS: - void setValue(const QFont &value); - -private Q_SLOTS: - void buttonClicked(); - -Q_SIGNALS: - void valueChanged(const QFont &value); - -private: - QFont m_font; - QLabel *m_pixmapLabel; - QLabel *m_label; - QToolButton *m_button; -}; - -QtFontEditWidget::QtFontEditWidget(QWidget *parent) : - QWidget(parent), - m_pixmapLabel(new QLabel), - m_label(new QLabel), - m_button(new QToolButton) -{ - QHBoxLayout *lt = new QHBoxLayout(this); - setupTreeViewEditorMargin(lt); - lt->setSpacing(0); - lt->addWidget(m_pixmapLabel); - lt->addWidget(m_label); - lt->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Ignored)); - - m_button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Ignored); - m_button->setFixedWidth(20); - setFocusProxy(m_button); - setFocusPolicy(m_button->focusPolicy()); - m_button->setText(tr("...")); - m_button->installEventFilter(this); - connect(m_button, SIGNAL(clicked()), this, SLOT(buttonClicked())); - lt->addWidget(m_button); - m_pixmapLabel->setPixmap(QtPropertyBrowserUtils::fontValuePixmap(m_font)); - m_label->setText(QtPropertyBrowserUtils::fontValueText(m_font)); -} - -void QtFontEditWidget::setValue(const QFont &f) -{ - if (m_font != f) { - m_font = f; - m_pixmapLabel->setPixmap(QtPropertyBrowserUtils::fontValuePixmap(f)); - m_label->setText(QtPropertyBrowserUtils::fontValueText(f)); - } -} - -void QtFontEditWidget::buttonClicked() -{ - bool ok = false; - QFont newFont = QFontDialog::getFont(&ok, m_font, this, tr("Select Font")); - if (ok && newFont != m_font) { - QFont f = m_font; - // prevent mask for unchanged attributes, don't change other attributes (like kerning, etc...) - if (m_font.family() != newFont.family()) - f.setFamily(newFont.family()); - if (m_font.pointSize() != newFont.pointSize()) - f.setPointSize(newFont.pointSize()); - if (m_font.bold() != newFont.bold()) - f.setBold(newFont.bold()); - if (m_font.italic() != newFont.italic()) - f.setItalic(newFont.italic()); - if (m_font.underline() != newFont.underline()) - f.setUnderline(newFont.underline()); - if (m_font.strikeOut() != newFont.strikeOut()) - f.setStrikeOut(newFont.strikeOut()); - setValue(f); - emit valueChanged(m_font); - } -} - -bool QtFontEditWidget::eventFilter(QObject *obj, QEvent *ev) -{ - if (obj == m_button) { - switch (ev->type()) { - case QEvent::KeyPress: - case QEvent::KeyRelease: { // Prevent the QToolButton from handling Enter/Escape meant control the delegate - switch (static_cast(ev)->key()) { - case Qt::Key_Escape: - case Qt::Key_Enter: - case Qt::Key_Return: - ev->ignore(); - return true; - default: - break; - } - } - break; - default: - break; - } - } - return QWidget::eventFilter(obj, ev); -} - -// QtFontEditorFactoryPrivate - -class QtFontEditorFactoryPrivate : public EditorFactoryPrivate -{ - QtFontEditorFactory *q_ptr; - Q_DECLARE_PUBLIC(QtFontEditorFactory) -public: - - void slotPropertyChanged(QtProperty *property, const QFont &value); - void slotSetValue(const QFont &value); -}; - -void QtFontEditorFactoryPrivate::slotPropertyChanged(QtProperty *property, - const QFont &value) -{ - const PropertyToEditorListMap::iterator it = m_createdEditors.find(property); - if (it == m_createdEditors.end()) - return; - QListIterator itEditor(it.value()); - - while (itEditor.hasNext()) - itEditor.next()->setValue(value); -} - -void QtFontEditorFactoryPrivate::slotSetValue(const QFont &value) -{ - QObject *object = q_ptr->sender(); - const EditorToPropertyMap::ConstIterator ecend = m_editorToProperty.constEnd(); - for (EditorToPropertyMap::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) - if (itEditor.key() == object) { - QtProperty *property = itEditor.value(); - QtFontPropertyManager *manager = q_ptr->propertyManager(property); - if (!manager) - return; - manager->setValue(property, value); - return; - } -} - -/*! - \class QtFontEditorFactory - - \brief The QtFontEditorFactory class provides font editing for - properties created by QtFontPropertyManager objects. - - \sa QtAbstractEditorFactory, QtFontPropertyManager -*/ - -/*! - Creates a factory with the given \a parent. -*/ -QtFontEditorFactory::QtFontEditorFactory(QObject *parent) : - QtAbstractEditorFactory(parent), - d_ptr(new QtFontEditorFactoryPrivate()) -{ - d_ptr->q_ptr = this; -} - -/*! - Destroys this factory, and all the widgets it has created. -*/ -QtFontEditorFactory::~QtFontEditorFactory() -{ - qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtFontEditorFactory::connectPropertyManager(QtFontPropertyManager *manager) -{ - connect(manager, SIGNAL(valueChanged(QtProperty*,QFont)), - this, SLOT(slotPropertyChanged(QtProperty*,QFont))); -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -QWidget *QtFontEditorFactory::createEditor(QtFontPropertyManager *manager, - QtProperty *property, QWidget *parent) -{ - QtFontEditWidget *editor = d_ptr->createEditor(property, parent); - editor->setValue(manager->value(property)); - connect(editor, SIGNAL(valueChanged(QFont)), this, SLOT(slotSetValue(QFont))); - connect(editor, SIGNAL(destroyed(QObject *)), this, SLOT(slotEditorDestroyed(QObject *))); - return editor; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtFontEditorFactory::disconnectPropertyManager(QtFontPropertyManager *manager) -{ - disconnect(manager, SIGNAL(valueChanged(QtProperty*,QFont)), this, SLOT(slotPropertyChanged(QtProperty*,QFont))); -} - -#if QT_VERSION >= 0x040400 -QT_END_NAMESPACE -#endif - -#include "moc_qteditorfactory.cxx" -#include "qteditorfactory.moc" diff --git a/QtPropertyBrowser/qteditorfactory.h b/QtPropertyBrowser/qteditorfactory.h deleted file mode 100644 index 07fed42abb..0000000000 --- a/QtPropertyBrowser/qteditorfactory.h +++ /dev/null @@ -1,448 +0,0 @@ -/**************************************************************************** -** -** This file is part of a Qt Solutions component. -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Solutions Commercial License Agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** Please note Third Party Software included with Qt Solutions may impose -** additional restrictions and it is the user's responsibility to ensure -** that they have met the licensing requirements of the GPL, LGPL, or Qt -** Solutions Commercial license and the relevant license of the Third -** Party Software they are using. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTEDITORFACTORY_H -#define QTEDITORFACTORY_H - -#include "qtpropertymanager.h" - -#if QT_VERSION >= 0x040400 -QT_BEGIN_NAMESPACE -#endif - -class QtSpinBoxFactoryPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtSpinBoxFactory : public QtAbstractEditorFactory -{ - Q_OBJECT -public: - QtSpinBoxFactory(QObject *parent = 0); - ~QtSpinBoxFactory(); -protected: - void connectPropertyManager(QtIntPropertyManager *manager); - QWidget *createEditor(QtIntPropertyManager *manager, QtProperty *property, - QWidget *parent); - void disconnectPropertyManager(QtIntPropertyManager *manager); -private: - QtSpinBoxFactoryPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtSpinBoxFactory) - Q_DISABLE_COPY(QtSpinBoxFactory) - Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, int)) - Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, int, int)) - Q_PRIVATE_SLOT(d_func(), void slotSingleStepChanged(QtProperty *, int)) - Q_PRIVATE_SLOT(d_func(), void slotSetValue(int)) - Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *)) -}; - -class QtSliderFactoryPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtSliderFactory : public QtAbstractEditorFactory -{ - Q_OBJECT -public: - QtSliderFactory(QObject *parent = 0); - ~QtSliderFactory(); -protected: - void connectPropertyManager(QtIntPropertyManager *manager); - QWidget *createEditor(QtIntPropertyManager *manager, QtProperty *property, - QWidget *parent); - void disconnectPropertyManager(QtIntPropertyManager *manager); -private: - QtSliderFactoryPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtSliderFactory) - Q_DISABLE_COPY(QtSliderFactory) - Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, int)) - Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, int, int)) - Q_PRIVATE_SLOT(d_func(), void slotSingleStepChanged(QtProperty *, int)) - Q_PRIVATE_SLOT(d_func(), void slotSetValue(int)) - Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *)) -}; - -class QtScrollBarFactoryPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtScrollBarFactory : public QtAbstractEditorFactory -{ - Q_OBJECT -public: - QtScrollBarFactory(QObject *parent = 0); - ~QtScrollBarFactory(); -protected: - void connectPropertyManager(QtIntPropertyManager *manager); - QWidget *createEditor(QtIntPropertyManager *manager, QtProperty *property, - QWidget *parent); - void disconnectPropertyManager(QtIntPropertyManager *manager); -private: - QtScrollBarFactoryPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtScrollBarFactory) - Q_DISABLE_COPY(QtScrollBarFactory) - Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, int)) - Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, int, int)) - Q_PRIVATE_SLOT(d_func(), void slotSingleStepChanged(QtProperty *, int)) - Q_PRIVATE_SLOT(d_func(), void slotSetValue(int)) - Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *)) -}; - -class QtCheckBoxFactoryPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtCheckBoxFactory : public QtAbstractEditorFactory -{ - Q_OBJECT -public: - QtCheckBoxFactory(QObject *parent = 0); - ~QtCheckBoxFactory(); -protected: - void connectPropertyManager(QtBoolPropertyManager *manager); - QWidget *createEditor(QtBoolPropertyManager *manager, QtProperty *property, - QWidget *parent); - void disconnectPropertyManager(QtBoolPropertyManager *manager); -private: - QtCheckBoxFactoryPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtCheckBoxFactory) - Q_DISABLE_COPY(QtCheckBoxFactory) - Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, bool)) - Q_PRIVATE_SLOT(d_func(), void slotSetValue(bool)) - Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *)) -}; - -class QtDoubleSpinBoxFactoryPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtDoubleSpinBoxFactory : public QtAbstractEditorFactory -{ - Q_OBJECT -public: - QtDoubleSpinBoxFactory(QObject *parent = 0); - ~QtDoubleSpinBoxFactory(); -protected: - void connectPropertyManager(QtDoublePropertyManager *manager); - QWidget *createEditor(QtDoublePropertyManager *manager, QtProperty *property, - QWidget *parent); - void disconnectPropertyManager(QtDoublePropertyManager *manager); -private: - QtDoubleSpinBoxFactoryPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtDoubleSpinBoxFactory) - Q_DISABLE_COPY(QtDoubleSpinBoxFactory) - Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, double)) - Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, double, double)) - Q_PRIVATE_SLOT(d_func(), void slotSingleStepChanged(QtProperty *, double)) - Q_PRIVATE_SLOT(d_func(), void slotDecimalsChanged(QtProperty *, int)) - Q_PRIVATE_SLOT(d_func(), void slotSetValue(double)) - Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *)) -}; - -class QtLineEditFactoryPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtLineEditFactory : public QtAbstractEditorFactory -{ - Q_OBJECT -public: - QtLineEditFactory(QObject *parent = 0); - ~QtLineEditFactory(); -protected: - void connectPropertyManager(QtStringPropertyManager *manager); - QWidget *createEditor(QtStringPropertyManager *manager, QtProperty *property, - QWidget *parent); - void disconnectPropertyManager(QtStringPropertyManager *manager); -private: - QtLineEditFactoryPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtLineEditFactory) - Q_DISABLE_COPY(QtLineEditFactory) - Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, const QString &)) - Q_PRIVATE_SLOT(d_func(), void slotRegExpChanged(QtProperty *, const QRegExp &)) - Q_PRIVATE_SLOT(d_func(), void slotSetValue(const QString &)) - Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *)) - Q_PRIVATE_SLOT(d_func(), void slotEditingFinished()) -}; - -class QtDateEditFactoryPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtDateEditFactory : public QtAbstractEditorFactory -{ - Q_OBJECT -public: - QtDateEditFactory(QObject *parent = 0); - ~QtDateEditFactory(); -protected: - void connectPropertyManager(QtDatePropertyManager *manager); - QWidget *createEditor(QtDatePropertyManager *manager, QtProperty *property, - QWidget *parent); - void disconnectPropertyManager(QtDatePropertyManager *manager); -private: - QtDateEditFactoryPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtDateEditFactory) - Q_DISABLE_COPY(QtDateEditFactory) - Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, const QDate &)) - Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, - const QDate &, const QDate &)) - Q_PRIVATE_SLOT(d_func(), void slotSetValue(const QDate &)) - Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *)) -}; - -class QtTimeEditFactoryPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtTimeEditFactory : public QtAbstractEditorFactory -{ - Q_OBJECT -public: - QtTimeEditFactory(QObject *parent = 0); - ~QtTimeEditFactory(); -protected: - void connectPropertyManager(QtTimePropertyManager *manager); - QWidget *createEditor(QtTimePropertyManager *manager, QtProperty *property, - QWidget *parent); - void disconnectPropertyManager(QtTimePropertyManager *manager); -private: - QtTimeEditFactoryPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtTimeEditFactory) - Q_DISABLE_COPY(QtTimeEditFactory) - Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, const QTime &)) - Q_PRIVATE_SLOT(d_func(), void slotSetValue(const QTime &)) - Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *)) -}; - -class QtDateTimeEditFactoryPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtDateTimeEditFactory : public QtAbstractEditorFactory -{ - Q_OBJECT -public: - QtDateTimeEditFactory(QObject *parent = 0); - ~QtDateTimeEditFactory(); -protected: - void connectPropertyManager(QtDateTimePropertyManager *manager); - QWidget *createEditor(QtDateTimePropertyManager *manager, QtProperty *property, - QWidget *parent); - void disconnectPropertyManager(QtDateTimePropertyManager *manager); -private: - QtDateTimeEditFactoryPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtDateTimeEditFactory) - Q_DISABLE_COPY(QtDateTimeEditFactory) - Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, const QDateTime &)) - Q_PRIVATE_SLOT(d_func(), void slotSetValue(const QDateTime &)) - Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *)) -}; - -class QtKeySequenceEditorFactoryPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtKeySequenceEditorFactory : public QtAbstractEditorFactory -{ - Q_OBJECT -public: - QtKeySequenceEditorFactory(QObject *parent = 0); - ~QtKeySequenceEditorFactory(); -protected: - void connectPropertyManager(QtKeySequencePropertyManager *manager); - QWidget *createEditor(QtKeySequencePropertyManager *manager, QtProperty *property, - QWidget *parent); - void disconnectPropertyManager(QtKeySequencePropertyManager *manager); -private: - QtKeySequenceEditorFactoryPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtKeySequenceEditorFactory) - Q_DISABLE_COPY(QtKeySequenceEditorFactory) - Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, const QKeySequence &)) - Q_PRIVATE_SLOT(d_func(), void slotSetValue(const QKeySequence &)) - Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *)) -}; - -class QtCharEditorFactoryPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtCharEditorFactory : public QtAbstractEditorFactory -{ - Q_OBJECT -public: - QtCharEditorFactory(QObject *parent = 0); - ~QtCharEditorFactory(); -protected: - void connectPropertyManager(QtCharPropertyManager *manager); - QWidget *createEditor(QtCharPropertyManager *manager, QtProperty *property, - QWidget *parent); - void disconnectPropertyManager(QtCharPropertyManager *manager); -private: - QtCharEditorFactoryPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtCharEditorFactory) - Q_DISABLE_COPY(QtCharEditorFactory) - Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, const QChar &)) - Q_PRIVATE_SLOT(d_func(), void slotSetValue(const QChar &)) - Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *)) -}; - -class QtEnumEditorFactoryPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtEnumEditorFactory : public QtAbstractEditorFactory -{ - Q_OBJECT -public: - QtEnumEditorFactory(QObject *parent = 0); - ~QtEnumEditorFactory(); -protected: - void connectPropertyManager(QtEnumPropertyManager *manager); - QWidget *createEditor(QtEnumPropertyManager *manager, QtProperty *property, - QWidget *parent); - void disconnectPropertyManager(QtEnumPropertyManager *manager); -private: - QtEnumEditorFactoryPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtEnumEditorFactory) - Q_DISABLE_COPY(QtEnumEditorFactory) - Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, int)) - Q_PRIVATE_SLOT(d_func(), void slotEnumNamesChanged(QtProperty *, - const QStringList &)) - Q_PRIVATE_SLOT(d_func(), void slotEnumIconsChanged(QtProperty *, - const QMap &)) - Q_PRIVATE_SLOT(d_func(), void slotSetValue(int)) - Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *)) -}; - -class QtCursorEditorFactoryPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtCursorEditorFactory : public QtAbstractEditorFactory -{ - Q_OBJECT -public: - QtCursorEditorFactory(QObject *parent = 0); - ~QtCursorEditorFactory(); -protected: - void connectPropertyManager(QtCursorPropertyManager *manager); - QWidget *createEditor(QtCursorPropertyManager *manager, QtProperty *property, - QWidget *parent); - void disconnectPropertyManager(QtCursorPropertyManager *manager); -private: - QtCursorEditorFactoryPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtCursorEditorFactory) - Q_DISABLE_COPY(QtCursorEditorFactory) - Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, const QCursor &)) - Q_PRIVATE_SLOT(d_func(), void slotEnumChanged(QtProperty *, int)) - Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *)) -}; - -class QtColorEditorFactoryPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtColorEditorFactory : public QtAbstractEditorFactory -{ - Q_OBJECT -public: - QtColorEditorFactory(QObject *parent = 0); - ~QtColorEditorFactory(); -protected: - void connectPropertyManager(QtColorPropertyManager *manager); - QWidget *createEditor(QtColorPropertyManager *manager, QtProperty *property, - QWidget *parent); - void disconnectPropertyManager(QtColorPropertyManager *manager); -private: - QtColorEditorFactoryPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtColorEditorFactory) - Q_DISABLE_COPY(QtColorEditorFactory) - Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, const QColor &)) - Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *)) - Q_PRIVATE_SLOT(d_func(), void slotSetValue(const QColor &)) -}; - -class QtFontEditorFactoryPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtFontEditorFactory : public QtAbstractEditorFactory -{ - Q_OBJECT -public: - QtFontEditorFactory(QObject *parent = 0); - ~QtFontEditorFactory(); -protected: - void connectPropertyManager(QtFontPropertyManager *manager); - QWidget *createEditor(QtFontPropertyManager *manager, QtProperty *property, - QWidget *parent); - void disconnectPropertyManager(QtFontPropertyManager *manager); -private: - QtFontEditorFactoryPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtFontEditorFactory) - Q_DISABLE_COPY(QtFontEditorFactory) - Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, const QFont &)) - Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *)) - Q_PRIVATE_SLOT(d_func(), void slotSetValue(const QFont &)) -}; - -#if QT_VERSION >= 0x040400 -QT_END_NAMESPACE -#endif - -#endif diff --git a/QtPropertyBrowser/qtgroupboxpropertybrowser.cpp b/QtPropertyBrowser/qtgroupboxpropertybrowser.cpp deleted file mode 100644 index d789c86956..0000000000 --- a/QtPropertyBrowser/qtgroupboxpropertybrowser.cpp +++ /dev/null @@ -1,578 +0,0 @@ -/**************************************************************************** -** -** This file is part of a Qt Solutions component. -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Solutions Commercial License Agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** Please note Third Party Software included with Qt Solutions may impose -** additional restrictions and it is the user's responsibility to ensure -** that they have met the licensing requirements of the GPL, LGPL, or Qt -** Solutions Commercial license and the relevant license of the Third -** Party Software they are using. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qtgroupboxpropertybrowser.h" -#include -#include -#include -#include -#include -#include - -#if QT_VERSION >= 0x040400 -QT_BEGIN_NAMESPACE -#endif - -class QtGroupBoxPropertyBrowserPrivate -{ - QtGroupBoxPropertyBrowser *q_ptr; - Q_DECLARE_PUBLIC(QtGroupBoxPropertyBrowser) -public: - - void init(QWidget *parent); - - void propertyInserted(QtBrowserItem *index, QtBrowserItem *afterIndex); - void propertyRemoved(QtBrowserItem *index); - void propertyChanged(QtBrowserItem *index); - QWidget *createEditor(QtProperty *property, QWidget *parent) const - { return q_ptr->createEditor(property, parent); } - - void slotEditorDestroyed(); - void slotUpdate(); - - struct WidgetItem - { - WidgetItem() : widget(0), label(0), widgetLabel(0), - groupBox(0), layout(0), line(0), parent(0) { } - QWidget *widget; // can be null - QLabel *label; - QLabel *widgetLabel; - QGroupBox *groupBox; - QGridLayout *layout; - QFrame *line; - WidgetItem *parent; - QList children; - }; -private: - void updateLater(); - void updateItem(WidgetItem *item); - void insertRow(QGridLayout *layout, int row) const; - void removeRow(QGridLayout *layout, int row) const; - - bool hasHeader(WidgetItem *item) const; - - QMap m_indexToItem; - QMap m_itemToIndex; - QMap m_widgetToItem; - QGridLayout *m_mainLayout; - QList m_children; - QList m_recreateQueue; -}; - -void QtGroupBoxPropertyBrowserPrivate::init(QWidget *parent) -{ - m_mainLayout = new QGridLayout(); - parent->setLayout(m_mainLayout); - QLayoutItem *item = new QSpacerItem(0, 0, - QSizePolicy::Fixed, QSizePolicy::Expanding); - m_mainLayout->addItem(item, 0, 0); -} - -void QtGroupBoxPropertyBrowserPrivate::slotEditorDestroyed() -{ - QWidget *editor = qobject_cast(q_ptr->sender()); - if (!editor) - return; - if (!m_widgetToItem.contains(editor)) - return; - m_widgetToItem[editor]->widget = 0; - m_widgetToItem.remove(editor); -} - -void QtGroupBoxPropertyBrowserPrivate::slotUpdate() -{ - QListIterator itItem(m_recreateQueue); - while (itItem.hasNext()) { - WidgetItem *item = itItem.next(); - - WidgetItem *par = item->parent; - QWidget *w = 0; - QGridLayout *l = 0; - int oldRow = -1; - if (!par) { - w = q_ptr; - l = m_mainLayout; - oldRow = m_children.indexOf(item); - } else { - w = par->groupBox; - l = par->layout; - oldRow = par->children.indexOf(item); - if (hasHeader(par)) - oldRow += 2; - } - - if (item->widget) { - item->widget->setParent(w); - } else if (item->widgetLabel) { - item->widgetLabel->setParent(w); - } else { - item->widgetLabel = new QLabel(w); - } - int span = 1; - if (item->widget) - l->addWidget(item->widget, oldRow, 1, 1, 1); - else if (item->widgetLabel) - l->addWidget(item->widgetLabel, oldRow, 1, 1, 1); - else - span = 2; - item->label = new QLabel(w); - item->label->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); - l->addWidget(item->label, oldRow, 0, 1, span); - - updateItem(item); - } - m_recreateQueue.clear(); -} - -void QtGroupBoxPropertyBrowserPrivate::updateLater() -{ - QTimer::singleShot(0, q_ptr, SLOT(slotUpdate())); -} - -void QtGroupBoxPropertyBrowserPrivate::propertyInserted(QtBrowserItem *index, QtBrowserItem *afterIndex) -{ - WidgetItem *afterItem = m_indexToItem.value(afterIndex); - WidgetItem *parentItem = m_indexToItem.value(index->parent()); - - WidgetItem *newItem = new WidgetItem(); - newItem->parent = parentItem; - - QGridLayout *layout = 0; - QWidget *parentWidget = 0; - int row = -1; - if (!afterItem) { - row = 0; - if (parentItem) - parentItem->children.insert(0, newItem); - else - m_children.insert(0, newItem); - } else { - if (parentItem) { - row = parentItem->children.indexOf(afterItem) + 1; - parentItem->children.insert(row, newItem); - } else { - row = m_children.indexOf(afterItem) + 1; - m_children.insert(row, newItem); - } - } - if (parentItem && hasHeader(parentItem)) - row += 2; - - if (!parentItem) { - layout = m_mainLayout; - parentWidget = q_ptr;; - } else { - if (!parentItem->groupBox) { - m_recreateQueue.removeAll(parentItem); - WidgetItem *par = parentItem->parent; - QWidget *w = 0; - QGridLayout *l = 0; - int oldRow = -1; - if (!par) { - w = q_ptr; - l = m_mainLayout; - oldRow = m_children.indexOf(parentItem); - } else { - w = par->groupBox; - l = par->layout; - oldRow = par->children.indexOf(parentItem); - if (hasHeader(par)) - oldRow += 2; - } - parentItem->groupBox = new QGroupBox(w); - parentItem->layout = new QGridLayout(); - parentItem->groupBox->setLayout(parentItem->layout); - if (parentItem->label) { - l->removeWidget(parentItem->label); - delete parentItem->label; - parentItem->label = 0; - } - if (parentItem->widget) { - l->removeWidget(parentItem->widget); - parentItem->widget->setParent(parentItem->groupBox); - parentItem->layout->addWidget(parentItem->widget, 0, 0, 1, 2); - parentItem->line = new QFrame(parentItem->groupBox); - } else if (parentItem->widgetLabel) { - l->removeWidget(parentItem->widgetLabel); - delete parentItem->widgetLabel; - parentItem->widgetLabel = 0; - } - if (parentItem->line) { - parentItem->line->setFrameShape(QFrame::HLine); - parentItem->line->setFrameShadow(QFrame::Sunken); - parentItem->layout->addWidget(parentItem->line, 1, 0, 1, 2); - } - l->addWidget(parentItem->groupBox, oldRow, 0, 1, 2); - updateItem(parentItem); - } - layout = parentItem->layout; - parentWidget = parentItem->groupBox; - } - - newItem->label = new QLabel(parentWidget); - newItem->label->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); - newItem->widget = createEditor(index->property(), parentWidget); - if (!newItem->widget) { - newItem->widgetLabel = new QLabel(parentWidget); - } else { - QObject::connect(newItem->widget, SIGNAL(destroyed()), q_ptr, SLOT(slotEditorDestroyed())); - m_widgetToItem[newItem->widget] = newItem; - } - - insertRow(layout, row); - int span = 1; - if (newItem->widget) - layout->addWidget(newItem->widget, row, 1); - else if (newItem->widgetLabel) - layout->addWidget(newItem->widgetLabel, row, 1); - else - span = 2; - layout->addWidget(newItem->label, row, 0, 1, span); - - m_itemToIndex[newItem] = index; - m_indexToItem[index] = newItem; - - updateItem(newItem); -} - -void QtGroupBoxPropertyBrowserPrivate::propertyRemoved(QtBrowserItem *index) -{ - WidgetItem *item = m_indexToItem.value(index); - - m_indexToItem.remove(index); - m_itemToIndex.remove(item); - - WidgetItem *parentItem = item->parent; - - int row = -1; - - if (parentItem) { - row = parentItem->children.indexOf(item); - parentItem->children.removeAt(row); - if (hasHeader(parentItem)) - row += 2; - } else { - row = m_children.indexOf(item); - m_children.removeAt(row); - } - - if (item->widget) - delete item->widget; - if (item->label) - delete item->label; - if (item->widgetLabel) - delete item->widgetLabel; - if (item->groupBox) - delete item->groupBox; - - if (!parentItem) { - removeRow(m_mainLayout, row); - } else if (parentItem->children.count() != 0) { - removeRow(parentItem->layout, row); - } else { - WidgetItem *par = parentItem->parent; - QWidget *w = 0; - QGridLayout *l = 0; - int oldRow = -1; - if (!par) { - w = q_ptr; - l = m_mainLayout; - oldRow = m_children.indexOf(parentItem); - } else { - w = par->groupBox; - l = par->layout; - oldRow = par->children.indexOf(parentItem); - if (hasHeader(par)) - oldRow += 2; - } - - if (parentItem->widget) { - parentItem->widget->hide(); - parentItem->widget->setParent(0); - } else if (parentItem->widgetLabel) { - parentItem->widgetLabel->hide(); - parentItem->widgetLabel->setParent(0); - } else { - //parentItem->widgetLabel = new QLabel(w); - } - l->removeWidget(parentItem->groupBox); - delete parentItem->groupBox; - parentItem->groupBox = 0; - parentItem->line = 0; - parentItem->layout = 0; - if (!m_recreateQueue.contains(parentItem)) - m_recreateQueue.append(parentItem); - updateLater(); - } - m_recreateQueue.removeAll(item); - - delete item; -} - -void QtGroupBoxPropertyBrowserPrivate::insertRow(QGridLayout *layout, int row) const -{ - QMap itemToPos; - int idx = 0; - while (idx < layout->count()) { - int r, c, rs, cs; - layout->getItemPosition(idx, &r, &c, &rs, &cs); - if (r >= row) { - itemToPos[layout->takeAt(idx)] = QRect(r + 1, c, rs, cs); - } else { - idx++; - } - } - - const QMap::ConstIterator icend = itemToPos.constEnd(); - for (QMap::ConstIterator it = itemToPos.constBegin(); it != icend; ++it) { - const QRect r = it.value(); - layout->addItem(it.key(), r.x(), r.y(), r.width(), r.height()); - } -} - -void QtGroupBoxPropertyBrowserPrivate::removeRow(QGridLayout *layout, int row) const -{ - QMap itemToPos; - int idx = 0; - while (idx < layout->count()) { - int r, c, rs, cs; - layout->getItemPosition(idx, &r, &c, &rs, &cs); - if (r > row) { - itemToPos[layout->takeAt(idx)] = QRect(r - 1, c, rs, cs); - } else { - idx++; - } - } - - const QMap::ConstIterator icend = itemToPos.constEnd(); - for (QMap::ConstIterator it = itemToPos.constBegin(); it != icend; ++it) { - const QRect r = it.value(); - layout->addItem(it.key(), r.x(), r.y(), r.width(), r.height()); - } -} - -bool QtGroupBoxPropertyBrowserPrivate::hasHeader(WidgetItem *item) const -{ - if (item->widget) - return true; - return false; -} - -void QtGroupBoxPropertyBrowserPrivate::propertyChanged(QtBrowserItem *index) -{ - WidgetItem *item = m_indexToItem.value(index); - - updateItem(item); -} - -void QtGroupBoxPropertyBrowserPrivate::updateItem(WidgetItem *item) -{ - QtProperty *property = m_itemToIndex[item]->property(); - if (item->groupBox) { - QFont font = item->groupBox->font(); - font.setUnderline(property->isModified()); - item->groupBox->setFont(font); - item->groupBox->setTitle(property->propertyName()); - item->groupBox->setToolTip(property->toolTip()); - item->groupBox->setStatusTip(property->statusTip()); - item->groupBox->setWhatsThis(property->whatsThis()); - item->groupBox->setEnabled(property->isEnabled()); - } - if (item->label) { - QFont font = item->label->font(); - font.setUnderline(property->isModified()); - item->label->setFont(font); - item->label->setText(property->propertyName()); - item->label->setToolTip(property->toolTip()); - item->label->setStatusTip(property->statusTip()); - item->label->setWhatsThis(property->whatsThis()); - item->label->setEnabled(property->isEnabled()); - } - if (item->widgetLabel) { - QFont font = item->widgetLabel->font(); - font.setUnderline(false); - item->widgetLabel->setFont(font); - item->widgetLabel->setText(property->valueText()); - item->widgetLabel->setEnabled(property->isEnabled()); - } - if (item->widget) { - QFont font = item->widget->font(); - font.setUnderline(false); - item->widget->setFont(font); - item->widget->setEnabled(property->isEnabled()); - item->widget->setToolTip(property->valueText()); - } - //item->setIcon(1, property->valueIcon()); -} - - - -/*! - \class QtGroupBoxPropertyBrowser - - \brief The QtGroupBoxPropertyBrowser class provides a QGroupBox - based property browser. - - A property browser is a widget that enables the user to edit a - given set of properties. Each property is represented by a label - specifying the property's name, and an editing widget (e.g. a line - edit or a combobox) holding its value. A property can have zero or - more subproperties. - - QtGroupBoxPropertyBrowser provides group boxes for all nested - properties, i.e. subproperties are enclosed by a group box with - the parent property's name as its title. For example: - - \image qtgroupboxpropertybrowser.png - - Use the QtAbstractPropertyBrowser API to add, insert and remove - properties from an instance of the QtGroupBoxPropertyBrowser - class. The properties themselves are created and managed by - implementations of the QtAbstractPropertyManager class. - - \sa QtTreePropertyBrowser, QtAbstractPropertyBrowser -*/ - -/*! - Creates a property browser with the given \a parent. -*/ -QtGroupBoxPropertyBrowser::QtGroupBoxPropertyBrowser(QWidget *parent) - : QtAbstractPropertyBrowser(parent) -{ - d_ptr = new QtGroupBoxPropertyBrowserPrivate; - d_ptr->q_ptr = this; - - d_ptr->init(this); -} - -/*! - Destroys this property browser. - - Note that the properties that were inserted into this browser are - \e not destroyed since they may still be used in other - browsers. The properties are owned by the manager that created - them. - - \sa QtProperty, QtAbstractPropertyManager -*/ -QtGroupBoxPropertyBrowser::~QtGroupBoxPropertyBrowser() -{ - const QMap::ConstIterator icend = d_ptr->m_itemToIndex.constEnd(); - for (QMap::ConstIterator it = d_ptr->m_itemToIndex.constBegin(); it != icend; ++it) - delete it.key(); - delete d_ptr; -} - -/*! - \reimp -*/ -void QtGroupBoxPropertyBrowser::itemInserted(QtBrowserItem *item, QtBrowserItem *afterItem) -{ - d_ptr->propertyInserted(item, afterItem); -} - -/*! - \reimp -*/ -void QtGroupBoxPropertyBrowser::itemRemoved(QtBrowserItem *item) -{ - d_ptr->propertyRemoved(item); -} - -/*! - \reimp -*/ -void QtGroupBoxPropertyBrowser::itemChanged(QtBrowserItem *item) -{ - d_ptr->propertyChanged(item); -} - -#if QT_VERSION >= 0x040400 -QT_END_NAMESPACE -#endif - -#include "moc_qtgroupboxpropertybrowser.cxx" diff --git a/QtPropertyBrowser/qtgroupboxpropertybrowser.h b/QtPropertyBrowser/qtgroupboxpropertybrowser.h deleted file mode 100644 index 075f3286e7..0000000000 --- a/QtPropertyBrowser/qtgroupboxpropertybrowser.h +++ /dev/null @@ -1,126 +0,0 @@ -/**************************************************************************** -** -** This file is part of a Qt Solutions component. -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Solutions Commercial License Agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** Please note Third Party Software included with Qt Solutions may impose -** additional restrictions and it is the user's responsibility to ensure -** that they have met the licensing requirements of the GPL, LGPL, or Qt -** Solutions Commercial license and the relevant license of the Third -** Party Software they are using. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTGROUPBOXPROPERTYBROWSER_H -#define QTGROUPBOXPROPERTYBROWSER_H - -#include "qtpropertybrowser.h" - -#if QT_VERSION >= 0x040400 -QT_BEGIN_NAMESPACE -#endif - -class QtGroupBoxPropertyBrowserPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtGroupBoxPropertyBrowser : public QtAbstractPropertyBrowser -{ - Q_OBJECT -public: - - QtGroupBoxPropertyBrowser(QWidget *parent = 0); - ~QtGroupBoxPropertyBrowser(); - -protected: - virtual void itemInserted(QtBrowserItem *item, QtBrowserItem *afterItem); - virtual void itemRemoved(QtBrowserItem *item); - virtual void itemChanged(QtBrowserItem *item); - -private: - - QtGroupBoxPropertyBrowserPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtGroupBoxPropertyBrowser) - Q_DISABLE_COPY(QtGroupBoxPropertyBrowser) - Q_PRIVATE_SLOT(d_func(), void slotUpdate()) - Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed()) - -}; - -#if QT_VERSION >= 0x040400 -QT_END_NAMESPACE -#endif - -#endif diff --git a/QtPropertyBrowser/qtpropertybrowser.cpp b/QtPropertyBrowser/qtpropertybrowser.cpp deleted file mode 100644 index 038802a922..0000000000 --- a/QtPropertyBrowser/qtpropertybrowser.cpp +++ /dev/null @@ -1,2028 +0,0 @@ -/**************************************************************************** -** -** This file is part of a Qt Solutions component. -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Solutions Commercial License Agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** Please note Third Party Software included with Qt Solutions may impose -** additional restrictions and it is the user's responsibility to ensure -** that they have met the licensing requirements of the GPL, LGPL, or Qt -** Solutions Commercial license and the relevant license of the Third -** Party Software they are using. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qtpropertybrowser.h" -#include -#include -#include - -#if defined(Q_CC_MSVC) -# pragma warning(disable: 4786) /* MS VS 6: truncating debug info after 255 characters */ -#endif - -#if QT_VERSION >= 0x040400 -QT_BEGIN_NAMESPACE -#endif - -class QtPropertyPrivate -{ -public: - QtPropertyPrivate(QtAbstractPropertyManager *manager) : m_enabled(true), m_modified(false), m_manager(manager) {} - QtProperty *q_ptr; - - QSet m_parentItems; - QList m_subItems; - - QString m_toolTip; - QString m_statusTip; - QString m_whatsThis; - QString m_name; - bool m_enabled; - bool m_modified; - - QtAbstractPropertyManager * const m_manager; -}; - -class QtAbstractPropertyManagerPrivate -{ - QtAbstractPropertyManager *q_ptr; - Q_DECLARE_PUBLIC(QtAbstractPropertyManager) -public: - void propertyDestroyed(QtProperty *property); - void propertyChanged(QtProperty *property) const; - void propertyRemoved(QtProperty *property, - QtProperty *parentProperty) const; - void propertyInserted(QtProperty *property, QtProperty *parentProperty, - QtProperty *afterProperty) const; - - QSet m_properties; -}; - -/*! - \class QtProperty - - \brief The QtProperty class encapsulates an instance of a property. - - Properties are created by objects of QtAbstractPropertyManager - subclasses; a manager can create properties of a given type, and - is used in conjunction with the QtAbstractPropertyBrowser class. A - property is always owned by the manager that created it, which can - be retrieved using the propertyManager() function. - - QtProperty contains the most common property attributes, and - provides functions for retrieving as well as setting their values: - - \table - \header \o Getter \o Setter - \row - \o propertyName() \o setPropertyName() - \row - \o statusTip() \o setStatusTip() - \row - \o toolTip() \o setToolTip() - \row - \o whatsThis() \o setWhatsThis() - \row - \o isEnabled() \o setEnabled() - \row - \o isModified() \o setModified() - \row - \o valueText() \o Nop - \row - \o valueIcon() \o Nop - \endtable - - It is also possible to nest properties: QtProperty provides the - addSubProperty(), insertSubProperty() and removeSubProperty() functions to - manipulate the set of subproperties. Use the subProperties() - function to retrieve a property's current set of subproperties. - Note that nested properties are not owned by the parent property, - i.e. each subproperty is owned by the manager that created it. - - \sa QtAbstractPropertyManager, QtBrowserItem -*/ - -/*! - Creates a property with the given \a manager. - - This constructor is only useful when creating a custom QtProperty - subclass (e.g. QtVariantProperty). To create a regular QtProperty - object, use the QtAbstractPropertyManager::addProperty() - function instead. - - \sa QtAbstractPropertyManager::addProperty() -*/ -QtProperty::QtProperty(QtAbstractPropertyManager *manager) -{ - d_ptr = new QtPropertyPrivate(manager); - d_ptr->q_ptr = this; -} - -/*! - Destroys this property. - - Note that subproperties are detached but not destroyed, i.e. they - can still be used in another context. - - \sa QtAbstractPropertyManager::clear() - -*/ -QtProperty::~QtProperty() -{ - QSetIterator itParent(d_ptr->m_parentItems); - while (itParent.hasNext()) { - QtProperty *property = itParent.next(); - property->d_ptr->m_manager->d_ptr->propertyRemoved(this, property); - } - - d_ptr->m_manager->d_ptr->propertyDestroyed(this); - - QListIterator itChild(d_ptr->m_subItems); - while (itChild.hasNext()) { - QtProperty *property = itChild.next(); - property->d_ptr->m_parentItems.remove(this); - } - - itParent.toFront(); - while (itParent.hasNext()) { - QtProperty *property = itParent.next(); - property->d_ptr->m_subItems.removeAll(this); - } - delete d_ptr; -} - -/*! - Returns the set of subproperties. - - Note that subproperties are not owned by \e this property, but by - the manager that created them. - - \sa insertSubProperty(), removeSubProperty() -*/ -QList QtProperty::subProperties() const -{ - return d_ptr->m_subItems; -} - -/*! - Returns a pointer to the manager that owns this property. -*/ -QtAbstractPropertyManager *QtProperty::propertyManager() const -{ - return d_ptr->m_manager; -} - -/*! - Returns the property's tool tip. - - \sa setToolTip() -*/ -QString QtProperty::toolTip() const -{ - return d_ptr->m_toolTip; -} - -/*! - Returns the property's status tip. - - \sa setStatusTip() -*/ -QString QtProperty::statusTip() const -{ - return d_ptr->m_statusTip; -} - -/*! - Returns the property's "What's This" help text. - - \sa setWhatsThis() -*/ -QString QtProperty::whatsThis() const -{ - return d_ptr->m_whatsThis; -} - -/*! - Returns the property's name. - - \sa setPropertyName() -*/ -QString QtProperty::propertyName() const -{ - return d_ptr->m_name; -} - -/*! - Returns whether the property is enabled. - - \sa setEnabled() -*/ -bool QtProperty::isEnabled() const -{ - return d_ptr->m_enabled; -} - -/*! - Returns whether the property is modified. - - \sa setModified() -*/ -bool QtProperty::isModified() const -{ - return d_ptr->m_modified; -} - -/*! - Returns whether the property has a value. - - \sa QtAbstractPropertyManager::hasValue() -*/ -bool QtProperty::hasValue() const -{ - return d_ptr->m_manager->hasValue(this); -} - -/*! - Returns an icon representing the current state of this property. - - If the given property type can not generate such an icon, this - function returns an invalid icon. - - \sa QtAbstractPropertyManager::valueIcon() -*/ -QIcon QtProperty::valueIcon() const -{ - return d_ptr->m_manager->valueIcon(this); -} - -/*! - Returns a string representing the current state of this property. - - If the given property type can not generate such a string, this - function returns an empty string. - - \sa QtAbstractPropertyManager::valueText() -*/ -QString QtProperty::valueText() const -{ - return d_ptr->m_manager->valueText(this); -} - -/*! - Sets the property's tool tip to the given \a text. - - \sa toolTip() -*/ -void QtProperty::setToolTip(const QString &text) -{ - if (d_ptr->m_toolTip == text) - return; - - d_ptr->m_toolTip = text; - propertyChanged(); -} - -/*! - Sets the property's status tip to the given \a text. - - \sa statusTip() -*/ -void QtProperty::setStatusTip(const QString &text) -{ - if (d_ptr->m_statusTip == text) - return; - - d_ptr->m_statusTip = text; - propertyChanged(); -} - -/*! - Sets the property's "What's This" help text to the given \a text. - - \sa whatsThis() -*/ -void QtProperty::setWhatsThis(const QString &text) -{ - if (d_ptr->m_whatsThis == text) - return; - - d_ptr->m_whatsThis = text; - propertyChanged(); -} - -/*! - \fn void QtProperty::setPropertyName(const QString &name) - - Sets the property's name to the given \a name. - - \sa propertyName() -*/ -void QtProperty::setPropertyName(const QString &text) -{ - if (d_ptr->m_name == text) - return; - - d_ptr->m_name = text; - propertyChanged(); -} - -/*! - Enables or disables the property according to the passed \a enable value. - - \sa isEnabled() -*/ -void QtProperty::setEnabled(bool enable) -{ - if (d_ptr->m_enabled == enable) - return; - - d_ptr->m_enabled = enable; - propertyChanged(); -} - -/*! - Sets the property's modified state according to the passed \a modified value. - - \sa isModified() -*/ -void QtProperty::setModified(bool modified) -{ - if (d_ptr->m_modified == modified) - return; - - d_ptr->m_modified = modified; - propertyChanged(); -} - -/*! - Appends the given \a property to this property's subproperties. - - If the given \a property already is added, this function does - nothing. - - \sa insertSubProperty(), removeSubProperty() -*/ -void QtProperty::addSubProperty(QtProperty *property) -{ - QtProperty *after = 0; - if (d_ptr->m_subItems.count() > 0) - after = d_ptr->m_subItems.last(); - insertSubProperty(property, after); -} - -/*! - \fn void QtProperty::insertSubProperty(QtProperty *property, QtProperty *precedingProperty) - - Inserts the given \a property after the specified \a - precedingProperty into this property's list of subproperties. If - \a precedingProperty is 0, the specified \a property is inserted - at the beginning of the list. - - If the given \a property already is inserted, this function does - nothing. - - \sa addSubProperty(), removeSubProperty() -*/ -void QtProperty::insertSubProperty(QtProperty *property, - QtProperty *afterProperty) -{ - if (!property) - return; - - if (property == this) - return; - - // traverse all children of item. if this item is a child of item then cannot add. - QList pendingList = property->subProperties(); - QMap visited; - while (!pendingList.isEmpty()) { - QtProperty *i = pendingList.first(); - if (i == this) - return; - pendingList.removeFirst(); - if (visited.contains(i)) - continue; - visited[i] = true; - pendingList += i->subProperties(); - } - - pendingList = subProperties(); - int pos = 0; - int newPos = 0; - QtProperty *properAfterProperty = 0; - while (pos < pendingList.count()) { - QtProperty *i = pendingList.at(pos); - if (i == property) - return; // if item is already inserted in this item then cannot add. - if (i == afterProperty) { - newPos = pos + 1; - properAfterProperty = afterProperty; - } - pos++; - } - - d_ptr->m_subItems.insert(newPos, property); - property->d_ptr->m_parentItems.insert(this); - - d_ptr->m_manager->d_ptr->propertyInserted(property, this, properAfterProperty); -} - -/*! - Removes the given \a property from the list of subproperties - without deleting it. - - \sa addSubProperty(), insertSubProperty() -*/ -void QtProperty::removeSubProperty(QtProperty *property) -{ - if (!property) - return; - - d_ptr->m_manager->d_ptr->propertyRemoved(property, this); - - QList pendingList = subProperties(); - int pos = 0; - while (pos < pendingList.count()) { - if (pendingList.at(pos) == property) { - d_ptr->m_subItems.removeAt(pos); - property->d_ptr->m_parentItems.remove(this); - - return; - } - pos++; - } -} - -/*! - \internal -*/ -void QtProperty::propertyChanged() -{ - d_ptr->m_manager->d_ptr->propertyChanged(this); -} - -//////////////////////////////// - -void QtAbstractPropertyManagerPrivate::propertyDestroyed(QtProperty *property) -{ - if (m_properties.contains(property)) { - emit q_ptr->propertyDestroyed(property); - q_ptr->uninitializeProperty(property); - m_properties.remove(property); - } -} - -void QtAbstractPropertyManagerPrivate::propertyChanged(QtProperty *property) const -{ - emit q_ptr->propertyChanged(property); -} - -void QtAbstractPropertyManagerPrivate::propertyRemoved(QtProperty *property, - QtProperty *parentProperty) const -{ - emit q_ptr->propertyRemoved(property, parentProperty); -} - -void QtAbstractPropertyManagerPrivate::propertyInserted(QtProperty *property, - QtProperty *parentProperty, QtProperty *afterProperty) const -{ - emit q_ptr->propertyInserted(property, parentProperty, afterProperty); -} - -/*! - \class QtAbstractPropertyManager - - \brief The QtAbstractPropertyManager provides an interface for - property managers. - - A manager can create and manage properties of a given type, and is - used in conjunction with the QtAbstractPropertyBrowser class. - - When using a property browser widget, the properties are created - and managed by implementations of the QtAbstractPropertyManager - class. To ensure that the properties' values will be displayed - using suitable editing widgets, the managers are associated with - objects of QtAbstractEditorFactory subclasses. The property browser - will use these associations to determine which factories it should - use to create the preferred editing widgets. - - The QtAbstractPropertyManager class provides common functionality - like creating a property using the addProperty() function, and - retrieving the properties created by the manager using the - properties() function. The class also provides signals that are - emitted when the manager's properties change: propertyInserted(), - propertyRemoved(), propertyChanged() and propertyDestroyed(). - - QtAbstractPropertyManager subclasses are supposed to provide their - own type specific API. Note that several ready-made - implementations are available: - - \list - \o QtBoolPropertyManager - \o QtColorPropertyManager - \o QtDatePropertyManager - \o QtDateTimePropertyManager - \o QtDoublePropertyManager - \o QtEnumPropertyManager - \o QtFlagPropertyManager - \o QtFontPropertyManager - \o QtGroupPropertyManager - \o QtIntPropertyManager - \o QtPointPropertyManager - \o QtRectPropertyManager - \o QtSizePropertyManager - \o QtSizePolicyPropertyManager - \o QtStringPropertyManager - \o QtTimePropertyManager - \o QtVariantPropertyManager - \endlist - - \sa QtAbstractEditorFactoryBase, QtAbstractPropertyBrowser, QtProperty -*/ - -/*! - \fn void QtAbstractPropertyManager::propertyInserted(QtProperty *newProperty, - QtProperty *parentProperty, QtProperty *precedingProperty) - - This signal is emitted when a new subproperty is inserted into an - existing property, passing pointers to the \a newProperty, \a - parentProperty and \a precedingProperty as parameters. - - If \a precedingProperty is 0, the \a newProperty was inserted at - the beginning of the \a parentProperty's subproperties list. - - Note that signal is emitted only if the \a parentProperty is created - by this manager. - - \sa QtAbstractPropertyBrowser::itemInserted() -*/ - -/*! - \fn void QtAbstractPropertyManager::propertyChanged(QtProperty *property) - - This signal is emitted whenever a property's data changes, passing - a pointer to the \a property as parameter. - - Note that signal is only emitted for properties that are created by - this manager. - - \sa QtAbstractPropertyBrowser::itemChanged() -*/ - -/*! - \fn void QtAbstractPropertyManager::propertyRemoved(QtProperty *property, QtProperty *parent) - - This signal is emitted when a subproperty is removed, passing - pointers to the removed \a property and the \a parent property as - parameters. - - Note that signal is emitted only when the \a parent property is - created by this manager. - - \sa QtAbstractPropertyBrowser::itemRemoved() -*/ - -/*! - \fn void QtAbstractPropertyManager::propertyDestroyed(QtProperty *property) - - This signal is emitted when the specified \a property is about to - be destroyed. - - Note that signal is only emitted for properties that are created - by this manager. - - \sa clear(), uninitializeProperty() -*/ - -/*! - \fn void QtAbstractPropertyBrowser::currentItemChanged(QtBrowserItem *current) - - This signal is emitted when the current item changes. The current item is specified by \a current. - - \sa QtAbstractPropertyBrowser::setCurrentItem() -*/ - -/*! - Creates an abstract property manager with the given \a parent. -*/ -QtAbstractPropertyManager::QtAbstractPropertyManager(QObject *parent) - : QObject(parent) -{ - d_ptr = new QtAbstractPropertyManagerPrivate; - d_ptr->q_ptr = this; - -} - -/*! - Destroys the manager. All properties created by the manager are - destroyed. -*/ -QtAbstractPropertyManager::~QtAbstractPropertyManager() -{ - clear(); - delete d_ptr; -} - -/*! - Destroys all the properties that this manager has created. - - \sa propertyDestroyed(), uninitializeProperty() -*/ -void QtAbstractPropertyManager::clear() const -{ - while (!properties().isEmpty()) { - QSetIterator itProperty(properties()); - QtProperty *prop = itProperty.next(); - delete prop; - } -} - -/*! - Returns the set of properties created by this manager. - - \sa addProperty() -*/ -QSet QtAbstractPropertyManager::properties() const -{ - return d_ptr->m_properties; -} - -/*! - Returns whether the given \a property has a value. - - The default implementation of this function returns true. - - \sa QtProperty::hasValue() -*/ -bool QtAbstractPropertyManager::hasValue(const QtProperty *property) const -{ - Q_UNUSED(property) - return true; -} - -/*! - Returns an icon representing the current state of the given \a - property. - - The default implementation of this function returns an invalid - icon. - - \sa QtProperty::valueIcon() -*/ -QIcon QtAbstractPropertyManager::valueIcon(const QtProperty *property) const -{ - Q_UNUSED(property) - return QIcon(); -} - -/*! - Returns a string representing the current state of the given \a - property. - - The default implementation of this function returns an empty - string. - - \sa QtProperty::valueText() -*/ -QString QtAbstractPropertyManager::valueText(const QtProperty *property) const -{ - Q_UNUSED(property) - return QString(); -} - -/*! - Creates a property with the given \a name which then is owned by this manager. - - Internally, this function calls the createProperty() and - initializeProperty() functions. - - \sa initializeProperty(), properties() -*/ -QtProperty *QtAbstractPropertyManager::addProperty(const QString &name) -{ - QtProperty *property = createProperty(); - if (property) { - property->setPropertyName(name); - d_ptr->m_properties.insert(property); - initializeProperty(property); - } - return property; -} - -/*! - Creates a property. - - The base implementation produce QtProperty instances; Reimplement - this function to make this manager produce objects of a QtProperty - subclass. - - \sa addProperty(), initializeProperty() -*/ -QtProperty *QtAbstractPropertyManager::createProperty() -{ - return new QtProperty(this); -} - -/*! - \fn void QtAbstractPropertyManager::initializeProperty(QtProperty *property) = 0 - - This function is called whenever a new valid property pointer has - been created, passing the pointer as parameter. - - The purpose is to let the manager know that the \a property has - been created so that it can provide additional attributes for the - new property, e.g. QtIntPropertyManager adds \l - {QtIntPropertyManager::value()}{value}, \l - {QtIntPropertyManager::minimum()}{minimum} and \l - {QtIntPropertyManager::maximum()}{maximum} attributes. Since each manager - subclass adds type specific attributes, this function is pure - virtual and must be reimplemented when deriving from the - QtAbstractPropertyManager class. - - \sa addProperty(), createProperty() -*/ - -/*! - This function is called just before the specified \a property is destroyed. - - The purpose is to let the property manager know that the \a - property is being destroyed so that it can remove the property's - additional attributes. - - \sa clear(), propertyDestroyed() -*/ -void QtAbstractPropertyManager::uninitializeProperty(QtProperty *property) -{ - Q_UNUSED(property) -} - -//////////////////////////////////// - -/*! - \class QtAbstractEditorFactoryBase - - \brief The QtAbstractEditorFactoryBase provides an interface for - editor factories. - - An editor factory is a class that is able to create an editing - widget of a specified type (e.g. line edits or comboboxes) for a - given QtProperty object, and it is used in conjunction with the - QtAbstractPropertyManager and QtAbstractPropertyBrowser classes. - - When using a property browser widget, the properties are created - and managed by implementations of the QtAbstractPropertyManager - class. To ensure that the properties' values will be displayed - using suitable editing widgets, the managers are associated with - objects of QtAbstractEditorFactory subclasses. The property browser - will use these associations to determine which factories it should - use to create the preferred editing widgets. - - Typically, an editor factory is created by subclassing the - QtAbstractEditorFactory template class which inherits - QtAbstractEditorFactoryBase. But note that several ready-made - implementations are available: - - \list - \o QtCheckBoxFactory - \o QtDateEditFactory - \o QtDateTimeEditFactory - \o QtDoubleSpinBoxFactory - \o QtEnumEditorFactory - \o QtLineEditFactory - \o QtScrollBarFactory - \o QtSliderFactory - \o QtSpinBoxFactory - \o QtTimeEditFactory - \o QtVariantEditorFactory - \endlist - - \sa QtAbstractPropertyManager, QtAbstractPropertyBrowser -*/ - -/*! - \fn virtual QWidget *QtAbstractEditorFactoryBase::createEditor(QtProperty *property, - QWidget *parent) = 0 - - Creates an editing widget (with the given \a parent) for the given - \a property. - - This function is reimplemented in QtAbstractEditorFactory template class - which also provides a pure virtual convenience overload of this - function enabling access to the property's manager. - - \sa QtAbstractEditorFactory::createEditor() -*/ - -/*! - \fn QtAbstractEditorFactoryBase::QtAbstractEditorFactoryBase(QObject *parent = 0) - - Creates an abstract editor factory with the given \a parent. -*/ - -/*! - \fn virtual void QtAbstractEditorFactoryBase::breakConnection(QtAbstractPropertyManager *manager) = 0 - - \internal - - Detaches property manager from factory. - This method is reimplemented in QtAbstractEditorFactory template subclass. - You don't need to reimplement it in your subclasses. Instead implement more convenient - QtAbstractEditorFactory::disconnectPropertyManager() which gives you access to particular manager subclass. -*/ - -/*! - \fn virtual void QtAbstractEditorFactoryBase::managerDestroyed(QObject *manager) = 0 - - \internal - - This method is called when property manager is being destroyed. - Basically it notifies factory not to produce editors for properties owned by \a manager. - You don't need to reimplement it in your subclass. This method is implemented in - QtAbstractEditorFactory template subclass. -*/ - -/*! - \class QtAbstractEditorFactory - - \brief The QtAbstractEditorFactory is the base template class for editor - factories. - - An editor factory is a class that is able to create an editing - widget of a specified type (e.g. line edits or comboboxes) for a - given QtProperty object, and it is used in conjunction with the - QtAbstractPropertyManager and QtAbstractPropertyBrowser classes. - - Note that the QtAbstractEditorFactory functions are using the - PropertyManager template argument class which can be any - QtAbstractPropertyManager subclass. For example: - - \code - QtSpinBoxFactory *factory; - QSet managers = factory->propertyManagers(); - \endcode - - Note that QtSpinBoxFactory by definition creates editing widgets - \e only for properties created by QtIntPropertyManager. - - When using a property browser widget, the properties are created - and managed by implementations of the QtAbstractPropertyManager - class. To ensure that the properties' values will be displayed - using suitable editing widgets, the managers are associated with - objects of QtAbstractEditorFactory subclasses. The property browser will - use these associations to determine which factories it should use - to create the preferred editing widgets. - - A QtAbstractEditorFactory object is capable of producing editors for - several property managers at the same time. To create an - association between this factory and a given manager, use the - addPropertyManager() function. Use the removePropertyManager() function to make - this factory stop producing editors for a given property - manager. Use the propertyManagers() function to retrieve the set of - managers currently associated with this factory. - - Several ready-made implementations of the QtAbstractEditorFactory class - are available: - - \list - \o QtCheckBoxFactory - \o QtDateEditFactory - \o QtDateTimeEditFactory - \o QtDoubleSpinBoxFactory - \o QtEnumEditorFactory - \o QtLineEditFactory - \o QtScrollBarFactory - \o QtSliderFactory - \o QtSpinBoxFactory - \o QtTimeEditFactory - \o QtVariantEditorFactory - \endlist - - When deriving from the QtAbstractEditorFactory class, several pure virtual - functions must be implemented: the connectPropertyManager() function is - used by the factory to connect to the given manager's signals, the - createEditor() function is supposed to create an editor for the - given property controlled by the given manager, and finally the - disconnectPropertyManager() function is used by the factory to disconnect - from the specified manager's signals. - - \sa QtAbstractEditorFactoryBase, QtAbstractPropertyManager -*/ - -/*! - \fn QtAbstractEditorFactory::QtAbstractEditorFactory(QObject *parent = 0) - - Creates an editor factory with the given \a parent. - - \sa addPropertyManager() -*/ - -/*! - \fn QWidget *QtAbstractEditorFactory::createEditor(QtProperty *property, QWidget *parent) - - Creates an editing widget (with the given \a parent) for the given - \a property. -*/ - -/*! - \fn void QtAbstractEditorFactory::addPropertyManager(PropertyManager *manager) - - Adds the given \a manager to this factory's set of managers, - making this factory produce editing widgets for properties created - by the given manager. - - The PropertyManager type is a template argument class, and represents the chosen - QtAbstractPropertyManager subclass. - - \sa propertyManagers(), removePropertyManager() -*/ - -/*! - \fn void QtAbstractEditorFactory::removePropertyManager(PropertyManager *manager) - - Removes the given \a manager from this factory's set of - managers. The PropertyManager type is a template argument class, and may be - any QtAbstractPropertyManager subclass. - - \sa propertyManagers(), addPropertyManager() -*/ - -/*! - \fn virtual void QtAbstractEditorFactory::connectPropertyManager(PropertyManager *manager) = 0 - - Connects this factory to the given \a manager's signals. The - PropertyManager type is a template argument class, and represents - the chosen QtAbstractPropertyManager subclass. - - This function is used internally by the addPropertyManager() function, and - makes it possible to update an editing widget when the associated - property's data changes. This is typically done in custom slots - responding to the signals emitted by the property's manager, - e.g. QtIntPropertyManager::valueChanged() and - QtIntPropertyManager::rangeChanged(). - - \sa propertyManagers(), disconnectPropertyManager() -*/ - -/*! - \fn virtual QWidget *QtAbstractEditorFactory::createEditor(PropertyManager *manager, QtProperty *property, - QWidget *parent) = 0 - - Creates an editing widget with the given \a parent for the - specified \a property created by the given \a manager. The - PropertyManager type is a template argument class, and represents - the chosen QtAbstractPropertyManager subclass. - - This function must be implemented in derived classes: It is - recommended to store a pointer to the widget and map it to the - given \a property, since the widget must be updated whenever the - associated property's data changes. This is typically done in - custom slots responding to the signals emitted by the property's - manager, e.g. QtIntPropertyManager::valueChanged() and - QtIntPropertyManager::rangeChanged(). - - \sa connectPropertyManager() -*/ - -/*! - \fn virtual void QtAbstractEditorFactory::disconnectPropertyManager(PropertyManager *manager) = 0 - - Disconnects this factory from the given \a manager's signals. The - PropertyManager type is a template argument class, and represents - the chosen QtAbstractPropertyManager subclass. - - This function is used internally by the removePropertyManager() function. - - \sa propertyManagers(), connectPropertyManager() -*/ - -/*! - \fn QSet QtAbstractEditorFactory::propertyManagers() const - - Returns the factory's set of associated managers. The - PropertyManager type is a template argument class, and represents - the chosen QtAbstractPropertyManager subclass. - - \sa addPropertyManager(), removePropertyManager() -*/ - -/*! - \fn PropertyManager *QtAbstractEditorFactory::propertyManager(QtProperty *property) const - - Returns the property manager for the given \a property, or 0 if - the given \a property doesn't belong to any of this factory's - registered managers. - - The PropertyManager type is a template argument class, and represents the chosen - QtAbstractPropertyManager subclass. - - \sa propertyManagers() -*/ - -/*! - \fn virtual void QtAbstractEditorFactory::managerDestroyed(QObject *manager) - - \internal - \reimp -*/ - -//////////////////////////////////// -class QtBrowserItemPrivate -{ -public: - QtBrowserItemPrivate(QtAbstractPropertyBrowser *browser, QtProperty *property, QtBrowserItem *parent) - : m_browser(browser), m_property(property), m_parent(parent), q_ptr(0) {} - - void addChild(QtBrowserItem *index, QtBrowserItem *after); - void removeChild(QtBrowserItem *index); - - QtAbstractPropertyBrowser * const m_browser; - QtProperty *m_property; - QtBrowserItem *m_parent; - - QtBrowserItem *q_ptr; - - QList m_children; - -}; - -void QtBrowserItemPrivate::addChild(QtBrowserItem *index, QtBrowserItem *after) -{ - if (m_children.contains(index)) - return; - int idx = m_children.indexOf(after) + 1; // we insert after returned idx, if it was -1 then we set idx to 0; - m_children.insert(idx, index); -} - -void QtBrowserItemPrivate::removeChild(QtBrowserItem *index) -{ - m_children.removeAll(index); -} - - -/*! - \class QtBrowserItem - - \brief The QtBrowserItem class represents a property in - a property browser instance. - - Browser items are created whenever a QtProperty is inserted to the - property browser. A QtBrowserItem uniquely identifies a - browser's item. Thus, if the same QtProperty is inserted multiple - times, each occurrence gets its own unique QtBrowserItem. The - items are owned by QtAbstractPropertyBrowser and automatically - deleted when they are removed from the browser. - - You can traverse a browser's properties by calling parent() and - children(). The property and the browser associated with an item - are available as property() and browser(). - - \sa QtAbstractPropertyBrowser, QtProperty -*/ - -/*! - Returns the property which is accosiated with this item. Note that - several items can be associated with the same property instance in - the same property browser. - - \sa QtAbstractPropertyBrowser::items() -*/ - -QtProperty *QtBrowserItem::property() const -{ - return d_ptr->m_property; -} - -/*! - Returns the parent item of \e this item. Returns 0 if \e this item - is associated with top-level property in item's property browser. - - \sa children() -*/ - -QtBrowserItem *QtBrowserItem::parent() const -{ - return d_ptr->m_parent; -} - -/*! - Returns the children items of \e this item. The properties - reproduced from children items are always the same as - reproduced from associated property' children, for example: - - \code - QtBrowserItem *item; - QList childrenItems = item->children(); - - QList childrenProperties = item->property()->subProperties(); - \endcode - - The \e childrenItems list represents the same list as \e childrenProperties. -*/ - -QList QtBrowserItem::children() const -{ - return d_ptr->m_children; -} - -/*! - Returns the property browser which owns \e this item. -*/ - -QtAbstractPropertyBrowser *QtBrowserItem::browser() const -{ - return d_ptr->m_browser; -} - -QtBrowserItem::QtBrowserItem(QtAbstractPropertyBrowser *browser, QtProperty *property, QtBrowserItem *parent) -{ - d_ptr = new QtBrowserItemPrivate(browser, property, parent); - d_ptr->q_ptr = this; -} - -QtBrowserItem::~QtBrowserItem() -{ - delete d_ptr; -} - - -//////////////////////////////////// - -typedef QMap > Map1; -typedef QMap > > Map2; -Q_GLOBAL_STATIC(Map1, m_viewToManagerToFactory) -Q_GLOBAL_STATIC(Map2, m_managerToFactoryToViews) - -class QtAbstractPropertyBrowserPrivate -{ - QtAbstractPropertyBrowser *q_ptr; - Q_DECLARE_PUBLIC(QtAbstractPropertyBrowser) -public: - QtAbstractPropertyBrowserPrivate(); - - void insertSubTree(QtProperty *property, - QtProperty *parentProperty); - void removeSubTree(QtProperty *property, - QtProperty *parentProperty); - void createBrowserIndexes(QtProperty *property, QtProperty *parentProperty, QtProperty *afterProperty); - void removeBrowserIndexes(QtProperty *property, QtProperty *parentProperty); - QtBrowserItem *createBrowserIndex(QtProperty *property, QtBrowserItem *parentIndex, QtBrowserItem *afterIndex); - void removeBrowserIndex(QtBrowserItem *index); - void clearIndex(QtBrowserItem *index); - - void slotPropertyInserted(QtProperty *property, - QtProperty *parentProperty, QtProperty *afterProperty); - void slotPropertyRemoved(QtProperty *property, QtProperty *parentProperty); - void slotPropertyDestroyed(QtProperty *property); - void slotPropertyDataChanged(QtProperty *property); - - QList m_subItems; - QMap > m_managerToProperties; - QMap > m_propertyToParents; - - QMap m_topLevelPropertyToIndex; - QList m_topLevelIndexes; - QMap > m_propertyToIndexes; - - QtBrowserItem *m_currentItem; -}; - -QtAbstractPropertyBrowserPrivate::QtAbstractPropertyBrowserPrivate() : - m_currentItem(0) -{ -} - -void QtAbstractPropertyBrowserPrivate::insertSubTree(QtProperty *property, - QtProperty *parentProperty) -{ - if (m_propertyToParents.contains(property)) { - // property was already inserted, so its manager is connected - // and all its children are inserted and theirs managers are connected - // we just register new parent (parent has to be new). - m_propertyToParents[property].append(parentProperty); - // don't need to update m_managerToProperties map since - // m_managerToProperties[manager] already contains property. - return; - } - QtAbstractPropertyManager *manager = property->propertyManager(); - if (m_managerToProperties[manager].isEmpty()) { - // connect manager's signals - q_ptr->connect(manager, SIGNAL(propertyInserted(QtProperty *, - QtProperty *, QtProperty *)), - q_ptr, SLOT(slotPropertyInserted(QtProperty *, - QtProperty *, QtProperty *))); - q_ptr->connect(manager, SIGNAL(propertyRemoved(QtProperty *, - QtProperty *)), - q_ptr, SLOT(slotPropertyRemoved(QtProperty *, QtProperty *))); - q_ptr->connect(manager, SIGNAL(propertyDestroyed(QtProperty *)), - q_ptr, SLOT(slotPropertyDestroyed(QtProperty *))); - q_ptr->connect(manager, SIGNAL(propertyChanged(QtProperty *)), - q_ptr, SLOT(slotPropertyDataChanged(QtProperty *))); - } - m_managerToProperties[manager].append(property); - m_propertyToParents[property].append(parentProperty); - - QList subList = property->subProperties(); - QListIterator itSub(subList); - while (itSub.hasNext()) { - QtProperty *subProperty = itSub.next(); - insertSubTree(subProperty, property); - } -} - -void QtAbstractPropertyBrowserPrivate::removeSubTree(QtProperty *property, - QtProperty *parentProperty) -{ - if (!m_propertyToParents.contains(property)) { - // ASSERT - return; - } - - m_propertyToParents[property].removeAll(parentProperty); - if (!m_propertyToParents[property].isEmpty()) - return; - - m_propertyToParents.remove(property); - QtAbstractPropertyManager *manager = property->propertyManager(); - m_managerToProperties[manager].removeAll(property); - if (m_managerToProperties[manager].isEmpty()) { - // disconnect manager's signals - q_ptr->disconnect(manager, SIGNAL(propertyInserted(QtProperty *, - QtProperty *, QtProperty *)), - q_ptr, SLOT(slotPropertyInserted(QtProperty *, - QtProperty *, QtProperty *))); - q_ptr->disconnect(manager, SIGNAL(propertyRemoved(QtProperty *, - QtProperty *)), - q_ptr, SLOT(slotPropertyRemoved(QtProperty *, QtProperty *))); - q_ptr->disconnect(manager, SIGNAL(propertyDestroyed(QtProperty *)), - q_ptr, SLOT(slotPropertyDestroyed(QtProperty *))); - q_ptr->disconnect(manager, SIGNAL(propertyChanged(QtProperty *)), - q_ptr, SLOT(slotPropertyDataChanged(QtProperty *))); - - m_managerToProperties.remove(manager); - } - - QList subList = property->subProperties(); - QListIterator itSub(subList); - while (itSub.hasNext()) { - QtProperty *subProperty = itSub.next(); - removeSubTree(subProperty, property); - } -} - -void QtAbstractPropertyBrowserPrivate::createBrowserIndexes(QtProperty *property, QtProperty *parentProperty, QtProperty *afterProperty) -{ - QMap parentToAfter; - if (afterProperty) { - QMap >::ConstIterator it = - m_propertyToIndexes.find(afterProperty); - if (it == m_propertyToIndexes.constEnd()) - return; - - QList indexes = it.value(); - QListIterator itIndex(indexes); - while (itIndex.hasNext()) { - QtBrowserItem *idx = itIndex.next(); - QtBrowserItem *parentIdx = idx->parent(); - if ((parentProperty && parentIdx && parentIdx->property() == parentProperty) || (!parentProperty && !parentIdx)) - parentToAfter[idx->parent()] = idx; - } - } else if (parentProperty) { - QMap >::ConstIterator it = - m_propertyToIndexes.find(parentProperty); - if (it == m_propertyToIndexes.constEnd()) - return; - - QList indexes = it.value(); - QListIterator itIndex(indexes); - while (itIndex.hasNext()) { - QtBrowserItem *idx = itIndex.next(); - parentToAfter[idx] = 0; - } - } else { - parentToAfter[0] = 0; - } - - const QMap::ConstIterator pcend = parentToAfter.constEnd(); - for (QMap::ConstIterator it = parentToAfter.constBegin(); it != pcend; ++it) - createBrowserIndex(property, it.key(), it.value()); -} - -QtBrowserItem *QtAbstractPropertyBrowserPrivate::createBrowserIndex(QtProperty *property, - QtBrowserItem *parentIndex, QtBrowserItem *afterIndex) -{ - QtBrowserItem *newIndex = new QtBrowserItem(q_ptr, property, parentIndex); - if (parentIndex) { - parentIndex->d_ptr->addChild(newIndex, afterIndex); - } else { - m_topLevelPropertyToIndex[property] = newIndex; - m_topLevelIndexes.insert(m_topLevelIndexes.indexOf(afterIndex) + 1, newIndex); - } - m_propertyToIndexes[property].append(newIndex); - - q_ptr->itemInserted(newIndex, afterIndex); - - QList subItems = property->subProperties(); - QListIterator itChild(subItems); - QtBrowserItem *afterChild = 0; - while (itChild.hasNext()) { - QtProperty *child = itChild.next(); - afterChild = createBrowserIndex(child, newIndex, afterChild); - } - return newIndex; -} - -void QtAbstractPropertyBrowserPrivate::removeBrowserIndexes(QtProperty *property, QtProperty *parentProperty) -{ - QList toRemove; - QMap >::ConstIterator it = - m_propertyToIndexes.find(property); - if (it == m_propertyToIndexes.constEnd()) - return; - - QList indexes = it.value(); - QListIterator itIndex(indexes); - while (itIndex.hasNext()) { - QtBrowserItem *idx = itIndex.next(); - QtBrowserItem *parentIdx = idx->parent(); - if ((parentProperty && parentIdx && parentIdx->property() == parentProperty) || (!parentProperty && !parentIdx)) - toRemove.append(idx); - } - - QListIterator itRemove(toRemove); - while (itRemove.hasNext()) { - QtBrowserItem *index = itRemove.next(); - removeBrowserIndex(index); - } -} - -void QtAbstractPropertyBrowserPrivate::removeBrowserIndex(QtBrowserItem *index) -{ - QList children = index->children(); - for (int i = children.count(); i > 0; i--) { - removeBrowserIndex(children.at(i - 1)); - } - - q_ptr->itemRemoved(index); - - if (index->parent()) { - index->parent()->d_ptr->removeChild(index); - } else { - m_topLevelPropertyToIndex.remove(index->property()); - m_topLevelIndexes.removeAll(index); - } - - QtProperty *property = index->property(); - - m_propertyToIndexes[property].removeAll(index); - if (m_propertyToIndexes[property].isEmpty()) - m_propertyToIndexes.remove(property); - - delete index; -} - -void QtAbstractPropertyBrowserPrivate::clearIndex(QtBrowserItem *index) -{ - QList children = index->children(); - QListIterator itChild(children); - while (itChild.hasNext()) { - clearIndex(itChild.next()); - } - delete index; -} - -void QtAbstractPropertyBrowserPrivate::slotPropertyInserted(QtProperty *property, - QtProperty *parentProperty, QtProperty *afterProperty) -{ - if (!m_propertyToParents.contains(parentProperty)) - return; - createBrowserIndexes(property, parentProperty, afterProperty); - insertSubTree(property, parentProperty); - //q_ptr->propertyInserted(property, parentProperty, afterProperty); -} - -void QtAbstractPropertyBrowserPrivate::slotPropertyRemoved(QtProperty *property, - QtProperty *parentProperty) -{ - if (!m_propertyToParents.contains(parentProperty)) - return; - removeSubTree(property, parentProperty); // this line should be probably moved down after propertyRemoved call - //q_ptr->propertyRemoved(property, parentProperty); - removeBrowserIndexes(property, parentProperty); -} - -void QtAbstractPropertyBrowserPrivate::slotPropertyDestroyed(QtProperty *property) -{ - if (!m_subItems.contains(property)) - return; - q_ptr->removeProperty(property); -} - -void QtAbstractPropertyBrowserPrivate::slotPropertyDataChanged(QtProperty *property) -{ - if (!m_propertyToParents.contains(property)) - return; - - QMap >::ConstIterator it = - m_propertyToIndexes.find(property); - if (it == m_propertyToIndexes.constEnd()) - return; - - QList indexes = it.value(); - QListIterator itIndex(indexes); - while (itIndex.hasNext()) { - QtBrowserItem *idx = itIndex.next(); - q_ptr->itemChanged(idx); - } - //q_ptr->propertyChanged(property); -} - -/*! - \class QtAbstractPropertyBrowser - - \brief QtAbstractPropertyBrowser provides a base class for - implementing property browsers. - - A property browser is a widget that enables the user to edit a - given set of properties. Each property is represented by a label - specifying the property's name, and an editing widget (e.g. a line - edit or a combobox) holding its value. A property can have zero or - more subproperties. - - \image qtpropertybrowser.png - - The top level properties can be retrieved using the - properties() function. To traverse each property's - subproperties, use the QtProperty::subProperties() function. In - addition, the set of top level properties can be manipulated using - the addProperty(), insertProperty() and removeProperty() - functions. Note that the QtProperty class provides a corresponding - set of functions making it possible to manipulate the set of - subproperties as well. - - To remove all the properties from the property browser widget, use - the clear() function. This function will clear the editor, but it - will not delete the properties since they can still be used in - other editors. - - The properties themselves are created and managed by - implementations of the QtAbstractPropertyManager class. A manager - can handle (i.e. create and manage) properties of a given type. In - the property browser the managers are associated with - implementations of the QtAbstractEditorFactory: A factory is a - class able to create an editing widget of a specified type. - - When using a property browser widget, managers must be created for - each of the required property types before the properties - themselves can be created. To ensure that the properties' values - will be displayed using suitable editing widgets, the managers - must be associated with objects of the preferred factory - implementations using the setFactoryForManager() function. The - property browser will use these associations to determine which - factory it should use to create the preferred editing widget. - - Note that a factory can be associated with many managers, but a - manager can only be associated with one single factory within the - context of a single property browser. The associations between - managers and factories can at any time be removed using the - unsetFactoryForManager() function. - - Whenever the property data changes or a property is inserted or - removed, the itemChanged(), itemInserted() or - itemRemoved() functions are called, respectively. These - functions must be reimplemented in derived classes in order to - update the property browser widget. Be aware that some property - instances can appear several times in an abstract tree - structure. For example: - - \table 100% - \row - \o - \code - QtProperty *property1, *property2, *property3; - - property2->addSubProperty(property1); - property3->addSubProperty(property2); - - QtAbstractPropertyBrowser *editor; - - editor->addProperty(property1); - editor->addProperty(property2); - editor->addProperty(property3); - \endcode - \o \image qtpropertybrowser-duplicate.png - \endtable - - The addProperty() function returns a QtBrowserItem that uniquely - identifies the created item. - - To make a property editable in the property browser, the - createEditor() function must be called to provide the - property with a suitable editing widget. - - Note that there are two ready-made property browser - implementations: - - \list - \o QtGroupBoxPropertyBrowser - \o QtTreePropertyBrowser - \endlist - - \sa QtAbstractPropertyManager, QtAbstractEditorFactoryBase -*/ - -/*! - \fn void QtAbstractPropertyBrowser::setFactoryForManager(PropertyManager *manager, - QtAbstractEditorFactory *factory) - - Connects the given \a manager to the given \a factory, ensuring - that properties of the \a manager's type will be displayed with an - editing widget suitable for their value. - - For example: - - \code - QtIntPropertyManager *intManager; - QtDoublePropertyManager *doubleManager; - - QtProperty *myInteger = intManager->addProperty(); - QtProperty *myDouble = doubleManager->addProperty(); - - QtSpinBoxFactory *spinBoxFactory; - QtDoubleSpinBoxFactory *doubleSpinBoxFactory; - - QtAbstractPropertyBrowser *editor; - editor->setFactoryForManager(intManager, spinBoxFactory); - editor->setFactoryForManager(doubleManager, doubleSpinBoxFactory); - - editor->addProperty(myInteger); - editor->addProperty(myDouble); - \endcode - - In this example the \c myInteger property's value is displayed - with a QSpinBox widget, while the \c myDouble property's value is - displayed with a QDoubleSpinBox widget. - - Note that a factory can be associated with many managers, but a - manager can only be associated with one single factory. If the - given \a manager already is associated with another factory, the - old association is broken before the new one established. - - This function ensures that the given \a manager and the given \a - factory are compatible, and it automatically calls the - QtAbstractEditorFactory::addPropertyManager() function if necessary. - - \sa unsetFactoryForManager() -*/ - -/*! - \fn virtual void QtAbstractPropertyBrowser::itemInserted(QtBrowserItem *insertedItem, - QtBrowserItem *precedingItem) = 0 - - This function is called to update the widget whenever a property - is inserted or added to the property browser, passing pointers to - the \a insertedItem of property and the specified - \a precedingItem as parameters. - - If \a precedingItem is 0, the \a insertedItem was put at - the beginning of its parent item's list of subproperties. If - the parent of \a insertedItem is 0, the \a insertedItem was added as a top - level property of \e this property browser. - - This function must be reimplemented in derived classes. Note that - if the \a insertedItem's property has subproperties, this - method will be called for those properties as soon as the current call is finished. - - \sa insertProperty(), addProperty() -*/ - -/*! - \fn virtual void QtAbstractPropertyBrowser::itemRemoved(QtBrowserItem *item) = 0 - - This function is called to update the widget whenever a property - is removed from the property browser, passing the pointer to the - \a item of the property as parameters. The passed \a item is - deleted just after this call is finished. - - If the the parent of \a item is 0, the removed \a item was a - top level property in this editor. - - This function must be reimplemented in derived classes. Note that - if the removed \a item's property has subproperties, this - method will be called for those properties just before the current call is started. - - \sa removeProperty() -*/ - -/*! - \fn virtual void QtAbstractPropertyBrowser::itemChanged(QtBrowserItem *item) = 0 - - This function is called whenever a property's data changes, - passing a pointer to the \a item of property as parameter. - - This function must be reimplemented in derived classes in order to - update the property browser widget whenever a property's name, - tool tip, status tip, "what's this" text, value text or value icon - changes. - - Note that if the property browser contains several occurrences of - the same property, this method will be called once for each - occurrence (with a different item each time). - - \sa QtProperty, items() -*/ - -/*! - Creates an abstract property browser with the given \a parent. -*/ -QtAbstractPropertyBrowser::QtAbstractPropertyBrowser(QWidget *parent) - : QWidget(parent) -{ - d_ptr = new QtAbstractPropertyBrowserPrivate; - d_ptr->q_ptr = this; - -} - -/*! - Destroys the property browser, and destroys all the items that were - created by this property browser. - - Note that the properties that were displayed in the editor are not - deleted since they still can be used in other editors. Neither - does the destructor delete the property managers and editor - factories that were used by this property browser widget unless - this widget was their parent. - - \sa QtAbstractPropertyManager::~QtAbstractPropertyManager() -*/ -QtAbstractPropertyBrowser::~QtAbstractPropertyBrowser() -{ - QList indexes = topLevelItems(); - QListIterator itItem(indexes); - while (itItem.hasNext()) - d_ptr->clearIndex(itItem.next()); - delete d_ptr; -} - -/*! - Returns the property browser's list of top level properties. - - To traverse the subproperties, use the QtProperty::subProperties() - function. - - \sa addProperty(), insertProperty(), removeProperty() -*/ -QList QtAbstractPropertyBrowser::properties() const -{ - return d_ptr->m_subItems; -} - -/*! - Returns the property browser's list of all items associated - with the given \a property. - - There is one item per instance of the property in the browser. - - \sa topLevelItem() -*/ - -QList QtAbstractPropertyBrowser::items(QtProperty *property) const -{ - return d_ptr->m_propertyToIndexes.value(property); -} - -/*! - Returns the top-level items associated with the given \a property. - - Returns 0 if \a property wasn't inserted into this property - browser or isn't a top-level one. - - \sa topLevelItems(), items() -*/ - -QtBrowserItem *QtAbstractPropertyBrowser::topLevelItem(QtProperty *property) const -{ - return d_ptr->m_topLevelPropertyToIndex.value(property); -} - -/*! - Returns the list of top-level items. - - \sa topLevelItem() -*/ - -QList QtAbstractPropertyBrowser::topLevelItems() const -{ - return d_ptr->m_topLevelIndexes; -} - -/*! - Removes all the properties from the editor, but does not delete - them since they can still be used in other editors. - - \sa removeProperty(), QtAbstractPropertyManager::clear() -*/ -void QtAbstractPropertyBrowser::clear() -{ - QList subList = properties(); - QListIterator itSub(subList); - itSub.toBack(); - while (itSub.hasPrevious()) { - QtProperty *property = itSub.previous(); - removeProperty(property); - } -} - -/*! - Appends the given \a property (and its subproperties) to the - property browser's list of top level properties. Returns the item - created by property browser which is associated with the \a property. - In order to get all children items created by the property - browser in this call, the returned item should be traversed. - - If the specified \a property is already added, this function does - nothing and returns 0. - - \sa insertProperty(), QtProperty::addSubProperty(), properties() -*/ -QtBrowserItem *QtAbstractPropertyBrowser::addProperty(QtProperty *property) -{ - QtProperty *afterProperty = 0; - if (d_ptr->m_subItems.count() > 0) - afterProperty = d_ptr->m_subItems.last(); - return insertProperty(property, afterProperty); -} - -/*! - \fn QtBrowserItem *QtAbstractPropertyBrowser::insertProperty(QtProperty *property, - QtProperty *afterProperty) - - Inserts the given \a property (and its subproperties) after - the specified \a afterProperty in the browser's list of top - level properties. Returns item created by property browser which - is associated with the \a property. In order to get all children items - created by the property browser in this call returned item should be traversed. - - If the specified \a afterProperty is 0, the given \a property is - inserted at the beginning of the list. If \a property is - already inserted, this function does nothing and returns 0. - - \sa addProperty(), QtProperty::insertSubProperty(), properties() -*/ -QtBrowserItem *QtAbstractPropertyBrowser::insertProperty(QtProperty *property, - QtProperty *afterProperty) -{ - if (!property) - return 0; - - // if item is already inserted in this item then cannot add. - QList pendingList = properties(); - int pos = 0; - int newPos = 0; - QtProperty *properAfterProperty = 0; - while (pos < pendingList.count()) { - QtProperty *prop = pendingList.at(pos); - if (prop == property) - return 0; - if (prop == afterProperty) { - newPos = pos + 1; - properAfterProperty = afterProperty; - } - pos++; - } - d_ptr->createBrowserIndexes(property, 0, afterProperty); - - // traverse inserted subtree and connect to manager's signals - d_ptr->insertSubTree(property, 0); - - d_ptr->m_subItems.insert(newPos, property); - //propertyInserted(property, 0, properAfterProperty); - return topLevelItem(property); -} - -/*! - Removes the specified \a property (and its subproperties) from the - property browser's list of top level properties. All items - that were associated with the given \a property and its children - are deleted. - - Note that the properties are \e not deleted since they can still - be used in other editors. - - \sa clear(), QtProperty::removeSubProperty(), properties() -*/ -void QtAbstractPropertyBrowser::removeProperty(QtProperty *property) -{ - if (!property) - return; - - QList pendingList = properties(); - int pos = 0; - while (pos < pendingList.count()) { - if (pendingList.at(pos) == property) { - d_ptr->m_subItems.removeAt(pos); //perhaps this two lines - d_ptr->removeSubTree(property, 0); //should be moved down after propertyRemoved call. - //propertyRemoved(property, 0); - - d_ptr->removeBrowserIndexes(property, 0); - - // when item is deleted, item will call removeItem for top level items, - // and itemRemoved for nested items. - - return; - } - pos++; - } -} - -/*! - Creates an editing widget (with the given \a parent) for the given - \a property according to the previously established associations - between property managers and editor factories. - - If the property is created by a property manager which was not - associated with any of the existing factories in \e this property - editor, the function returns 0. - - To make a property editable in the property browser, the - createEditor() function must be called to provide the - property with a suitable editing widget. - - Reimplement this function to provide additional decoration for the - editing widgets created by the installed factories. - - \sa setFactoryForManager() -*/ -QWidget *QtAbstractPropertyBrowser::createEditor(QtProperty *property, - QWidget *parent) -{ - QtAbstractEditorFactoryBase *factory = 0; - QtAbstractPropertyManager *manager = property->propertyManager(); - - if (m_viewToManagerToFactory()->contains(this) && - (*m_viewToManagerToFactory())[this].contains(manager)) { - factory = (*m_viewToManagerToFactory())[this][manager]; - } - - if (!factory) - return 0; - return factory->createEditor(property, parent); -} - -bool QtAbstractPropertyBrowser::addFactory(QtAbstractPropertyManager *abstractManager, - QtAbstractEditorFactoryBase *abstractFactory) -{ - bool connectNeeded = false; - if (!m_managerToFactoryToViews()->contains(abstractManager) || - !(*m_managerToFactoryToViews())[abstractManager].contains(abstractFactory)) { - connectNeeded = true; - } else if ((*m_managerToFactoryToViews())[abstractManager][abstractFactory] - .contains(this)) { - return connectNeeded; - } - - if (m_viewToManagerToFactory()->contains(this) && - (*m_viewToManagerToFactory())[this].contains(abstractManager)) { - unsetFactoryForManager(abstractManager); - } - - (*m_managerToFactoryToViews())[abstractManager][abstractFactory].append(this); - (*m_viewToManagerToFactory())[this][abstractManager] = abstractFactory; - - return connectNeeded; -} - -/*! - Removes the association between the given \a manager and the - factory bound to it, automatically calling the - QtAbstractEditorFactory::removePropertyManager() function if necessary. - - \sa setFactoryForManager() -*/ -void QtAbstractPropertyBrowser::unsetFactoryForManager(QtAbstractPropertyManager *manager) -{ - if (!m_viewToManagerToFactory()->contains(this) || - !(*m_viewToManagerToFactory())[this].contains(manager)) { - return; - } - - QtAbstractEditorFactoryBase *abstractFactory = - (*m_viewToManagerToFactory())[this][manager]; - (*m_viewToManagerToFactory())[this].remove(manager); - if ((*m_viewToManagerToFactory())[this].isEmpty()) { - (*m_viewToManagerToFactory()).remove(this); - } - - (*m_managerToFactoryToViews())[manager][abstractFactory].removeAll(this); - if ((*m_managerToFactoryToViews())[manager][abstractFactory].isEmpty()) { - (*m_managerToFactoryToViews())[manager].remove(abstractFactory); - abstractFactory->breakConnection(manager); - if ((*m_managerToFactoryToViews())[manager].isEmpty()) { - (*m_managerToFactoryToViews()).remove(manager); - } - } -} - -/*! - Returns the current item in the property browser. - - \sa setCurrentItem() -*/ -QtBrowserItem *QtAbstractPropertyBrowser::currentItem() const -{ - return d_ptr->m_currentItem; -} - -/*! - Sets the current item in the property browser to \a item. - - \sa currentItem(), currentItemChanged() -*/ -void QtAbstractPropertyBrowser::setCurrentItem(QtBrowserItem *item) -{ - QtBrowserItem *oldItem = d_ptr->m_currentItem; - d_ptr->m_currentItem = item; - if (oldItem != item) - emit currentItemChanged(item); -} - -#if QT_VERSION >= 0x040400 -QT_END_NAMESPACE -#endif - -#include "moc_qtpropertybrowser.cxx" diff --git a/QtPropertyBrowser/qtpropertybrowser.h b/QtPropertyBrowser/qtpropertybrowser.h deleted file mode 100644 index 544f7765f1..0000000000 --- a/QtPropertyBrowser/qtpropertybrowser.h +++ /dev/null @@ -1,376 +0,0 @@ -/**************************************************************************** -** -** This file is part of a Qt Solutions component. -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Solutions Commercial License Agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** Please note Third Party Software included with Qt Solutions may impose -** additional restrictions and it is the user's responsibility to ensure -** that they have met the licensing requirements of the GPL, LGPL, or Qt -** Solutions Commercial license and the relevant license of the Third -** Party Software they are using. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTPROPERTYBROWSER_H -#define QTPROPERTYBROWSER_H - -#include -#include - -#if QT_VERSION >= 0x040400 -QT_BEGIN_NAMESPACE -#endif - -#if defined(Q_WS_WIN) -# if !defined(QT_QTPROPERTYBROWSER_EXPORT) && !defined(QT_QTPROPERTYBROWSER_IMPORT) -# define QT_QTPROPERTYBROWSER_EXPORT -# elif defined(QT_QTPROPERTYBROWSER_IMPORT) -# if defined(QT_QTPROPERTYBROWSER_EXPORT) -# undef QT_QTPROPERTYBROWSER_EXPORT -# endif -# define QT_QTPROPERTYBROWSER_EXPORT __declspec(dllimport) -# elif defined(QT_QTPROPERTYBROWSER_EXPORT) -# undef QT_QTPROPERTYBROWSER_EXPORT -# define QT_QTPROPERTYBROWSER_EXPORT __declspec(dllexport) -# endif -#else -# define QT_QTPROPERTYBROWSER_EXPORT -#endif - - -class QtAbstractPropertyManager; -class QtPropertyPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtProperty -{ -public: - virtual ~QtProperty(); - - QList subProperties() const; - - QtAbstractPropertyManager *propertyManager() const; - - QString toolTip() const; - QString statusTip() const; - QString whatsThis() const; - QString propertyName() const; - bool isEnabled() const; - bool isModified() const; - - bool hasValue() const; - QIcon valueIcon() const; - QString valueText() const; - - void setToolTip(const QString &text); - void setStatusTip(const QString &text); - void setWhatsThis(const QString &text); - void setPropertyName(const QString &text); - void setEnabled(bool enable); - void setModified(bool modified); - - void addSubProperty(QtProperty *property); - void insertSubProperty(QtProperty *property, QtProperty *afterProperty); - void removeSubProperty(QtProperty *property); -protected: - explicit QtProperty(QtAbstractPropertyManager *manager); - void propertyChanged(); -private: - friend class QtAbstractPropertyManager; - QtPropertyPrivate *d_ptr; -}; - -class QtAbstractPropertyManagerPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtAbstractPropertyManager : public QObject -{ - Q_OBJECT -public: - - explicit QtAbstractPropertyManager(QObject *parent = 0); - ~QtAbstractPropertyManager(); - - QSet properties() const; - void clear() const; - - QtProperty *addProperty(const QString &name = QString()); -Q_SIGNALS: - - void propertyInserted(QtProperty *property, - QtProperty *parent, QtProperty *after); - void propertyChanged(QtProperty *property); - void propertyRemoved(QtProperty *property, QtProperty *parent); - void propertyDestroyed(QtProperty *property); -protected: - virtual bool hasValue(const QtProperty *property) const; - virtual QIcon valueIcon(const QtProperty *property) const; - virtual QString valueText(const QtProperty *property) const; - virtual void initializeProperty(QtProperty *property) = 0; - virtual void uninitializeProperty(QtProperty *property); - virtual QtProperty *createProperty(); -private: - friend class QtProperty; - QtAbstractPropertyManagerPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtAbstractPropertyManager) - Q_DISABLE_COPY(QtAbstractPropertyManager) -}; - -class QT_QTPROPERTYBROWSER_EXPORT QtAbstractEditorFactoryBase : public QObject -{ - Q_OBJECT -public: - virtual QWidget *createEditor(QtProperty *property, QWidget *parent) = 0; -protected: - explicit QtAbstractEditorFactoryBase(QObject *parent = 0) - : QObject(parent) {} - - virtual void breakConnection(QtAbstractPropertyManager *manager) = 0; -protected Q_SLOTS: - virtual void managerDestroyed(QObject *manager) = 0; - - friend class QtAbstractPropertyBrowser; -}; - -template -class QtAbstractEditorFactory : public QtAbstractEditorFactoryBase -{ -public: - explicit QtAbstractEditorFactory(QObject *parent) : QtAbstractEditorFactoryBase(parent) {} - QWidget *createEditor(QtProperty *property, QWidget *parent) - { - QSetIterator it(m_managers); - while (it.hasNext()) { - PropertyManager *manager = it.next(); - if (manager == property->propertyManager()) { - return createEditor(manager, property, parent); - } - } - return 0; - } - void addPropertyManager(PropertyManager *manager) - { - if (m_managers.contains(manager)) - return; - m_managers.insert(manager); - connectPropertyManager(manager); - connect(manager, SIGNAL(destroyed(QObject *)), - this, SLOT(managerDestroyed(QObject *))); - } - void removePropertyManager(PropertyManager *manager) - { - if (!m_managers.contains(manager)) - return; - disconnect(manager, SIGNAL(destroyed(QObject *)), - this, SLOT(managerDestroyed(QObject *))); - disconnectPropertyManager(manager); - m_managers.remove(manager); - } - QSet propertyManagers() const - { - return m_managers; - } - PropertyManager *propertyManager(QtProperty *property) const - { - QtAbstractPropertyManager *manager = property->propertyManager(); - QSetIterator itManager(m_managers); - while (itManager.hasNext()) { - PropertyManager *m = itManager.next(); - if (m == manager) { - return m; - } - } - return 0; - } -protected: - virtual void connectPropertyManager(PropertyManager *manager) = 0; - virtual QWidget *createEditor(PropertyManager *manager, QtProperty *property, - QWidget *parent) = 0; - virtual void disconnectPropertyManager(PropertyManager *manager) = 0; - void managerDestroyed(QObject *manager) - { - QSetIterator it(m_managers); - while (it.hasNext()) { - PropertyManager *m = it.next(); - if (m == manager) { - m_managers.remove(m); - return; - } - } - } -private: - void breakConnection(QtAbstractPropertyManager *manager) - { - QSetIterator it(m_managers); - while (it.hasNext()) { - PropertyManager *m = it.next(); - if (m == manager) { - removePropertyManager(m); - return; - } - } - } -private: - QSet m_managers; - friend class QtAbstractPropertyEditor; -}; - -class QtAbstractPropertyBrowser; -class QtBrowserItemPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtBrowserItem -{ -public: - QtProperty *property() const; - QtBrowserItem *parent() const; - QList children() const; - QtAbstractPropertyBrowser *browser() const; -private: - explicit QtBrowserItem(QtAbstractPropertyBrowser *browser, QtProperty *property, QtBrowserItem *parent); - ~QtBrowserItem(); - QtBrowserItemPrivate *d_ptr; - friend class QtAbstractPropertyBrowserPrivate; -}; - -class QtAbstractPropertyBrowserPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtAbstractPropertyBrowser : public QWidget -{ - Q_OBJECT -public: - - explicit QtAbstractPropertyBrowser(QWidget *parent = 0); - ~QtAbstractPropertyBrowser(); - - QList properties() const; - QList items(QtProperty *property) const; - QtBrowserItem *topLevelItem(QtProperty *property) const; - QList topLevelItems() const; - void clear(); - - template - void setFactoryForManager(PropertyManager *manager, - QtAbstractEditorFactory *factory) { - QtAbstractPropertyManager *abstractManager = manager; - QtAbstractEditorFactoryBase *abstractFactory = factory; - - if (addFactory(abstractManager, abstractFactory)) - factory->addPropertyManager(manager); - } - - void unsetFactoryForManager(QtAbstractPropertyManager *manager); - - QtBrowserItem *currentItem() const; - void setCurrentItem(QtBrowserItem *); - -Q_SIGNALS: - void currentItemChanged(QtBrowserItem *); - -public Q_SLOTS: - - QtBrowserItem *addProperty(QtProperty *property); - QtBrowserItem *insertProperty(QtProperty *property, QtProperty *afterProperty); - void removeProperty(QtProperty *property); - -protected: - - virtual void itemInserted(QtBrowserItem *item, QtBrowserItem *afterItem) = 0; - virtual void itemRemoved(QtBrowserItem *item) = 0; - // can be tooltip, statustip, whatsthis, name, icon, text. - virtual void itemChanged(QtBrowserItem *item) = 0; - - virtual QWidget *createEditor(QtProperty *property, QWidget *parent); -private: - - bool addFactory(QtAbstractPropertyManager *abstractManager, - QtAbstractEditorFactoryBase *abstractFactory); - - QtAbstractPropertyBrowserPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtAbstractPropertyBrowser) - Q_DISABLE_COPY(QtAbstractPropertyBrowser) - Q_PRIVATE_SLOT(d_func(), void slotPropertyInserted(QtProperty *, - QtProperty *, QtProperty *)) - Q_PRIVATE_SLOT(d_func(), void slotPropertyRemoved(QtProperty *, - QtProperty *)) - Q_PRIVATE_SLOT(d_func(), void slotPropertyDestroyed(QtProperty *)) - Q_PRIVATE_SLOT(d_func(), void slotPropertyDataChanged(QtProperty *)) - -}; - -#if QT_VERSION >= 0x040400 -QT_END_NAMESPACE -#endif - -#endif // QTPROPERTYBROWSER_H diff --git a/QtPropertyBrowser/qtpropertybrowserutils.cpp b/QtPropertyBrowser/qtpropertybrowserutils.cpp deleted file mode 100644 index 81e37637a7..0000000000 --- a/QtPropertyBrowser/qtpropertybrowserutils.cpp +++ /dev/null @@ -1,482 +0,0 @@ -/**************************************************************************** -** -** This file is part of a Qt Solutions component. -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Solutions Commercial License Agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** Please note Third Party Software included with Qt Solutions may impose -** additional restrictions and it is the user's responsibility to ensure -** that they have met the licensing requirements of the GPL, LGPL, or Qt -** Solutions Commercial license and the relevant license of the Third -** Party Software they are using. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qtpropertybrowserutils_p.h" -#include -#include -#include -#include -#include -#include -#include - -#if QT_VERSION >= 0x040400 -QT_BEGIN_NAMESPACE -#endif - -QtCursorDatabase::QtCursorDatabase() -{ - appendCursor(Qt::ArrowCursor, QApplication::translate("QtCursorDatabase", "Arrow", 0, - QApplication::UnicodeUTF8), QIcon(QLatin1String(":/trolltech/qtpropertybrowser/images/cursor-arrow.png"))); - appendCursor(Qt::UpArrowCursor, QApplication::translate("QtCursorDatabase", "Up Arrow", 0, - QApplication::UnicodeUTF8), QIcon(QLatin1String(":/trolltech/qtpropertybrowser/images/cursor-uparrow.png"))); - appendCursor(Qt::CrossCursor, QApplication::translate("QtCursorDatabase", "Cross", 0, - QApplication::UnicodeUTF8), QIcon(QLatin1String(":/trolltech/qtpropertybrowser/images/cursor-cross.png"))); - appendCursor(Qt::WaitCursor, QApplication::translate("QtCursorDatabase", "Wait", 0, - QApplication::UnicodeUTF8), QIcon(QLatin1String(":/trolltech/qtpropertybrowser/images/cursor-wait.png"))); - appendCursor(Qt::IBeamCursor, QApplication::translate("QtCursorDatabase", "IBeam", 0, - QApplication::UnicodeUTF8), QIcon(QLatin1String(":/trolltech/qtpropertybrowser/images/cursor-ibeam.png"))); - appendCursor(Qt::SizeVerCursor, QApplication::translate("QtCursorDatabase", "Size Vertical", 0, - QApplication::UnicodeUTF8), QIcon(QLatin1String(":/trolltech/qtpropertybrowser/images/cursor-sizev.png"))); - appendCursor(Qt::SizeHorCursor, QApplication::translate("QtCursorDatabase", "Size Horizontal", 0, - QApplication::UnicodeUTF8), QIcon(QLatin1String(":/trolltech/qtpropertybrowser/images/cursor-sizeh.png"))); - appendCursor(Qt::SizeFDiagCursor, QApplication::translate("QtCursorDatabase", "Size Backslash", 0, - QApplication::UnicodeUTF8), QIcon(QLatin1String(":/trolltech/qtpropertybrowser/images/cursor-sizef.png"))); - appendCursor(Qt::SizeBDiagCursor, QApplication::translate("QtCursorDatabase", "Size Slash", 0, - QApplication::UnicodeUTF8), QIcon(QLatin1String(":/trolltech/qtpropertybrowser/images/cursor-sizeb.png"))); - appendCursor(Qt::SizeAllCursor, QApplication::translate("QtCursorDatabase", "Size All", 0, - QApplication::UnicodeUTF8), QIcon(QLatin1String(":/trolltech/qtpropertybrowser/images/cursor-sizeall.png"))); - appendCursor(Qt::BlankCursor, QApplication::translate("QtCursorDatabase", "Blank", 0, - QApplication::UnicodeUTF8), QIcon()); - appendCursor(Qt::SplitVCursor, QApplication::translate("QtCursorDatabase", "Split Vertical", 0, - QApplication::UnicodeUTF8), QIcon(QLatin1String(":/trolltech/qtpropertybrowser/images/cursor-vsplit.png"))); - appendCursor(Qt::SplitHCursor, QApplication::translate("QtCursorDatabase", "Split Horizontal", 0, - QApplication::UnicodeUTF8), QIcon(QLatin1String(":/trolltech/qtpropertybrowser/images/cursor-hsplit.png"))); - appendCursor(Qt::PointingHandCursor, QApplication::translate("QtCursorDatabase", "Pointing Hand", 0, - QApplication::UnicodeUTF8), QIcon(QLatin1String(":/trolltech/qtpropertybrowser/images/cursor-hand.png"))); - appendCursor(Qt::ForbiddenCursor, QApplication::translate("QtCursorDatabase", "Forbidden", 0, - QApplication::UnicodeUTF8), QIcon(QLatin1String(":/trolltech/qtpropertybrowser/images/cursor-forbidden.png"))); - appendCursor(Qt::OpenHandCursor, QApplication::translate("QtCursorDatabase", "Open Hand", 0, - QApplication::UnicodeUTF8), QIcon(QLatin1String(":/trolltech/qtpropertybrowser/images/cursor-openhand.png"))); - appendCursor(Qt::ClosedHandCursor, QApplication::translate("QtCursorDatabase", "Closed Hand", 0, - QApplication::UnicodeUTF8), QIcon(QLatin1String(":/trolltech/qtpropertybrowser/images/cursor-closedhand.png"))); - appendCursor(Qt::WhatsThisCursor, QApplication::translate("QtCursorDatabase", "What's This", 0, - QApplication::UnicodeUTF8), QIcon(QLatin1String(":/trolltech/qtpropertybrowser/images/cursor-whatsthis.png"))); - appendCursor(Qt::BusyCursor, QApplication::translate("QtCursorDatabase", "Busy", 0, - QApplication::UnicodeUTF8), QIcon(QLatin1String(":/trolltech/qtpropertybrowser/images/cursor-busy.png"))); -} - -void QtCursorDatabase::appendCursor(Qt::CursorShape shape, const QString &name, const QIcon &icon) -{ - if (m_cursorShapeToValue.contains(shape)) - return; - int value = m_cursorNames.count(); - m_cursorNames.append(name); - m_cursorIcons[value] = icon; - m_valueToCursorShape[value] = shape; - m_cursorShapeToValue[shape] = value; -} - -QStringList QtCursorDatabase::cursorShapeNames() const -{ - return m_cursorNames; -} - -QMap QtCursorDatabase::cursorShapeIcons() const -{ - return m_cursorIcons; -} - -QString QtCursorDatabase::cursorToShapeName(const QCursor &cursor) const -{ - int val = cursorToValue(cursor); - if (val >= 0) - return m_cursorNames.at(val); - return QString(); -} - -QIcon QtCursorDatabase::cursorToShapeIcon(const QCursor &cursor) const -{ - int val = cursorToValue(cursor); - return m_cursorIcons.value(val); -} - -int QtCursorDatabase::cursorToValue(const QCursor &cursor) const -{ -#ifndef QT_NO_CURSOR - Qt::CursorShape shape = cursor.shape(); - if (m_cursorShapeToValue.contains(shape)) - return m_cursorShapeToValue[shape]; -#endif - return -1; -} - -#ifndef QT_NO_CURSOR -QCursor QtCursorDatabase::valueToCursor(int value) const -{ - if (m_valueToCursorShape.contains(value)) - return QCursor(m_valueToCursorShape[value]); - return QCursor(); -} -#endif - -QPixmap QtPropertyBrowserUtils::brushValuePixmap(const QBrush &b) -{ - QImage img(16, 16, QImage::Format_ARGB32_Premultiplied); - img.fill(0); - - QPainter painter(&img); - painter.setCompositionMode(QPainter::CompositionMode_Source); - painter.fillRect(0, 0, img.width(), img.height(), b); - QColor color = b.color(); - if (color.alpha() != 255) { // indicate alpha by an inset - QBrush opaqueBrush = b; - color.setAlpha(255); - opaqueBrush.setColor(color); - painter.fillRect(img.width() / 4, img.height() / 4, - img.width() / 2, img.height() / 2, opaqueBrush); - } - painter.end(); - return QPixmap::fromImage(img); -} - -QIcon QtPropertyBrowserUtils::brushValueIcon(const QBrush &b) -{ - return QIcon(brushValuePixmap(b)); -} - -QString QtPropertyBrowserUtils::colorValueText(const QColor &c) -{ - return QApplication::translate("QtPropertyBrowserUtils", "[%1, %2, %3] (%4)", 0, QApplication::UnicodeUTF8) - .arg(QString::number(c.red())) - .arg(QString::number(c.green())) - .arg(QString::number(c.blue())) - .arg(QString::number(c.alpha())); -} - -QPixmap QtPropertyBrowserUtils::fontValuePixmap(const QFont &font) -{ - QFont f = font; - QImage img(16, 16, QImage::Format_ARGB32_Premultiplied); - img.fill(0); - QPainter p(&img); - p.setRenderHint(QPainter::TextAntialiasing, true); - p.setRenderHint(QPainter::Antialiasing, true); - f.setPointSize(13); - p.setFont(f); - QTextOption t; - t.setAlignment(Qt::AlignCenter); - p.drawText(QRect(0, 0, 16, 16), QString(QLatin1Char('A')), t); - return QPixmap::fromImage(img); -} - -QIcon QtPropertyBrowserUtils::fontValueIcon(const QFont &f) -{ - return QIcon(fontValuePixmap(f)); -} - -QString QtPropertyBrowserUtils::fontValueText(const QFont &f) -{ - return QApplication::translate("QtPropertyBrowserUtils", "[%1, %2]", 0, QApplication::UnicodeUTF8) - .arg(f.family()) - .arg(f.pointSize()); -} - - -QtBoolEdit::QtBoolEdit(QWidget *parent) : - QWidget(parent), - m_checkBox(new QCheckBox(this)), - m_textVisible(true) -{ - QHBoxLayout *lt = new QHBoxLayout; - if (QApplication::layoutDirection() == Qt::LeftToRight) - lt->setContentsMargins(4, 0, 0, 0); - else - lt->setContentsMargins(0, 0, 4, 0); - lt->addWidget(m_checkBox); - setLayout(lt); - connect(m_checkBox, SIGNAL(toggled(bool)), this, SIGNAL(toggled(bool))); - setFocusProxy(m_checkBox); - m_checkBox->setText(tr("True")); -} - -void QtBoolEdit::setTextVisible(bool textVisible) -{ - if (m_textVisible == textVisible) - return; - - m_textVisible = textVisible; - if (m_textVisible) - m_checkBox->setText(isChecked() ? tr("True") : tr("False")); - else - m_checkBox->setText(QString()); -} - -Qt::CheckState QtBoolEdit::checkState() const -{ - return m_checkBox->checkState(); -} - -void QtBoolEdit::setCheckState(Qt::CheckState state) -{ - m_checkBox->setCheckState(state); -} - -bool QtBoolEdit::isChecked() const -{ - return m_checkBox->isChecked(); -} - -void QtBoolEdit::setChecked(bool c) -{ - m_checkBox->setChecked(c); - if (!m_textVisible) - return; - m_checkBox->setText(isChecked() ? tr("True") : tr("False")); -} - -bool QtBoolEdit::blockCheckBoxSignals(bool block) -{ - return m_checkBox->blockSignals(block); -} - -void QtBoolEdit::mousePressEvent(QMouseEvent *event) -{ - if (event->buttons() == Qt::LeftButton) { - m_checkBox->click(); - event->accept(); - } else { - QWidget::mousePressEvent(event); - } -} - - -QtKeySequenceEdit::QtKeySequenceEdit(QWidget *parent) - : QWidget(parent), m_num(0), m_lineEdit(new QLineEdit(this)) -{ - QHBoxLayout *layout = new QHBoxLayout(this); - layout->addWidget(m_lineEdit); - layout->setMargin(0); - m_lineEdit->installEventFilter(this); - m_lineEdit->setReadOnly(true); - m_lineEdit->setFocusProxy(this); - setFocusPolicy(m_lineEdit->focusPolicy()); - setAttribute(Qt::WA_InputMethodEnabled); -} - -bool QtKeySequenceEdit::eventFilter(QObject *o, QEvent *e) -{ - if (o == m_lineEdit && e->type() == QEvent::ContextMenu) { - QContextMenuEvent *c = static_cast(e); - QMenu *menu = m_lineEdit->createStandardContextMenu(); - const QList actions = menu->actions(); - QListIterator itAction(actions); - while (itAction.hasNext()) { - QAction *action = itAction.next(); - action->setShortcut(QKeySequence()); - QString actionString = action->text(); - const int pos = actionString.lastIndexOf(QLatin1Char('\t')); - if (pos > 0) - actionString.remove(pos, actionString.length() - pos); - action->setText(actionString); - } - QAction *actionBefore = 0; - if (actions.count() > 0) - actionBefore = actions[0]; - QAction *clearAction = new QAction(tr("Clear Shortcut"), menu); - menu->insertAction(actionBefore, clearAction); - menu->insertSeparator(actionBefore); - clearAction->setEnabled(!m_keySequence.isEmpty()); - connect(clearAction, SIGNAL(triggered()), this, SLOT(slotClearShortcut())); - menu->exec(c->globalPos()); - delete menu; - e->accept(); - return true; - } - - return QWidget::eventFilter(o, e); -} - -void QtKeySequenceEdit::slotClearShortcut() -{ - if (m_keySequence.isEmpty()) - return; - setKeySequence(QKeySequence()); - emit keySequenceChanged(m_keySequence); -} - -void QtKeySequenceEdit::handleKeyEvent(QKeyEvent *e) -{ - int nextKey = e->key(); - if (nextKey == Qt::Key_Control || nextKey == Qt::Key_Shift || - nextKey == Qt::Key_Meta || nextKey == Qt::Key_Alt || - nextKey == Qt::Key_Super_L || nextKey == Qt::Key_AltGr) - return; - - nextKey |= translateModifiers(e->modifiers(), e->text()); - int k0 = m_keySequence[0]; - int k1 = m_keySequence[1]; - int k2 = m_keySequence[2]; - int k3 = m_keySequence[3]; - switch (m_num) { - case 0: k0 = nextKey; k1 = 0; k2 = 0; k3 = 0; break; - case 1: k1 = nextKey; k2 = 0; k3 = 0; break; - case 2: k2 = nextKey; k3 = 0; break; - case 3: k3 = nextKey; break; - default: break; - } - ++m_num; - if (m_num > 3) - m_num = 0; - m_keySequence = QKeySequence(k0, k1, k2, k3); - m_lineEdit->setText(m_keySequence.toString(QKeySequence::NativeText)); - e->accept(); - emit keySequenceChanged(m_keySequence); -} - -void QtKeySequenceEdit::setKeySequence(const QKeySequence &sequence) -{ - if (sequence == m_keySequence) - return; - m_num = 0; - m_keySequence = sequence; - m_lineEdit->setText(m_keySequence.toString(QKeySequence::NativeText)); -} - -QKeySequence QtKeySequenceEdit::keySequence() const -{ - return m_keySequence; -} - -int QtKeySequenceEdit::translateModifiers(Qt::KeyboardModifiers state, const QString &text) const -{ - int result = 0; - if ((state & Qt::ShiftModifier) && (text.size() == 0 || !text.at(0).isPrint() || text.at(0).isLetter() || text.at(0).isSpace())) - result |= Qt::SHIFT; - if (state & Qt::ControlModifier) - result |= Qt::CTRL; - if (state & Qt::MetaModifier) - result |= Qt::META; - if (state & Qt::AltModifier) - result |= Qt::ALT; - return result; -} - -void QtKeySequenceEdit::focusInEvent(QFocusEvent *e) -{ - m_lineEdit->event(e); - m_lineEdit->selectAll(); - QWidget::focusInEvent(e); -} - -void QtKeySequenceEdit::focusOutEvent(QFocusEvent *e) -{ - m_num = 0; - m_lineEdit->event(e); - QWidget::focusOutEvent(e); -} - -void QtKeySequenceEdit::keyPressEvent(QKeyEvent *e) -{ - handleKeyEvent(e); - e->accept(); -} - -void QtKeySequenceEdit::keyReleaseEvent(QKeyEvent *e) -{ - m_lineEdit->event(e); -} - -bool QtKeySequenceEdit::event(QEvent *e) -{ - if (e->type() == QEvent::Shortcut || - e->type() == QEvent::ShortcutOverride || - e->type() == QEvent::KeyRelease) { - e->accept(); - return true; - } - return QWidget::event(e); -} - - - - -#if QT_VERSION >= 0x040400 -QT_END_NAMESPACE -#endif - -#include "moc_qtpropertybrowserutils_p.cxx" diff --git a/QtPropertyBrowser/qtpropertybrowserutils_p.h b/QtPropertyBrowser/qtpropertybrowserutils_p.h deleted file mode 100644 index dca4b8c37b..0000000000 --- a/QtPropertyBrowser/qtpropertybrowserutils_p.h +++ /dev/null @@ -1,207 +0,0 @@ -/**************************************************************************** -** -** This file is part of a Qt Solutions component. -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Solutions Commercial License Agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** Please note Third Party Software included with Qt Solutions may impose -** additional restrictions and it is the user's responsibility to ensure -** that they have met the licensing requirements of the GPL, LGPL, or Qt -** Solutions Commercial license and the relevant license of the Third -** Party Software they are using. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of Qt Designer. This header -// file may change from version to version without notice, or even be removed. -// -// We mean it. -// - -#ifndef QTPROPERTYBROWSERUTILS_H -#define QTPROPERTYBROWSERUTILS_H - -#include -#include -#include -#include - -#if QT_VERSION >= 0x040400 -QT_BEGIN_NAMESPACE -#endif - -class QMouseEvent; -class QCheckBox; -class QLineEdit; - -class QtCursorDatabase -{ -public: - QtCursorDatabase(); - - QStringList cursorShapeNames() const; - QMap cursorShapeIcons() const; - QString cursorToShapeName(const QCursor &cursor) const; - QIcon cursorToShapeIcon(const QCursor &cursor) const; - int cursorToValue(const QCursor &cursor) const; -#ifndef QT_NO_CURSOR - QCursor valueToCursor(int value) const; -#endif -private: - void appendCursor(Qt::CursorShape shape, const QString &name, const QIcon &icon); - QStringList m_cursorNames; - QMap m_cursorIcons; - QMap m_valueToCursorShape; - QMap m_cursorShapeToValue; -}; - -class QtPropertyBrowserUtils -{ -public: - static QPixmap brushValuePixmap(const QBrush &b); - static QIcon brushValueIcon(const QBrush &b); - static QString colorValueText(const QColor &c); - static QPixmap fontValuePixmap(const QFont &f); - static QIcon fontValueIcon(const QFont &f); - static QString fontValueText(const QFont &f); -}; - -class QtBoolEdit : public QWidget { - Q_OBJECT -public: - QtBoolEdit(QWidget *parent = 0); - - bool textVisible() const { return m_textVisible; } - void setTextVisible(bool textVisible); - - Qt::CheckState checkState() const; - void setCheckState(Qt::CheckState state); - - bool isChecked() const; - void setChecked(bool c); - - bool blockCheckBoxSignals(bool block); - -Q_SIGNALS: - void toggled(bool); - -protected: - void mousePressEvent(QMouseEvent * event); - -private: - QCheckBox *m_checkBox; - bool m_textVisible; -}; - -class QtKeySequenceEdit : public QWidget -{ - Q_OBJECT -public: - QtKeySequenceEdit(QWidget *parent = 0); - - QKeySequence keySequence() const; - bool eventFilter(QObject *o, QEvent *e); -public Q_SLOTS: - void setKeySequence(const QKeySequence &sequence); -Q_SIGNALS: - void keySequenceChanged(const QKeySequence &sequence); -protected: - void focusInEvent(QFocusEvent *e); - void focusOutEvent(QFocusEvent *e); - void keyPressEvent(QKeyEvent *e); - void keyReleaseEvent(QKeyEvent *e); - bool event(QEvent *e); -private slots: - void slotClearShortcut(); -private: - void handleKeyEvent(QKeyEvent *e); - int translateModifiers(Qt::KeyboardModifiers state, const QString &text) const; - - int m_num; - QKeySequence m_keySequence; - QLineEdit *m_lineEdit; -}; - -#if QT_VERSION >= 0x040400 -QT_END_NAMESPACE -#endif - -#endif diff --git a/QtPropertyBrowser/qtpropertymanager.cpp b/QtPropertyBrowser/qtpropertymanager.cpp deleted file mode 100644 index 28f8435095..0000000000 --- a/QtPropertyBrowser/qtpropertymanager.cpp +++ /dev/null @@ -1,6483 +0,0 @@ -/**************************************************************************** -** -** This file is part of a Qt Solutions component. -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Solutions Commercial License Agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** Please note Third Party Software included with Qt Solutions may impose -** additional restrictions and it is the user's responsibility to ensure -** that they have met the licensing requirements of the GPL, LGPL, or Qt -** Solutions Commercial license and the relevant license of the Third -** Party Software they are using. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qtpropertymanager.h" -#include "qtpropertybrowserutils_p.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#if defined(Q_CC_MSVC) -# pragma warning(disable: 4786) /* MS VS 6: truncating debug info after 255 characters */ -#endif - -#if QT_VERSION >= 0x040400 -QT_BEGIN_NAMESPACE -#endif - -template -static void setSimpleMinimumData(PrivateData *data, const Value &minVal) -{ - data->minVal = minVal; - if (data->maxVal < data->minVal) - data->maxVal = data->minVal; - - if (data->val < data->minVal) - data->val = data->minVal; -} - -template -static void setSimpleMaximumData(PrivateData *data, const Value &maxVal) -{ - data->maxVal = maxVal; - if (data->minVal > data->maxVal) - data->minVal = data->maxVal; - - if (data->val > data->maxVal) - data->val = data->maxVal; -} - -template -static void setSizeMinimumData(PrivateData *data, const Value &newMinVal) -{ - data->minVal = newMinVal; - if (data->maxVal.width() < data->minVal.width()) - data->maxVal.setWidth(data->minVal.width()); - if (data->maxVal.height() < data->minVal.height()) - data->maxVal.setHeight(data->minVal.height()); - - if (data->val.width() < data->minVal.width()) - data->val.setWidth(data->minVal.width()); - if (data->val.height() < data->minVal.height()) - data->val.setHeight(data->minVal.height()); -} - -template -static void setSizeMaximumData(PrivateData *data, const Value &newMaxVal) -{ - data->maxVal = newMaxVal; - if (data->minVal.width() > data->maxVal.width()) - data->minVal.setWidth(data->maxVal.width()); - if (data->minVal.height() > data->maxVal.height()) - data->minVal.setHeight(data->maxVal.height()); - - if (data->val.width() > data->maxVal.width()) - data->val.setWidth(data->maxVal.width()); - if (data->val.height() > data->maxVal.height()) - data->val.setHeight(data->maxVal.height()); -} - -template -static SizeValue qBoundSize(const SizeValue &minVal, const SizeValue &val, const SizeValue &maxVal) -{ - SizeValue croppedVal = val; - if (minVal.width() > val.width()) - croppedVal.setWidth(minVal.width()); - else if (maxVal.width() < val.width()) - croppedVal.setWidth(maxVal.width()); - - if (minVal.height() > val.height()) - croppedVal.setHeight(minVal.height()); - else if (maxVal.height() < val.height()) - croppedVal.setHeight(maxVal.height()); - - return croppedVal; -} - -// Match the exact signature of qBound for VS 6. -QSize qBound(QSize minVal, QSize val, QSize maxVal) -{ - return qBoundSize(minVal, val, maxVal); -} - -QSizeF qBound(QSizeF minVal, QSizeF val, QSizeF maxVal) -{ - return qBoundSize(minVal, val, maxVal); -} - -namespace { - -namespace { -template -void orderBorders(Value &minVal, Value &maxVal) -{ - if (minVal > maxVal) - qSwap(minVal, maxVal); -} - -template -static void orderSizeBorders(Value &minVal, Value &maxVal) -{ - Value fromSize = minVal; - Value toSize = maxVal; - if (fromSize.width() > toSize.width()) { - fromSize.setWidth(maxVal.width()); - toSize.setWidth(minVal.width()); - } - if (fromSize.height() > toSize.height()) { - fromSize.setHeight(maxVal.height()); - toSize.setHeight(minVal.height()); - } - minVal = fromSize; - maxVal = toSize; -} - -void orderBorders(QSize &minVal, QSize &maxVal) -{ - orderSizeBorders(minVal, maxVal); -} - -void orderBorders(QSizeF &minVal, QSizeF &maxVal) -{ - orderSizeBorders(minVal, maxVal); -} - -} -} -//////// - -template -static Value getData(const QMap &propertyMap, - Value PrivateData::*data, - const QtProperty *property, const Value &defaultValue = Value()) -{ - typedef QMap PropertyToData; - typedef Q_TYPENAME PropertyToData::const_iterator PropertyToDataConstIterator; - const PropertyToDataConstIterator it = propertyMap.constFind(property); - if (it == propertyMap.constEnd()) - return defaultValue; - return it.value().*data; -} - -template -static Value getValue(const QMap &propertyMap, - const QtProperty *property, const Value &defaultValue = Value()) -{ - return getData(propertyMap, &PrivateData::val, property, defaultValue); -} - -template -static Value getMinimum(const QMap &propertyMap, - const QtProperty *property, const Value &defaultValue = Value()) -{ - return getData(propertyMap, &PrivateData::minVal, property, defaultValue); -} - -template -static Value getMaximum(const QMap &propertyMap, - const QtProperty *property, const Value &defaultValue = Value()) -{ - return getData(propertyMap, &PrivateData::maxVal, property, defaultValue); -} - -template -static void setSimpleValue(QMap &propertyMap, - PropertyManager *manager, - void (PropertyManager::*propertyChangedSignal)(QtProperty *), - void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter), - QtProperty *property, const Value &val) -{ - typedef QMap PropertyToData; - typedef Q_TYPENAME PropertyToData::iterator PropertyToDataIterator; - const PropertyToDataIterator it = propertyMap.find(property); - if (it == propertyMap.end()) - return; - - if (it.value() == val) - return; - - it.value() = val; - - emit (manager->*propertyChangedSignal)(property); - emit (manager->*valueChangedSignal)(property, val); -} - -template -static void setValueInRange(PropertyManager *manager, PropertyManagerPrivate *managerPrivate, - void (PropertyManager::*propertyChangedSignal)(QtProperty *), - void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter), - QtProperty *property, const Value &val, - void (PropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, ValueChangeParameter)) -{ - typedef Q_TYPENAME PropertyManagerPrivate::Data PrivateData; - typedef QMap PropertyToData; - typedef Q_TYPENAME PropertyToData::iterator PropertyToDataIterator; - const PropertyToDataIterator it = managerPrivate->m_values.find(property); - if (it == managerPrivate->m_values.end()) - return; - - PrivateData &data = it.value(); - - if (data.val == val) - return; - - const Value oldVal = data.val; - - data.val = qBound(data.minVal, val, data.maxVal); - - if (data.val == oldVal) - return; - - if (setSubPropertyValue) - (managerPrivate->*setSubPropertyValue)(property, data.val); - - emit (manager->*propertyChangedSignal)(property); - emit (manager->*valueChangedSignal)(property, data.val); -} - -template -static void setBorderValues(PropertyManager *manager, PropertyManagerPrivate *managerPrivate, - void (PropertyManager::*propertyChangedSignal)(QtProperty *), - void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter), - void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter), - QtProperty *property, const Value &minVal, const Value &maxVal, - void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, - ValueChangeParameter, ValueChangeParameter, ValueChangeParameter)) -{ - typedef Q_TYPENAME PropertyManagerPrivate::Data PrivateData; - typedef QMap PropertyToData; - typedef Q_TYPENAME PropertyToData::iterator PropertyToDataIterator; - const PropertyToDataIterator it = managerPrivate->m_values.find(property); - if (it == managerPrivate->m_values.end()) - return; - - Value fromVal = minVal; - Value toVal = maxVal; - orderBorders(fromVal, toVal); - - PrivateData &data = it.value(); - - if (data.minVal == fromVal && data.maxVal == toVal) - return; - - const Value oldVal = data.val; - - data.setMinimumValue(fromVal); - data.setMaximumValue(toVal); - - emit (manager->*rangeChangedSignal)(property, data.minVal, data.maxVal); - - if (setSubPropertyRange) - (managerPrivate->*setSubPropertyRange)(property, data.minVal, data.maxVal, data.val); - - if (data.val == oldVal) - return; - - emit (manager->*propertyChangedSignal)(property); - emit (manager->*valueChangedSignal)(property, data.val); -} - -template -static void setBorderValue(PropertyManager *manager, PropertyManagerPrivate *managerPrivate, - void (PropertyManager::*propertyChangedSignal)(QtProperty *), - void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter), - void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter), - QtProperty *property, - Value (PrivateData::*getRangeVal)() const, - void (PrivateData::*setRangeVal)(ValueChangeParameter), const Value &borderVal, - void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, - ValueChangeParameter, ValueChangeParameter, ValueChangeParameter)) -{ - typedef QMap PropertyToData; - typedef Q_TYPENAME PropertyToData::iterator PropertyToDataIterator; - const PropertyToDataIterator it = managerPrivate->m_values.find(property); - if (it == managerPrivate->m_values.end()) - return; - - PrivateData &data = it.value(); - - if ((data.*getRangeVal)() == borderVal) - return; - - const Value oldVal = data.val; - - (data.*setRangeVal)(borderVal); - - emit (manager->*rangeChangedSignal)(property, data.minVal, data.maxVal); - - if (setSubPropertyRange) - (managerPrivate->*setSubPropertyRange)(property, data.minVal, data.maxVal, data.val); - - if (data.val == oldVal) - return; - - emit (manager->*propertyChangedSignal)(property); - emit (manager->*valueChangedSignal)(property, data.val); -} - -template -static void setMinimumValue(PropertyManager *manager, PropertyManagerPrivate *managerPrivate, - void (PropertyManager::*propertyChangedSignal)(QtProperty *), - void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter), - void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter), - QtProperty *property, const Value &minVal) -{ - void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, - ValueChangeParameter, ValueChangeParameter, ValueChangeParameter) = 0; - setBorderValue(manager, managerPrivate, - propertyChangedSignal, valueChangedSignal, rangeChangedSignal, - property, &PropertyManagerPrivate::Data::minimumValue, &PropertyManagerPrivate::Data::setMinimumValue, minVal, setSubPropertyRange); -} - -template -static void setMaximumValue(PropertyManager *manager, PropertyManagerPrivate *managerPrivate, - void (PropertyManager::*propertyChangedSignal)(QtProperty *), - void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter), - void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter), - QtProperty *property, const Value &maxVal) -{ - void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, - ValueChangeParameter, ValueChangeParameter, ValueChangeParameter) = 0; - setBorderValue(manager, managerPrivate, - propertyChangedSignal, valueChangedSignal, rangeChangedSignal, - property, &PropertyManagerPrivate::Data::maximumValue, &PropertyManagerPrivate::Data::setMaximumValue, maxVal, setSubPropertyRange); -} - -class QtMetaEnumWrapper : public QObject -{ - Q_OBJECT - Q_PROPERTY(QSizePolicy::Policy policy READ policy) -public: - QSizePolicy::Policy policy() const { return QSizePolicy::Ignored; } -private: - QtMetaEnumWrapper(QObject *parent) : QObject(parent) {} -}; - -class QtMetaEnumProvider -{ -public: - QtMetaEnumProvider(); - - QStringList policyEnumNames() const { return m_policyEnumNames; } - QStringList languageEnumNames() const { return m_languageEnumNames; } - QStringList countryEnumNames(QLocale::Language language) const { return m_countryEnumNames.value(language); } - - QSizePolicy::Policy indexToSizePolicy(int index) const; - int sizePolicyToIndex(QSizePolicy::Policy policy) const; - - void indexToLocale(int languageIndex, int countryIndex, QLocale::Language *language, QLocale::Country *country) const; - void localeToIndex(QLocale::Language language, QLocale::Country country, int *languageIndex, int *countryIndex) const; - -private: - void initLocale(); - - QStringList m_policyEnumNames; - QStringList m_languageEnumNames; - QMap m_countryEnumNames; - QMap m_indexToLanguage; - QMap m_languageToIndex; - QMap > m_indexToCountry; - QMap > m_countryToIndex; - QMetaEnum m_policyEnum; -}; - -#if QT_VERSION < 0x040300 - -static QList countriesForLanguage(QLocale::Language language) -{ - QList countries; - QLocale::Country country = QLocale::AnyCountry; - while (country <= QLocale::LastCountry) { - QLocale locale(language, country); - if (locale.language() == language && !countries.contains(locale.country())) - countries << locale.country(); - country = (QLocale::Country)((uint)country + 1); // ++country - } - return countries; -} - -#endif - -static QList sortCountries(const QList &countries) -{ - QMultiMap nameToCountry; - QListIterator itCountry(countries); - while (itCountry.hasNext()) { - QLocale::Country country = itCountry.next(); - nameToCountry.insert(QLocale::countryToString(country), country); - } - return nameToCountry.values(); -} - -void QtMetaEnumProvider::initLocale() -{ - QMultiMap nameToLanguage; - QLocale::Language language = QLocale::C; - while (language <= QLocale::LastLanguage) { - QLocale locale(language); - if (locale.language() == language) - nameToLanguage.insert(QLocale::languageToString(language), language); - language = (QLocale::Language)((uint)language + 1); // ++language - } - - const QLocale system = QLocale::system(); - if (!nameToLanguage.contains(QLocale::languageToString(system.language()))) - nameToLanguage.insert(QLocale::languageToString(system.language()), system.language()); - - QList languages = nameToLanguage.values(); - QListIterator itLang(languages); - while (itLang.hasNext()) { - QLocale::Language language = itLang.next(); - QList countries; -#if QT_VERSION < 0x040300 - countries = countriesForLanguage(language); -#else - countries = QLocale::countriesForLanguage(language); -#endif - if (countries.isEmpty() && language == system.language()) - countries << system.country(); - - if (!countries.isEmpty() && !m_languageToIndex.contains(language)) { - countries = sortCountries(countries); - int langIdx = m_languageEnumNames.count(); - m_indexToLanguage[langIdx] = language; - m_languageToIndex[language] = langIdx; - QStringList countryNames; - QListIterator it(countries); - int countryIdx = 0; - while (it.hasNext()) { - QLocale::Country country = it.next(); - countryNames << QLocale::countryToString(country); - m_indexToCountry[langIdx][countryIdx] = country; - m_countryToIndex[language][country] = countryIdx; - ++countryIdx; - } - m_languageEnumNames << QLocale::languageToString(language); - m_countryEnumNames[language] = countryNames; - } - } -} - -QtMetaEnumProvider::QtMetaEnumProvider() -{ - QMetaProperty p; - - p = QtMetaEnumWrapper::staticMetaObject.property( - QtMetaEnumWrapper::staticMetaObject.propertyOffset() + 0); - m_policyEnum = p.enumerator(); - const int keyCount = m_policyEnum.keyCount(); - for (int i = 0; i < keyCount; i++) - m_policyEnumNames << QLatin1String(m_policyEnum.key(i)); - - initLocale(); -} - -QSizePolicy::Policy QtMetaEnumProvider::indexToSizePolicy(int index) const -{ - return static_cast(m_policyEnum.value(index)); -} - -int QtMetaEnumProvider::sizePolicyToIndex(QSizePolicy::Policy policy) const -{ - const int keyCount = m_policyEnum.keyCount(); - for (int i = 0; i < keyCount; i++) - if (indexToSizePolicy(i) == policy) - return i; - return -1; -} - -void QtMetaEnumProvider::indexToLocale(int languageIndex, int countryIndex, QLocale::Language *language, QLocale::Country *country) const -{ - QLocale::Language l = QLocale::C; - QLocale::Country c = QLocale::AnyCountry; - if (m_indexToLanguage.contains(languageIndex)) { - l = m_indexToLanguage[languageIndex]; - if (m_indexToCountry.contains(languageIndex) && m_indexToCountry[languageIndex].contains(countryIndex)) - c = m_indexToCountry[languageIndex][countryIndex]; - } - if (language) - *language = l; - if (country) - *country = c; -} - -void QtMetaEnumProvider::localeToIndex(QLocale::Language language, QLocale::Country country, int *languageIndex, int *countryIndex) const -{ - int l = -1; - int c = -1; - if (m_languageToIndex.contains(language)) { - l = m_languageToIndex[language]; - if (m_countryToIndex.contains(language) && m_countryToIndex[language].contains(country)) - c = m_countryToIndex[language][country]; - } - - if (languageIndex) - *languageIndex = l; - if (countryIndex) - *countryIndex = c; -} - -Q_GLOBAL_STATIC(QtMetaEnumProvider, metaEnumProvider) - -// QtGroupPropertyManager - -/*! - \class QtGroupPropertyManager - - \brief The QtGroupPropertyManager provides and manages group properties. - - This class is intended to provide a grouping element without any value. - - \sa QtAbstractPropertyManager -*/ - -/*! - Creates a manager with the given \a parent. -*/ -QtGroupPropertyManager::QtGroupPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) -{ - -} - -/*! - Destroys this manager, and all the properties it has created. -*/ -QtGroupPropertyManager::~QtGroupPropertyManager() -{ - -} - -/*! - \reimp -*/ -bool QtGroupPropertyManager::hasValue(const QtProperty *property) const -{ - Q_UNUSED(property) - return false; -} - -/*! - \reimp -*/ -void QtGroupPropertyManager::initializeProperty(QtProperty *property) -{ - Q_UNUSED(property) -} - -/*! - \reimp -*/ -void QtGroupPropertyManager::uninitializeProperty(QtProperty *property) -{ - Q_UNUSED(property) -} - -// QtIntPropertyManager - -class QtIntPropertyManagerPrivate -{ - QtIntPropertyManager *q_ptr; - Q_DECLARE_PUBLIC(QtIntPropertyManager) -public: - - struct Data - { - Data() : val(0), minVal(-INT_MAX), maxVal(INT_MAX), singleStep(1) {} - int val; - int minVal; - int maxVal; - int singleStep; - int minimumValue() const { return minVal; } - int maximumValue() const { return maxVal; } - void setMinimumValue(int newMinVal) { setSimpleMinimumData(this, newMinVal); } - void setMaximumValue(int newMaxVal) { setSimpleMaximumData(this, newMaxVal); } - }; - - typedef QMap PropertyValueMap; - PropertyValueMap m_values; -}; - -/*! - \class QtIntPropertyManager - - \brief The QtIntPropertyManager provides and manages int properties. - - An int property has a current value, and a range specifying the - valid values. The range is defined by a minimum and a maximum - value. - - The property's value and range can be retrieved using the value(), - minimum() and maximum() functions, and can be set using the - setValue(), setMinimum() and setMaximum() slots. Alternatively, - the range can be defined in one go using the setRange() slot. - - In addition, QtIntPropertyManager provides the valueChanged() signal which - is emitted whenever a property created by this manager changes, - and the rangeChanged() signal which is emitted whenever such a - property changes its range of valid values. - - \sa QtAbstractPropertyManager, QtSpinBoxFactory, QtSliderFactory, QtScrollBarFactory -*/ - -/*! - \fn void QtIntPropertyManager::valueChanged(QtProperty *property, int value) - - This signal is emitted whenever a property created by this manager - changes its value, passing a pointer to the \a property and the new - \a value as parameters. - - \sa setValue() -*/ - -/*! - \fn void QtIntPropertyManager::rangeChanged(QtProperty *property, int minimum, int maximum) - - This signal is emitted whenever a property created by this manager - changes its range of valid values, passing a pointer to the - \a property and the new \a minimum and \a maximum values. - - \sa setRange() -*/ - -/*! - \fn void QtIntPropertyManager::singleStepChanged(QtProperty *property, int step) - - This signal is emitted whenever a property created by this manager - changes its single step property, passing a pointer to the - \a property and the new \a step value - - \sa setSingleStep() -*/ - -/*! - Creates a manager with the given \a parent. -*/ -QtIntPropertyManager::QtIntPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) -{ - d_ptr = new QtIntPropertyManagerPrivate; - d_ptr->q_ptr = this; -} - -/*! - Destroys this manager, and all the properties it has created. -*/ -QtIntPropertyManager::~QtIntPropertyManager() -{ - clear(); - delete d_ptr; -} - -/*! - Returns the given \a property's value. - - If the given property is not managed by this manager, this - function returns 0. - - \sa setValue() -*/ -int QtIntPropertyManager::value(const QtProperty *property) const -{ - return getValue(d_ptr->m_values, property, 0); -} - -/*! - Returns the given \a property's minimum value. - - \sa setMinimum(), maximum(), setRange() -*/ -int QtIntPropertyManager::minimum(const QtProperty *property) const -{ - return getMinimum(d_ptr->m_values, property, 0); -} - -/*! - Returns the given \a property's maximum value. - - \sa setMaximum(), minimum(), setRange() -*/ -int QtIntPropertyManager::maximum(const QtProperty *property) const -{ - return getMaximum(d_ptr->m_values, property, 0); -} - -/*! - Returns the given \a property's step value. - - The step is typically used to increment or decrement a property value while pressing an arrow key. - - \sa setSingleStep() -*/ -int QtIntPropertyManager::singleStep(const QtProperty *property) const -{ - return getData(d_ptr->m_values, &QtIntPropertyManagerPrivate::Data::singleStep, property, 0); -} - -/*! - \reimp -*/ -QString QtIntPropertyManager::valueText(const QtProperty *property) const -{ - const QtIntPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QString(); - return QString::number(it.value().val); -} - -/*! - \fn void QtIntPropertyManager::setValue(QtProperty *property, int value) - - Sets the value of the given \a property to \a value. - - If the specified \a value is not valid according to the given \a - property's range, the \a value is adjusted to the nearest valid - value within the range. - - \sa value(), setRange(), valueChanged() -*/ -void QtIntPropertyManager::setValue(QtProperty *property, int val) -{ - void (QtIntPropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, int) = 0; - setValueInRange(this, d_ptr, - &QtIntPropertyManager::propertyChanged, - &QtIntPropertyManager::valueChanged, - property, val, setSubPropertyValue); -} - -/*! - Sets the minimum value for the given \a property to \a minVal. - - When setting the minimum value, the maximum and current values are - adjusted if necessary (ensuring that the range remains valid and - that the current value is within the range). - - \sa minimum(), setRange(), rangeChanged() -*/ -void QtIntPropertyManager::setMinimum(QtProperty *property, int minVal) -{ - setMinimumValue(this, d_ptr, - &QtIntPropertyManager::propertyChanged, - &QtIntPropertyManager::valueChanged, - &QtIntPropertyManager::rangeChanged, - property, minVal); -} - -/*! - Sets the maximum value for the given \a property to \a maxVal. - - When setting maximum value, the minimum and current values are - adjusted if necessary (ensuring that the range remains valid and - that the current value is within the range). - - \sa maximum(), setRange(), rangeChanged() -*/ -void QtIntPropertyManager::setMaximum(QtProperty *property, int maxVal) -{ - setMaximumValue(this, d_ptr, - &QtIntPropertyManager::propertyChanged, - &QtIntPropertyManager::valueChanged, - &QtIntPropertyManager::rangeChanged, - property, maxVal); -} - -/*! - \fn void QtIntPropertyManager::setRange(QtProperty *property, int minimum, int maximum) - - Sets the range of valid values. - - This is a convenience function defining the range of valid values - in one go; setting the \a minimum and \a maximum values for the - given \a property with a single function call. - - When setting a new range, the current value is adjusted if - necessary (ensuring that the value remains within range). - - \sa setMinimum(), setMaximum(), rangeChanged() -*/ -void QtIntPropertyManager::setRange(QtProperty *property, int minVal, int maxVal) -{ - void (QtIntPropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, int, int, int) = 0; - setBorderValues(this, d_ptr, - &QtIntPropertyManager::propertyChanged, - &QtIntPropertyManager::valueChanged, - &QtIntPropertyManager::rangeChanged, - property, minVal, maxVal, setSubPropertyRange); -} - -/*! - Sets the step value for the given \a property to \a step. - - The step is typically used to increment or decrement a property value while pressing an arrow key. - - \sa singleStep() -*/ -void QtIntPropertyManager::setSingleStep(QtProperty *property, int step) -{ - const QtIntPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); - if (it == d_ptr->m_values.end()) - return; - - QtIntPropertyManagerPrivate::Data data = it.value(); - - if (step < 0) - step = 0; - - if (data.singleStep == step) - return; - - data.singleStep = step; - - it.value() = data; - - emit singleStepChanged(property, data.singleStep); -} - -/*! - \reimp -*/ -void QtIntPropertyManager::initializeProperty(QtProperty *property) -{ - d_ptr->m_values[property] = QtIntPropertyManagerPrivate::Data(); -} - -/*! - \reimp -*/ -void QtIntPropertyManager::uninitializeProperty(QtProperty *property) -{ - d_ptr->m_values.remove(property); -} - -// QtDoublePropertyManager - -class QtDoublePropertyManagerPrivate -{ - QtDoublePropertyManager *q_ptr; - Q_DECLARE_PUBLIC(QtDoublePropertyManager) -public: - - struct Data - { - Data() : val(0), minVal(-INT_MAX), maxVal(INT_MAX), singleStep(1), decimals(2) {} - double val; - double minVal; - double maxVal; - double singleStep; - int decimals; - double minimumValue() const { return minVal; } - double maximumValue() const { return maxVal; } - void setMinimumValue(double newMinVal) { setSimpleMinimumData(this, newMinVal); } - void setMaximumValue(double newMaxVal) { setSimpleMaximumData(this, newMaxVal); } - }; - - typedef QMap PropertyValueMap; - PropertyValueMap m_values; -}; - -/*! - \class QtDoublePropertyManager - - \brief The QtDoublePropertyManager provides and manages double properties. - - A double property has a current value, and a range specifying the - valid values. The range is defined by a minimum and a maximum - value. - - The property's value and range can be retrieved using the value(), - minimum() and maximum() functions, and can be set using the - setValue(), setMinimum() and setMaximum() slots. - Alternatively, the range can be defined in one go using the - setRange() slot. - - In addition, QtDoublePropertyManager provides the valueChanged() signal - which is emitted whenever a property created by this manager - changes, and the rangeChanged() signal which is emitted whenever - such a property changes its range of valid values. - - \sa QtAbstractPropertyManager, QtDoubleSpinBoxFactory -*/ - -/*! - \fn void QtDoublePropertyManager::valueChanged(QtProperty *property, double value) - - This signal is emitted whenever a property created by this manager - changes its value, passing a pointer to the \a property and the new - \a value as parameters. - - \sa setValue() -*/ - -/*! - \fn void QtDoublePropertyManager::rangeChanged(QtProperty *property, double minimum, double maximum) - - This signal is emitted whenever a property created by this manager - changes its range of valid values, passing a pointer to the - \a property and the new \a minimum and \a maximum values - - \sa setRange() -*/ - -/*! - \fn void QtDoublePropertyManager::decimalsChanged(QtProperty *property, int prec) - - This signal is emitted whenever a property created by this manager - changes its precision of value, passing a pointer to the - \a property and the new \a prec value - - \sa setDecimals() -*/ - -/*! - \fn void QtDoublePropertyManager::singleStepChanged(QtProperty *property, double step) - - This signal is emitted whenever a property created by this manager - changes its single step property, passing a pointer to the - \a property and the new \a step value - - \sa setSingleStep() -*/ - -/*! - Creates a manager with the given \a parent. -*/ -QtDoublePropertyManager::QtDoublePropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) -{ - d_ptr = new QtDoublePropertyManagerPrivate; - d_ptr->q_ptr = this; -} - -/*! - Destroys this manager, and all the properties it has created. -*/ -QtDoublePropertyManager::~QtDoublePropertyManager() -{ - clear(); - delete d_ptr; -} - -/*! - Returns the given \a property's value. - - If the given property is not managed by this manager, this - function returns 0. - - \sa setValue() -*/ -double QtDoublePropertyManager::value(const QtProperty *property) const -{ - return getValue(d_ptr->m_values, property, 0.0); -} - -/*! - Returns the given \a property's minimum value. - - \sa maximum(), setRange() -*/ -double QtDoublePropertyManager::minimum(const QtProperty *property) const -{ - return getMinimum(d_ptr->m_values, property, 0.0); -} - -/*! - Returns the given \a property's maximum value. - - \sa minimum(), setRange() -*/ -double QtDoublePropertyManager::maximum(const QtProperty *property) const -{ - return getMaximum(d_ptr->m_values, property, 0.0); -} - -/*! - Returns the given \a property's step value. - - The step is typically used to increment or decrement a property value while pressing an arrow key. - - \sa setSingleStep() -*/ -double QtDoublePropertyManager::singleStep(const QtProperty *property) const -{ - return getData(d_ptr->m_values, &QtDoublePropertyManagerPrivate::Data::singleStep, property, 0); -} - -/*! - Returns the given \a property's precision, in decimals. - - \sa setDecimals() -*/ -int QtDoublePropertyManager::decimals(const QtProperty *property) const -{ - return getData(d_ptr->m_values, &QtDoublePropertyManagerPrivate::Data::decimals, property, 0); -} - -/*! - \reimp -*/ -QString QtDoublePropertyManager::valueText(const QtProperty *property) const -{ - const QtDoublePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QString(); - - // Original code - //return QString::number(it.value().val, 'f', it.value().decimals); - - // Use default constructor to use locale defined as default locale - QLocale myLocale; - - // Taken from QString QDoubleSpinBox::textFromValue(double value) const - QString str = myLocale.toString(it.value().val, 'f', it.value().decimals); - if (qAbs(it.value().val) >= 1000.0) { - str.remove(myLocale.groupSeparator()); - } - - return str; -} - -/*! - \fn void QtDoublePropertyManager::setValue(QtProperty *property, double value) - - Sets the value of the given \a property to \a value. - - If the specified \a value is not valid according to the given - \a property's range, the \a value is adjusted to the nearest valid value - within the range. - - \sa value(), setRange(), valueChanged() -*/ -void QtDoublePropertyManager::setValue(QtProperty *property, double val) -{ - void (QtDoublePropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, double) = 0; - setValueInRange(this, d_ptr, - &QtDoublePropertyManager::propertyChanged, - &QtDoublePropertyManager::valueChanged, - property, val, setSubPropertyValue); -} - -/*! - Sets the step value for the given \a property to \a step. - - The step is typically used to increment or decrement a property value while pressing an arrow key. - - \sa singleStep() -*/ -void QtDoublePropertyManager::setSingleStep(QtProperty *property, double step) -{ - const QtDoublePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); - if (it == d_ptr->m_values.end()) - return; - - QtDoublePropertyManagerPrivate::Data data = it.value(); - - if (step < 0) - step = 0; - - if (data.singleStep == step) - return; - - data.singleStep = step; - - it.value() = data; - - emit singleStepChanged(property, data.singleStep); -} - -/*! - \fn void QtDoublePropertyManager::setDecimals(QtProperty *property, int prec) - - Sets the precision of the given \a property to \a prec. - - The valid decimal range is 0-13. The default is 2. - - \sa decimals() -*/ -void QtDoublePropertyManager::setDecimals(QtProperty *property, int prec) -{ - const QtDoublePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); - if (it == d_ptr->m_values.end()) - return; - - QtDoublePropertyManagerPrivate::Data data = it.value(); - - if (prec > 13) - prec = 13; - else if (prec < 0) - prec = 0; - - if (data.decimals == prec) - return; - - data.decimals = prec; - - it.value() = data; - - emit decimalsChanged(property, data.decimals); -} - -/*! - Sets the minimum value for the given \a property to \a minVal. - - When setting the minimum value, the maximum and current values are - adjusted if necessary (ensuring that the range remains valid and - that the current value is within in the range). - - \sa minimum(), setRange(), rangeChanged() -*/ -void QtDoublePropertyManager::setMinimum(QtProperty *property, double minVal) -{ - setMinimumValue(this, d_ptr, - &QtDoublePropertyManager::propertyChanged, - &QtDoublePropertyManager::valueChanged, - &QtDoublePropertyManager::rangeChanged, - property, minVal); -} - -/*! - Sets the maximum value for the given \a property to \a maxVal. - - When setting the maximum value, the minimum and current values are - adjusted if necessary (ensuring that the range remains valid and - that the current value is within in the range). - - \sa maximum(), setRange(), rangeChanged() -*/ -void QtDoublePropertyManager::setMaximum(QtProperty *property, double maxVal) -{ - setMaximumValue(this, d_ptr, - &QtDoublePropertyManager::propertyChanged, - &QtDoublePropertyManager::valueChanged, - &QtDoublePropertyManager::rangeChanged, - property, maxVal); -} - -/*! - \fn void QtDoublePropertyManager::setRange(QtProperty *property, double minimum, double maximum) - - Sets the range of valid values. - - This is a convenience function defining the range of valid values - in one go; setting the \a minimum and \a maximum values for the - given \a property with a single function call. - - When setting a new range, the current value is adjusted if - necessary (ensuring that the value remains within range). - - \sa setMinimum(), setMaximum(), rangeChanged() -*/ -void QtDoublePropertyManager::setRange(QtProperty *property, double minVal, double maxVal) -{ - void (QtDoublePropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, double, double, double) = 0; - setBorderValues(this, d_ptr, - &QtDoublePropertyManager::propertyChanged, - &QtDoublePropertyManager::valueChanged, - &QtDoublePropertyManager::rangeChanged, - property, minVal, maxVal, setSubPropertyRange); -} - -/*! - \reimp -*/ -void QtDoublePropertyManager::initializeProperty(QtProperty *property) -{ - d_ptr->m_values[property] = QtDoublePropertyManagerPrivate::Data(); -} - -/*! - \reimp -*/ -void QtDoublePropertyManager::uninitializeProperty(QtProperty *property) -{ - d_ptr->m_values.remove(property); -} - -// QtStringPropertyManager - -class QtStringPropertyManagerPrivate -{ - QtStringPropertyManager *q_ptr; - Q_DECLARE_PUBLIC(QtStringPropertyManager) -public: - - struct Data - { - Data() : regExp(QString(QLatin1Char('*')), Qt::CaseSensitive, QRegExp::Wildcard) - { - } - QString val; - QRegExp regExp; - }; - - typedef QMap PropertyValueMap; - QMap m_values; -}; - -/*! - \class QtStringPropertyManager - - \brief The QtStringPropertyManager provides and manages QString properties. - - A string property's value can be retrieved using the value() - function, and set using the setValue() slot. - - The current value can be checked against a regular expression. To - set the regular expression use the setRegExp() slot, use the - regExp() function to retrieve the currently set expression. - - In addition, QtStringPropertyManager provides the valueChanged() signal - which is emitted whenever a property created by this manager - changes, and the regExpChanged() signal which is emitted whenever - such a property changes its currently set regular expression. - - \sa QtAbstractPropertyManager, QtLineEditFactory -*/ - -/*! - \fn void QtStringPropertyManager::valueChanged(QtProperty *property, const QString &value) - - This signal is emitted whenever a property created by this manager - changes its value, passing a pointer to the \a property and the - new \a value as parameters. - - \sa setValue() -*/ - -/*! - \fn void QtStringPropertyManager::regExpChanged(QtProperty *property, const QRegExp ®Exp) - - This signal is emitted whenever a property created by this manager - changes its currenlty set regular expression, passing a pointer to - the \a property and the new \a regExp as parameters. - - \sa setRegExp() -*/ - -/*! - Creates a manager with the given \a parent. -*/ -QtStringPropertyManager::QtStringPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) -{ - d_ptr = new QtStringPropertyManagerPrivate; - d_ptr->q_ptr = this; -} - -/*! - Destroys this manager, and all the properties it has created. -*/ -QtStringPropertyManager::~QtStringPropertyManager() -{ - clear(); - delete d_ptr; -} - -/*! - Returns the given \a property's value. - - If the given property is not managed by this manager, this - function returns an empty string. - - \sa setValue() -*/ -QString QtStringPropertyManager::value(const QtProperty *property) const -{ - return getValue(d_ptr->m_values, property); -} - -/*! - Returns the given \a property's currently set regular expression. - - If the given \a property is not managed by this manager, this - function returns an empty expression. - - \sa setRegExp() -*/ -QRegExp QtStringPropertyManager::regExp(const QtProperty *property) const -{ - return getData(d_ptr->m_values, &QtStringPropertyManagerPrivate::Data::regExp, property, QRegExp()); -} - -/*! - \reimp -*/ -QString QtStringPropertyManager::valueText(const QtProperty *property) const -{ - const QtStringPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QString(); - return it.value().val; -} - -/*! - \fn void QtStringPropertyManager::setValue(QtProperty *property, const QString &value) - - Sets the value of the given \a property to \a value. - - If the specified \a value doesn't match the given \a property's - regular expression, this function does nothing. - - \sa value(), setRegExp(), valueChanged() -*/ -void QtStringPropertyManager::setValue(QtProperty *property, const QString &val) -{ - const QtStringPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); - if (it == d_ptr->m_values.end()) - return; - - QtStringPropertyManagerPrivate::Data data = it.value(); - - if (data.val == val) - return; - - if (data.regExp.isValid() && !data.regExp.exactMatch(val)) - return; - - data.val = val; - - it.value() = data; - - emit propertyChanged(property); - emit valueChanged(property, data.val); -} - -/*! - Sets the regular expression of the given \a property to \a regExp. - - \sa regExp(), setValue(), regExpChanged() -*/ -void QtStringPropertyManager::setRegExp(QtProperty *property, const QRegExp ®Exp) -{ - const QtStringPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); - if (it == d_ptr->m_values.end()) - return; - - QtStringPropertyManagerPrivate::Data data = it.value() ; - - if (data.regExp == regExp) - return; - - data.regExp = regExp; - - it.value() = data; - - emit regExpChanged(property, data.regExp); -} - -/*! - \reimp -*/ -void QtStringPropertyManager::initializeProperty(QtProperty *property) -{ - d_ptr->m_values[property] = QtStringPropertyManagerPrivate::Data(); -} - -/*! - \reimp -*/ -void QtStringPropertyManager::uninitializeProperty(QtProperty *property) -{ - d_ptr->m_values.remove(property); -} - -// QtBoolPropertyManager - -class QtBoolPropertyManagerPrivate -{ - QtBoolPropertyManager *q_ptr; - Q_DECLARE_PUBLIC(QtBoolPropertyManager) -public: - - QMap m_values; -}; - -/*! - \class QtBoolPropertyManager - - \brief The QtBoolPropertyManager class provides and manages boolean properties. - - The property's value can be retrieved using the value() function, - and set using the setValue() slot. - - In addition, QtBoolPropertyManager provides the valueChanged() signal - which is emitted whenever a property created by this manager - changes. - - \sa QtAbstractPropertyManager, QtCheckBoxFactory -*/ - -/*! - \fn void QtBoolPropertyManager::valueChanged(QtProperty *property, bool value) - - This signal is emitted whenever a property created by this manager - changes its value, passing a pointer to the \a property and the - new \a value as parameters. -*/ - -/*! - Creates a manager with the given \a parent. -*/ -QtBoolPropertyManager::QtBoolPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) -{ - d_ptr = new QtBoolPropertyManagerPrivate; - d_ptr->q_ptr = this; -} - -/*! - Destroys this manager, and all the properties it has created. -*/ -QtBoolPropertyManager::~QtBoolPropertyManager() -{ - clear(); - delete d_ptr; -} - -/*! - Returns the given \a property's value. - - If the given \a property is not managed by \e this manager, this - function returns false. - - \sa setValue() -*/ -bool QtBoolPropertyManager::value(const QtProperty *property) const -{ - return d_ptr->m_values.value(property, false); -} - -/*! - \reimp -*/ -QString QtBoolPropertyManager::valueText(const QtProperty *property) const -{ - const QMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QString(); - - static const QString trueText = tr("True"); - static const QString falseText = tr("False"); - return it.value() ? trueText : falseText; -} - -// Return an icon containing a check box indicator -static QIcon drawCheckBox(bool value) -{ - QStyleOptionButton opt; - opt.state |= value ? QStyle::State_On : QStyle::State_Off; - opt.state |= QStyle::State_Enabled; - const QStyle *style = QApplication::style(); - // Figure out size of an indicator and make sure it is not scaled down in a list view item - // by making the pixmap as big as a list view icon and centering the indicator in it. - // (if it is smaller, it can't be helped) - const int indicatorWidth = style->pixelMetric(QStyle::PM_IndicatorWidth, &opt); - const int indicatorHeight = style->pixelMetric(QStyle::PM_IndicatorHeight, &opt); - const int listViewIconSize = indicatorWidth; - const int pixmapWidth = indicatorWidth; - const int pixmapHeight = qMax(indicatorHeight, listViewIconSize); - - opt.rect = QRect(0, 0, indicatorWidth, indicatorHeight); - QPixmap pixmap = QPixmap(pixmapWidth, pixmapHeight); - pixmap.fill(Qt::transparent); - { - // Center? - const int xoff = (pixmapWidth > indicatorWidth) ? (pixmapWidth - indicatorWidth) / 2 : 0; - const int yoff = (pixmapHeight > indicatorHeight) ? (pixmapHeight - indicatorHeight) / 2 : 0; - QPainter painter(&pixmap); - painter.translate(xoff, yoff); - style->drawPrimitive(QStyle::PE_IndicatorCheckBox, &opt, &painter); - } - return QIcon(pixmap); -} - -/*! - \reimp -*/ -QIcon QtBoolPropertyManager::valueIcon(const QtProperty *property) const -{ - const QMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QIcon(); - - static const QIcon checkedIcon = drawCheckBox(true); - static const QIcon uncheckedIcon = drawCheckBox(false); - return it.value() ? checkedIcon : uncheckedIcon; -} - -/*! - \fn void QtBoolPropertyManager::setValue(QtProperty *property, bool value) - - Sets the value of the given \a property to \a value. - - \sa value() -*/ -void QtBoolPropertyManager::setValue(QtProperty *property, bool val) -{ - setSimpleValue(d_ptr->m_values, this, - &QtBoolPropertyManager::propertyChanged, - &QtBoolPropertyManager::valueChanged, - property, val); -} - -/*! - \reimp -*/ -void QtBoolPropertyManager::initializeProperty(QtProperty *property) -{ - d_ptr->m_values[property] = false; -} - -/*! - \reimp -*/ -void QtBoolPropertyManager::uninitializeProperty(QtProperty *property) -{ - d_ptr->m_values.remove(property); -} - -// QtDatePropertyManager - -class QtDatePropertyManagerPrivate -{ - QtDatePropertyManager *q_ptr; - Q_DECLARE_PUBLIC(QtDatePropertyManager) -public: - - struct Data - { - Data() : val(QDate::currentDate()), minVal(QDate(1752, 9, 14)), - maxVal(QDate(7999, 12, 31)) {} - QDate val; - QDate minVal; - QDate maxVal; - QDate minimumValue() const { return minVal; } - QDate maximumValue() const { return maxVal; } - void setMinimumValue(const QDate &newMinVal) { setSimpleMinimumData(this, newMinVal); } - void setMaximumValue(const QDate &newMaxVal) { setSimpleMaximumData(this, newMaxVal); } - }; - - QString m_format; - - typedef QMap PropertyValueMap; - QMap m_values; -}; - -/*! - \class QtDatePropertyManager - - \brief The QtDatePropertyManager provides and manages QDate properties. - - A date property has a current value, and a range specifying the - valid dates. The range is defined by a minimum and a maximum - value. - - The property's values can be retrieved using the minimum(), - maximum() and value() functions, and can be set using the - setMinimum(), setMaximum() and setValue() slots. Alternatively, - the range can be defined in one go using the setRange() slot. - - In addition, QtDatePropertyManager provides the valueChanged() signal - which is emitted whenever a property created by this manager - changes, and the rangeChanged() signal which is emitted whenever - such a property changes its range of valid dates. - - \sa QtAbstractPropertyManager, QtDateEditFactory, QtDateTimePropertyManager -*/ - -/*! - \fn void QtDatePropertyManager::valueChanged(QtProperty *property, const QDate &value) - - This signal is emitted whenever a property created by this manager - changes its value, passing a pointer to the \a property and the new - \a value as parameters. - - \sa setValue() -*/ - -/*! - \fn void QtDatePropertyManager::rangeChanged(QtProperty *property, const QDate &minimum, const QDate &maximum) - - This signal is emitted whenever a property created by this manager - changes its range of valid dates, passing a pointer to the \a - property and the new \a minimum and \a maximum dates. - - \sa setRange() -*/ - -/*! - Creates a manager with the given \a parent. -*/ -QtDatePropertyManager::QtDatePropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) -{ - d_ptr = new QtDatePropertyManagerPrivate; - d_ptr->q_ptr = this; - - QLocale loc; - d_ptr->m_format = loc.dateFormat(QLocale::ShortFormat); -} - -/*! - Destroys this manager, and all the properties it has created. -*/ -QtDatePropertyManager::~QtDatePropertyManager() -{ - clear(); - delete d_ptr; -} - -/*! - Returns the given \a property's value. - - If the given \a property is not managed by \e this manager, this - function returns an invalid date. - - \sa setValue() -*/ -QDate QtDatePropertyManager::value(const QtProperty *property) const -{ - return getValue(d_ptr->m_values, property); -} - -/*! - Returns the given \a property's minimum date. - - \sa maximum(), setRange() -*/ -QDate QtDatePropertyManager::minimum(const QtProperty *property) const -{ - return getMinimum(d_ptr->m_values, property); -} - -/*! - Returns the given \a property's maximum date. - - \sa minimum(), setRange() -*/ -QDate QtDatePropertyManager::maximum(const QtProperty *property) const -{ - return getMaximum(d_ptr->m_values, property); -} - -/*! - \reimp -*/ -QString QtDatePropertyManager::valueText(const QtProperty *property) const -{ - const QtDatePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QString(); - return it.value().val.toString(d_ptr->m_format); -} - -/*! - \fn void QtDatePropertyManager::setValue(QtProperty *property, const QDate &value) - - Sets the value of the given \a property to \a value. - - If the specified \a value is not a valid date according to the - given \a property's range, the value is adjusted to the nearest - valid value within the range. - - \sa value(), setRange(), valueChanged() -*/ -void QtDatePropertyManager::setValue(QtProperty *property, const QDate &val) -{ - void (QtDatePropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, const QDate &) = 0; - setValueInRange(this, d_ptr, - &QtDatePropertyManager::propertyChanged, - &QtDatePropertyManager::valueChanged, - property, val, setSubPropertyValue); -} - -/*! - Sets the minimum value for the given \a property to \a minVal. - - When setting the minimum value, the maximum and current values are - adjusted if necessary (ensuring that the range remains valid and - that the current value is within in the range). - - \sa minimum(), setRange() -*/ -void QtDatePropertyManager::setMinimum(QtProperty *property, const QDate &minVal) -{ - setMinimumValue(this, d_ptr, - &QtDatePropertyManager::propertyChanged, - &QtDatePropertyManager::valueChanged, - &QtDatePropertyManager::rangeChanged, - property, minVal); -} - -/*! - Sets the maximum value for the given \a property to \a maxVal. - - When setting the maximum value, the minimum and current - values are adjusted if necessary (ensuring that the range remains - valid and that the current value is within in the range). - - \sa maximum(), setRange() -*/ -void QtDatePropertyManager::setMaximum(QtProperty *property, const QDate &maxVal) -{ - setMaximumValue(this, d_ptr, - &QtDatePropertyManager::propertyChanged, - &QtDatePropertyManager::valueChanged, - &QtDatePropertyManager::rangeChanged, - property, maxVal); -} - -/*! - \fn void QtDatePropertyManager::setRange(QtProperty *property, const QDate &minimum, const QDate &maximum) - - Sets the range of valid dates. - - This is a convenience function defining the range of valid dates - in one go; setting the \a minimum and \a maximum values for the - given \a property with a single function call. - - When setting a new date range, the current value is adjusted if - necessary (ensuring that the value remains in date range). - - \sa setMinimum(), setMaximum(), rangeChanged() -*/ -void QtDatePropertyManager::setRange(QtProperty *property, const QDate &minVal, const QDate &maxVal) -{ - void (QtDatePropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, const QDate &, - const QDate &, const QDate &) = 0; - setBorderValues(this, d_ptr, - &QtDatePropertyManager::propertyChanged, - &QtDatePropertyManager::valueChanged, - &QtDatePropertyManager::rangeChanged, - property, minVal, maxVal, setSubPropertyRange); -} - -/*! - \reimp -*/ -void QtDatePropertyManager::initializeProperty(QtProperty *property) -{ - d_ptr->m_values[property] = QtDatePropertyManagerPrivate::Data(); -} - -/*! - \reimp -*/ -void QtDatePropertyManager::uninitializeProperty(QtProperty *property) -{ - d_ptr->m_values.remove(property); -} - -// QtTimePropertyManager - -class QtTimePropertyManagerPrivate -{ - QtTimePropertyManager *q_ptr; - Q_DECLARE_PUBLIC(QtTimePropertyManager) -public: - - QString m_format; - - typedef QMap PropertyValueMap; - PropertyValueMap m_values; -}; - -/*! - \class QtTimePropertyManager - - \brief The QtTimePropertyManager provides and manages QTime properties. - - A time property's value can be retrieved using the value() - function, and set using the setValue() slot. - - In addition, QtTimePropertyManager provides the valueChanged() signal - which is emitted whenever a property created by this manager - changes. - - \sa QtAbstractPropertyManager, QtTimeEditFactory -*/ - -/*! - \fn void QtTimePropertyManager::valueChanged(QtProperty *property, const QTime &value) - - This signal is emitted whenever a property created by this manager - changes its value, passing a pointer to the \a property and the - new \a value as parameters. - - \sa setValue() -*/ - -/*! - Creates a manager with the given \a parent. -*/ -QtTimePropertyManager::QtTimePropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) -{ - d_ptr = new QtTimePropertyManagerPrivate; - d_ptr->q_ptr = this; - - QLocale loc; - d_ptr->m_format = loc.timeFormat(QLocale::ShortFormat); -} - -/*! - Destroys this manager, and all the properties it has created. -*/ -QtTimePropertyManager::~QtTimePropertyManager() -{ - clear(); - delete d_ptr; -} - -/*! - Returns the given \a property's value. - - If the given property is not managed by this manager, this - function returns an invalid time object. - - \sa setValue() -*/ -QTime QtTimePropertyManager::value(const QtProperty *property) const -{ - return d_ptr->m_values.value(property, QTime()); -} - -/*! - \reimp -*/ -QString QtTimePropertyManager::valueText(const QtProperty *property) const -{ - const QtTimePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QString(); - return it.value().toString(d_ptr->m_format); -} - -/*! - \fn void QtTimePropertyManager::setValue(QtProperty *property, const QTime &value) - - Sets the value of the given \a property to \a value. - - \sa value(), valueChanged() -*/ -void QtTimePropertyManager::setValue(QtProperty *property, const QTime &val) -{ - setSimpleValue(d_ptr->m_values, this, - &QtTimePropertyManager::propertyChanged, - &QtTimePropertyManager::valueChanged, - property, val); -} - -/*! - \reimp -*/ -void QtTimePropertyManager::initializeProperty(QtProperty *property) -{ - d_ptr->m_values[property] = QTime::currentTime(); -} - -/*! - \reimp -*/ -void QtTimePropertyManager::uninitializeProperty(QtProperty *property) -{ - d_ptr->m_values.remove(property); -} - -// QtDateTimePropertyManager - -class QtDateTimePropertyManagerPrivate -{ - QtDateTimePropertyManager *q_ptr; - Q_DECLARE_PUBLIC(QtDateTimePropertyManager) -public: - - QString m_format; - - typedef QMap PropertyValueMap; - PropertyValueMap m_values; -}; - -/*! \class QtDateTimePropertyManager - - \brief The QtDateTimePropertyManager provides and manages QDateTime properties. - - A date and time property has a current value which can be - retrieved using the value() function, and set using the setValue() - slot. In addition, QtDateTimePropertyManager provides the - valueChanged() signal which is emitted whenever a property created - by this manager changes. - - \sa QtAbstractPropertyManager, QtDateTimeEditFactory, QtDatePropertyManager -*/ - -/*! - \fn void QtDateTimePropertyManager::valueChanged(QtProperty *property, const QDateTime &value) - - This signal is emitted whenever a property created by this manager - changes its value, passing a pointer to the \a property and the new - \a value as parameters. -*/ - -/*! - Creates a manager with the given \a parent. -*/ -QtDateTimePropertyManager::QtDateTimePropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) -{ - d_ptr = new QtDateTimePropertyManagerPrivate; - d_ptr->q_ptr = this; - - QLocale loc; - d_ptr->m_format = loc.dateFormat(QLocale::ShortFormat); - d_ptr->m_format += QLatin1Char(' '); - d_ptr->m_format += loc.timeFormat(QLocale::ShortFormat); -} - -/*! - Destroys this manager, and all the properties it has created. -*/ -QtDateTimePropertyManager::~QtDateTimePropertyManager() -{ - clear(); - delete d_ptr; -} - -/*! - Returns the given \a property's value. - - If the given \a property is not managed by this manager, this - function returns an invalid QDateTime object. - - \sa setValue() -*/ -QDateTime QtDateTimePropertyManager::value(const QtProperty *property) const -{ - return d_ptr->m_values.value(property, QDateTime()); -} - -/*! - \reimp -*/ -QString QtDateTimePropertyManager::valueText(const QtProperty *property) const -{ - const QtDateTimePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QString(); - return it.value().toString(d_ptr->m_format); -} - -/*! - \fn void QtDateTimePropertyManager::setValue(QtProperty *property, const QDateTime &value) - - Sets the value of the given \a property to \a value. - - \sa value(), valueChanged() -*/ -void QtDateTimePropertyManager::setValue(QtProperty *property, const QDateTime &val) -{ - setSimpleValue(d_ptr->m_values, this, - &QtDateTimePropertyManager::propertyChanged, - &QtDateTimePropertyManager::valueChanged, - property, val); -} - -/*! - \reimp -*/ -void QtDateTimePropertyManager::initializeProperty(QtProperty *property) -{ - d_ptr->m_values[property] = QDateTime::currentDateTime(); -} - -/*! - \reimp -*/ -void QtDateTimePropertyManager::uninitializeProperty(QtProperty *property) -{ - d_ptr->m_values.remove(property); -} - -// QtKeySequencePropertyManager - -class QtKeySequencePropertyManagerPrivate -{ - QtKeySequencePropertyManager *q_ptr; - Q_DECLARE_PUBLIC(QtKeySequencePropertyManager) -public: - - QString m_format; - - typedef QMap PropertyValueMap; - PropertyValueMap m_values; -}; - -/*! \class QtKeySequencePropertyManager - - \brief The QtKeySequencePropertyManager provides and manages QKeySequence properties. - - A key sequence's value can be retrieved using the value() - function, and set using the setValue() slot. - - In addition, QtKeySequencePropertyManager provides the valueChanged() signal - which is emitted whenever a property created by this manager - changes. - - \sa QtAbstractPropertyManager -*/ - -/*! - \fn void QtKeySequencePropertyManager::valueChanged(QtProperty *property, const QKeySequence &value) - - This signal is emitted whenever a property created by this manager - changes its value, passing a pointer to the \a property and the new - \a value as parameters. -*/ - -/*! - Creates a manager with the given \a parent. -*/ -QtKeySequencePropertyManager::QtKeySequencePropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) -{ - d_ptr = new QtKeySequencePropertyManagerPrivate; - d_ptr->q_ptr = this; -} - -/*! - Destroys this manager, and all the properties it has created. -*/ -QtKeySequencePropertyManager::~QtKeySequencePropertyManager() -{ - clear(); - delete d_ptr; -} - -/*! - Returns the given \a property's value. - - If the given \a property is not managed by this manager, this - function returns an empty QKeySequence object. - - \sa setValue() -*/ -QKeySequence QtKeySequencePropertyManager::value(const QtProperty *property) const -{ - return d_ptr->m_values.value(property, QKeySequence()); -} - -/*! - \reimp -*/ -QString QtKeySequencePropertyManager::valueText(const QtProperty *property) const -{ - const QtKeySequencePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QString(); - return it.value().toString(QKeySequence::NativeText); -} - -/*! - \fn void QtKeySequencePropertyManager::setValue(QtProperty *property, const QKeySequence &value) - - Sets the value of the given \a property to \a value. - - \sa value(), valueChanged() -*/ -void QtKeySequencePropertyManager::setValue(QtProperty *property, const QKeySequence &val) -{ - setSimpleValue(d_ptr->m_values, this, - &QtKeySequencePropertyManager::propertyChanged, - &QtKeySequencePropertyManager::valueChanged, - property, val); -} - -/*! - \reimp -*/ -void QtKeySequencePropertyManager::initializeProperty(QtProperty *property) -{ - d_ptr->m_values[property] = QKeySequence(); -} - -/*! - \reimp -*/ -void QtKeySequencePropertyManager::uninitializeProperty(QtProperty *property) -{ - d_ptr->m_values.remove(property); -} - -// QtCharPropertyManager - -class QtCharPropertyManagerPrivate -{ - QtCharPropertyManager *q_ptr; - Q_DECLARE_PUBLIC(QtCharPropertyManager) -public: - - typedef QMap PropertyValueMap; - PropertyValueMap m_values; -}; - -/*! \class QtCharPropertyManager - - \brief The QtCharPropertyManager provides and manages QChar properties. - - A char's value can be retrieved using the value() - function, and set using the setValue() slot. - - In addition, QtCharPropertyManager provides the valueChanged() signal - which is emitted whenever a property created by this manager - changes. - - \sa QtAbstractPropertyManager -*/ - -/*! - \fn void QtCharPropertyManager::valueChanged(QtProperty *property, const QChar &value) - - This signal is emitted whenever a property created by this manager - changes its value, passing a pointer to the \a property and the new - \a value as parameters. -*/ - -/*! - Creates a manager with the given \a parent. -*/ -QtCharPropertyManager::QtCharPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) -{ - d_ptr = new QtCharPropertyManagerPrivate; - d_ptr->q_ptr = this; -} - -/*! - Destroys this manager, and all the properties it has created. -*/ -QtCharPropertyManager::~QtCharPropertyManager() -{ - clear(); - delete d_ptr; -} - -/*! - Returns the given \a property's value. - - If the given \a property is not managed by this manager, this - function returns an null QChar object. - - \sa setValue() -*/ -QChar QtCharPropertyManager::value(const QtProperty *property) const -{ - return d_ptr->m_values.value(property, QChar()); -} - -/*! - \reimp -*/ -QString QtCharPropertyManager::valueText(const QtProperty *property) const -{ - const QtCharPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QString(); - const QChar c = it.value(); - return c.isNull() ? QString() : QString(c); -} - -/*! - \fn void QtCharPropertyManager::setValue(QtProperty *property, const QChar &value) - - Sets the value of the given \a property to \a value. - - \sa value(), valueChanged() -*/ -void QtCharPropertyManager::setValue(QtProperty *property, const QChar &val) -{ - setSimpleValue(d_ptr->m_values, this, - &QtCharPropertyManager::propertyChanged, - &QtCharPropertyManager::valueChanged, - property, val); -} - -/*! - \reimp -*/ -void QtCharPropertyManager::initializeProperty(QtProperty *property) -{ - d_ptr->m_values[property] = QChar(); -} - -/*! - \reimp -*/ -void QtCharPropertyManager::uninitializeProperty(QtProperty *property) -{ - d_ptr->m_values.remove(property); -} - -// QtLocalePropertyManager - -class QtLocalePropertyManagerPrivate -{ - QtLocalePropertyManager *q_ptr; - Q_DECLARE_PUBLIC(QtLocalePropertyManager) -public: - - QtLocalePropertyManagerPrivate(); - - void slotEnumChanged(QtProperty *property, int value); - void slotPropertyDestroyed(QtProperty *property); - - typedef QMap PropertyValueMap; - PropertyValueMap m_values; - - QtEnumPropertyManager *m_enumPropertyManager; - - QMap m_propertyToLanguage; - QMap m_propertyToCountry; - - QMap m_languageToProperty; - QMap m_countryToProperty; -}; - -QtLocalePropertyManagerPrivate::QtLocalePropertyManagerPrivate() -{ -} - -void QtLocalePropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value) -{ - if (QtProperty *prop = m_languageToProperty.value(property, 0)) { - const QLocale loc = m_values[prop]; - QLocale::Language newLanguage = loc.language(); - QLocale::Country newCountry = loc.country(); - metaEnumProvider()->indexToLocale(value, 0, &newLanguage, 0); - QLocale newLoc(newLanguage, newCountry); - q_ptr->setValue(prop, newLoc); - } else if (QtProperty *prop = m_countryToProperty.value(property, 0)) { - const QLocale loc = m_values[prop]; - QLocale::Language newLanguage = loc.language(); - QLocale::Country newCountry = loc.country(); - metaEnumProvider()->indexToLocale(m_enumPropertyManager->value(m_propertyToLanguage.value(prop)), value, &newLanguage, &newCountry); - QLocale newLoc(newLanguage, newCountry); - q_ptr->setValue(prop, newLoc); - } -} - -void QtLocalePropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) -{ - if (QtProperty *subProp = m_languageToProperty.value(property, 0)) { - m_propertyToLanguage[subProp] = 0; - m_languageToProperty.remove(property); - } else if (QtProperty *subProp = m_countryToProperty.value(property, 0)) { - m_propertyToCountry[subProp] = 0; - m_countryToProperty.remove(property); - } -} - -/*! - \class QtLocalePropertyManager - - \brief The QtLocalePropertyManager provides and manages QLocale properties. - - A locale property has nested \e language and \e country - subproperties. The top-level property's value can be retrieved - using the value() function, and set using the setValue() slot. - - The subproperties are created by QtEnumPropertyManager object. - These submanager can be retrieved using the subEnumPropertyManager() - function. In order to provide editing widgets for the subproperties - in a property browser widget, this manager must be associated with editor factory. - - In addition, QtLocalePropertyManager provides the valueChanged() - signal which is emitted whenever a property created by this - manager changes. - - \sa QtAbstractPropertyManager, QtEnumPropertyManager -*/ - -/*! - \fn void QtLocalePropertyManager::valueChanged(QtProperty *property, const QLocale &value) - - This signal is emitted whenever a property created by this manager - changes its value, passing a pointer to the \a property and the - new \a value as parameters. - - \sa setValue() -*/ - -/*! - Creates a manager with the given \a parent. -*/ -QtLocalePropertyManager::QtLocalePropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) -{ - d_ptr = new QtLocalePropertyManagerPrivate; - d_ptr->q_ptr = this; - - d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this); - connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotEnumChanged(QtProperty *, int))); - - connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)), - this, SLOT(slotPropertyDestroyed(QtProperty *))); -} - -/*! - Destroys this manager, and all the properties it has created. -*/ -QtLocalePropertyManager::~QtLocalePropertyManager() -{ - clear(); - delete d_ptr; -} - -/*! - Returns the manager that creates the nested \e language - and \e country subproperties. - - In order to provide editing widgets for the mentioned subproperties - in a property browser widget, this manager must be associated with - an editor factory. - - \sa QtAbstractPropertyBrowser::setFactoryForManager() -*/ -QtEnumPropertyManager *QtLocalePropertyManager::subEnumPropertyManager() const -{ - return d_ptr->m_enumPropertyManager; -} - -/*! - Returns the given \a property's value. - - If the given property is not managed by this manager, this - function returns the default locale. - - \sa setValue() -*/ -QLocale QtLocalePropertyManager::value(const QtProperty *property) const -{ - return d_ptr->m_values.value(property, QLocale()); -} - -/*! - \reimp -*/ -QString QtLocalePropertyManager::valueText(const QtProperty *property) const -{ - const QtLocalePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QString(); - - QLocale loc = it.value(); - - int langIdx = 0; - int countryIdx = 0; - metaEnumProvider()->localeToIndex(loc.language(), loc.country(), &langIdx, &countryIdx); - QString str = tr("%1, %2") - .arg(metaEnumProvider()->languageEnumNames().at(langIdx)) - .arg(metaEnumProvider()->countryEnumNames(loc.language()).at(countryIdx)); - return str; -} - -/*! - \fn void QtLocalePropertyManager::setValue(QtProperty *property, const QLocale &value) - - Sets the value of the given \a property to \a value. Nested - properties are updated automatically. - - \sa value(), valueChanged() -*/ -void QtLocalePropertyManager::setValue(QtProperty *property, const QLocale &val) -{ - const QtLocalePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); - if (it == d_ptr->m_values.end()) - return; - - const QLocale loc = it.value(); - if (loc == val) - return; - - it.value() = val; - - int langIdx = 0; - int countryIdx = 0; - metaEnumProvider()->localeToIndex(val.language(), val.country(), &langIdx, &countryIdx); - if (loc.language() != val.language()) { - d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToLanguage.value(property), langIdx); - d_ptr->m_enumPropertyManager->setEnumNames(d_ptr->m_propertyToCountry.value(property), - metaEnumProvider()->countryEnumNames(val.language())); - } - d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToCountry.value(property), countryIdx); - - emit propertyChanged(property); - emit valueChanged(property, val); -} - -/*! - \reimp -*/ -void QtLocalePropertyManager::initializeProperty(QtProperty *property) -{ - QLocale val; - d_ptr->m_values[property] = val; - - int langIdx = 0; - int countryIdx = 0; - metaEnumProvider()->localeToIndex(val.language(), val.country(), &langIdx, &countryIdx); - - QtProperty *languageProp = d_ptr->m_enumPropertyManager->addProperty(); - languageProp->setPropertyName(tr("Language")); - d_ptr->m_enumPropertyManager->setEnumNames(languageProp, metaEnumProvider()->languageEnumNames()); - d_ptr->m_enumPropertyManager->setValue(languageProp, langIdx); - d_ptr->m_propertyToLanguage[property] = languageProp; - d_ptr->m_languageToProperty[languageProp] = property; - property->addSubProperty(languageProp); - - QtProperty *countryProp = d_ptr->m_enumPropertyManager->addProperty(); - countryProp->setPropertyName(tr("Country")); - d_ptr->m_enumPropertyManager->setEnumNames(countryProp, metaEnumProvider()->countryEnumNames(val.language())); - d_ptr->m_enumPropertyManager->setValue(countryProp, countryIdx); - d_ptr->m_propertyToCountry[property] = countryProp; - d_ptr->m_countryToProperty[countryProp] = property; - property->addSubProperty(countryProp); -} - -/*! - \reimp -*/ -void QtLocalePropertyManager::uninitializeProperty(QtProperty *property) -{ - QtProperty *languageProp = d_ptr->m_propertyToLanguage[property]; - if (languageProp) { - d_ptr->m_languageToProperty.remove(languageProp); - delete languageProp; - } - d_ptr->m_propertyToLanguage.remove(property); - - QtProperty *countryProp = d_ptr->m_propertyToCountry[property]; - if (countryProp) { - d_ptr->m_countryToProperty.remove(countryProp); - delete countryProp; - } - d_ptr->m_propertyToCountry.remove(property); - - d_ptr->m_values.remove(property); -} - -// QtPointPropertyManager - -class QtPointPropertyManagerPrivate -{ - QtPointPropertyManager *q_ptr; - Q_DECLARE_PUBLIC(QtPointPropertyManager) -public: - - void slotIntChanged(QtProperty *property, int value); - void slotPropertyDestroyed(QtProperty *property); - - typedef QMap PropertyValueMap; - PropertyValueMap m_values; - - QtIntPropertyManager *m_intPropertyManager; - - QMap m_propertyToX; - QMap m_propertyToY; - - QMap m_xToProperty; - QMap m_yToProperty; -}; - -void QtPointPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value) -{ - if (QtProperty *xprop = m_xToProperty.value(property, 0)) { - QPoint p = m_values[xprop]; - p.setX(value); - q_ptr->setValue(xprop, p); - } else if (QtProperty *yprop = m_yToProperty.value(property, 0)) { - QPoint p = m_values[yprop]; - p.setY(value); - q_ptr->setValue(yprop, p); - } -} - -void QtPointPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) -{ - if (QtProperty *pointProp = m_xToProperty.value(property, 0)) { - m_propertyToX[pointProp] = 0; - m_xToProperty.remove(property); - } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) { - m_propertyToY[pointProp] = 0; - m_yToProperty.remove(property); - } -} - -/*! \class QtPointPropertyManager - - \brief The QtPointPropertyManager provides and manages QPoint properties. - - A point property has nested \e x and \e y subproperties. The - top-level property's value can be retrieved using the value() - function, and set using the setValue() slot. - - The subproperties are created by a QtIntPropertyManager object. This - manager can be retrieved using the subIntPropertyManager() function. In - order to provide editing widgets for the subproperties in a - property browser widget, this manager must be associated with an - editor factory. - - In addition, QtPointPropertyManager provides the valueChanged() signal which - is emitted whenever a property created by this manager changes. - - \sa QtAbstractPropertyManager, QtIntPropertyManager, QtPointFPropertyManager -*/ - -/*! - \fn void QtPointPropertyManager::valueChanged(QtProperty *property, const QPoint &value) - - This signal is emitted whenever a property created by this manager - changes its value, passing a pointer to the \a property and the - new \a value as parameters. - - \sa setValue() -*/ - -/*! - Creates a manager with the given \a parent. -*/ -QtPointPropertyManager::QtPointPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) -{ - d_ptr = new QtPointPropertyManagerPrivate; - d_ptr->q_ptr = this; - - d_ptr->m_intPropertyManager = new QtIntPropertyManager(this); - connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotIntChanged(QtProperty *, int))); - connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)), - this, SLOT(slotPropertyDestroyed(QtProperty *))); -} - -/*! - Destroys this manager, and all the properties it has created. -*/ -QtPointPropertyManager::~QtPointPropertyManager() -{ - clear(); - delete d_ptr; -} - -/*! - Returns the manager that creates the nested \e x and \e y - subproperties. - - In order to provide editing widgets for the subproperties in a - property browser widget, this manager must be associated with an - editor factory. - - \sa QtAbstractPropertyBrowser::setFactoryForManager() -*/ -QtIntPropertyManager *QtPointPropertyManager::subIntPropertyManager() const -{ - return d_ptr->m_intPropertyManager; -} - -/*! - Returns the given \a property's value. - - If the given \a property is not managed by this manager, this - function returns a point with coordinates (0, 0). - - \sa setValue() -*/ -QPoint QtPointPropertyManager::value(const QtProperty *property) const -{ - return d_ptr->m_values.value(property, QPoint()); -} - -/*! - \reimp -*/ -QString QtPointPropertyManager::valueText(const QtProperty *property) const -{ - const QtPointPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QString(); - const QPoint v = it.value(); - return QString(tr("(%1, %2)").arg(QString::number(v.x())) - .arg(QString::number(v.y()))); -} - -/*! - \fn void QtPointPropertyManager::setValue(QtProperty *property, const QPoint &value) - - Sets the value of the given \a property to \a value. Nested - properties are updated automatically. - - \sa value(), valueChanged() -*/ -void QtPointPropertyManager::setValue(QtProperty *property, const QPoint &val) -{ - const QtPointPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); - if (it == d_ptr->m_values.end()) - return; - - if (it.value() == val) - return; - - it.value() = val; - d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToX[property], val.x()); - d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToY[property], val.y()); - - emit propertyChanged(property); - emit valueChanged(property, val); -} - -/*! - \reimp -*/ -void QtPointPropertyManager::initializeProperty(QtProperty *property) -{ - d_ptr->m_values[property] = QPoint(0, 0); - - QtProperty *xProp = d_ptr->m_intPropertyManager->addProperty(); - xProp->setPropertyName(tr("X")); - d_ptr->m_intPropertyManager->setValue(xProp, 0); - d_ptr->m_propertyToX[property] = xProp; - d_ptr->m_xToProperty[xProp] = property; - property->addSubProperty(xProp); - - QtProperty *yProp = d_ptr->m_intPropertyManager->addProperty(); - yProp->setPropertyName(tr("Y")); - d_ptr->m_intPropertyManager->setValue(yProp, 0); - d_ptr->m_propertyToY[property] = yProp; - d_ptr->m_yToProperty[yProp] = property; - property->addSubProperty(yProp); -} - -/*! - \reimp -*/ -void QtPointPropertyManager::uninitializeProperty(QtProperty *property) -{ - QtProperty *xProp = d_ptr->m_propertyToX[property]; - if (xProp) { - d_ptr->m_xToProperty.remove(xProp); - delete xProp; - } - d_ptr->m_propertyToX.remove(property); - - QtProperty *yProp = d_ptr->m_propertyToY[property]; - if (yProp) { - d_ptr->m_yToProperty.remove(yProp); - delete yProp; - } - d_ptr->m_propertyToY.remove(property); - - d_ptr->m_values.remove(property); -} - -// QtPointFPropertyManager - -class QtPointFPropertyManagerPrivate -{ - QtPointFPropertyManager *q_ptr; - Q_DECLARE_PUBLIC(QtPointFPropertyManager) -public: - - struct Data - { - Data() : decimals(2) {} - QPointF val; - int decimals; - }; - - void slotDoubleChanged(QtProperty *property, double value); - void slotPropertyDestroyed(QtProperty *property); - - typedef QMap PropertyValueMap; - PropertyValueMap m_values; - - QtDoublePropertyManager *m_doublePropertyManager; - - QMap m_propertyToX; - QMap m_propertyToY; - - QMap m_xToProperty; - QMap m_yToProperty; -}; - -void QtPointFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value) -{ - if (QtProperty *prop = m_xToProperty.value(property, 0)) { - QPointF p = m_values[prop].val; - p.setX(value); - q_ptr->setValue(prop, p); - } else if (QtProperty *prop = m_yToProperty.value(property, 0)) { - QPointF p = m_values[prop].val; - p.setY(value); - q_ptr->setValue(prop, p); - } -} - -void QtPointFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) -{ - if (QtProperty *pointProp = m_xToProperty.value(property, 0)) { - m_propertyToX[pointProp] = 0; - m_xToProperty.remove(property); - } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) { - m_propertyToY[pointProp] = 0; - m_yToProperty.remove(property); - } -} - -/*! \class QtPointFPropertyManager - - \brief The QtPointFPropertyManager provides and manages QPointF properties. - - A point property has nested \e x and \e y subproperties. The - top-level property's value can be retrieved using the value() - function, and set using the setValue() slot. - - The subproperties are created by a QtDoublePropertyManager object. This - manager can be retrieved using the subDoublePropertyManager() function. In - order to provide editing widgets for the subproperties in a - property browser widget, this manager must be associated with an - editor factory. - - In addition, QtPointFPropertyManager provides the valueChanged() signal which - is emitted whenever a property created by this manager changes. - - \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtPointPropertyManager -*/ - -/*! - \fn void QtPointFPropertyManager::valueChanged(QtProperty *property, const QPointF &value) - - This signal is emitted whenever a property created by this manager - changes its value, passing a pointer to the \a property and the - new \a value as parameters. - - \sa setValue() -*/ - -/*! - \fn void QtPointFPropertyManager::decimalsChanged(QtProperty *property, int prec) - - This signal is emitted whenever a property created by this manager - changes its precision of value, passing a pointer to the - \a property and the new \a prec value - - \sa setDecimals() -*/ - -/*! - Creates a manager with the given \a parent. -*/ -QtPointFPropertyManager::QtPointFPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) -{ - d_ptr = new QtPointFPropertyManagerPrivate; - d_ptr->q_ptr = this; - - d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this); - connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty *, double)), - this, SLOT(slotDoubleChanged(QtProperty *, double))); - connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty *)), - this, SLOT(slotPropertyDestroyed(QtProperty *))); -} - -/*! - Destroys this manager, and all the properties it has created. -*/ -QtPointFPropertyManager::~QtPointFPropertyManager() -{ - clear(); - delete d_ptr; -} - -/*! - Returns the manager that creates the nested \e x and \e y - subproperties. - - In order to provide editing widgets for the subproperties in a - property browser widget, this manager must be associated with an - editor factory. - - \sa QtAbstractPropertyBrowser::setFactoryForManager() -*/ -QtDoublePropertyManager *QtPointFPropertyManager::subDoublePropertyManager() const -{ - return d_ptr->m_doublePropertyManager; -} - -/*! - Returns the given \a property's value. - - If the given \a property is not managed by this manager, this - function returns a point with coordinates (0, 0). - - \sa setValue() -*/ -QPointF QtPointFPropertyManager::value(const QtProperty *property) const -{ - return getValue(d_ptr->m_values, property); -} - -/*! - Returns the given \a property's precision, in decimals. - - \sa setDecimals() -*/ -int QtPointFPropertyManager::decimals(const QtProperty *property) const -{ - return getData(d_ptr->m_values, &QtPointFPropertyManagerPrivate::Data::decimals, property, 0); -} - -/*! - \reimp -*/ -QString QtPointFPropertyManager::valueText(const QtProperty *property) const -{ - const QtPointFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QString(); - const QPointF v = it.value().val; - const int dec = it.value().decimals; - return QString(tr("(%1, %2)").arg(QString::number(v.x(), 'f', dec)) - .arg(QString::number(v.y(), 'f', dec))); -} - -/*! - \fn void QtPointFPropertyManager::setValue(QtProperty *property, const QPointF &value) - - Sets the value of the given \a property to \a value. Nested - properties are updated automatically. - - \sa value(), valueChanged() -*/ -void QtPointFPropertyManager::setValue(QtProperty *property, const QPointF &val) -{ - const QtPointFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); - if (it == d_ptr->m_values.end()) - return; - - if (it.value().val == val) - return; - - it.value().val = val; - d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToX[property], val.x()); - d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToY[property], val.y()); - - emit propertyChanged(property); - emit valueChanged(property, val); -} - -/*! - \fn void QtPointFPropertyManager::setDecimals(QtProperty *property, int prec) - - Sets the precision of the given \a property to \a prec. - - The valid decimal range is 0-13. The default is 2. - - \sa decimals() -*/ -void QtPointFPropertyManager::setDecimals(QtProperty *property, int prec) -{ - const QtPointFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); - if (it == d_ptr->m_values.end()) - return; - - QtPointFPropertyManagerPrivate::Data data = it.value(); - - if (prec > 13) - prec = 13; - else if (prec < 0) - prec = 0; - - if (data.decimals == prec) - return; - - data.decimals = prec; - d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToX[property], prec); - d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToY[property], prec); - - it.value() = data; - - emit decimalsChanged(property, data.decimals); -} - -/*! - \reimp -*/ -void QtPointFPropertyManager::initializeProperty(QtProperty *property) -{ - d_ptr->m_values[property] = QtPointFPropertyManagerPrivate::Data(); - - QtProperty *xProp = d_ptr->m_doublePropertyManager->addProperty(); - xProp->setPropertyName(tr("X")); - d_ptr->m_doublePropertyManager->setDecimals(xProp, decimals(property)); - d_ptr->m_doublePropertyManager->setValue(xProp, 0); - d_ptr->m_propertyToX[property] = xProp; - d_ptr->m_xToProperty[xProp] = property; - property->addSubProperty(xProp); - - QtProperty *yProp = d_ptr->m_doublePropertyManager->addProperty(); - yProp->setPropertyName(tr("Y")); - d_ptr->m_doublePropertyManager->setDecimals(yProp, decimals(property)); - d_ptr->m_doublePropertyManager->setValue(yProp, 0); - d_ptr->m_propertyToY[property] = yProp; - d_ptr->m_yToProperty[yProp] = property; - property->addSubProperty(yProp); -} - -/*! - \reimp -*/ -void QtPointFPropertyManager::uninitializeProperty(QtProperty *property) -{ - QtProperty *xProp = d_ptr->m_propertyToX[property]; - if (xProp) { - d_ptr->m_xToProperty.remove(xProp); - delete xProp; - } - d_ptr->m_propertyToX.remove(property); - - QtProperty *yProp = d_ptr->m_propertyToY[property]; - if (yProp) { - d_ptr->m_yToProperty.remove(yProp); - delete yProp; - } - d_ptr->m_propertyToY.remove(property); - - d_ptr->m_values.remove(property); -} - -// QtSizePropertyManager - -class QtSizePropertyManagerPrivate -{ - QtSizePropertyManager *q_ptr; - Q_DECLARE_PUBLIC(QtSizePropertyManager) -public: - - void slotIntChanged(QtProperty *property, int value); - void slotPropertyDestroyed(QtProperty *property); - void setValue(QtProperty *property, const QSize &val); - void setRange(QtProperty *property, - const QSize &minVal, const QSize &maxVal, const QSize &val); - - struct Data - { - Data() : val(QSize(0, 0)), minVal(QSize(0, 0)), maxVal(QSize(INT_MAX, INT_MAX)) {} - QSize val; - QSize minVal; - QSize maxVal; - QSize minimumValue() const { return minVal; } - QSize maximumValue() const { return maxVal; } - void setMinimumValue(const QSize &newMinVal) { setSizeMinimumData(this, newMinVal); } - void setMaximumValue(const QSize &newMaxVal) { setSizeMaximumData(this, newMaxVal); } - }; - - typedef QMap PropertyValueMap; - PropertyValueMap m_values; - - QtIntPropertyManager *m_intPropertyManager; - - QMap m_propertyToW; - QMap m_propertyToH; - - QMap m_wToProperty; - QMap m_hToProperty; -}; - -void QtSizePropertyManagerPrivate::slotIntChanged(QtProperty *property, int value) -{ - if (QtProperty *prop = m_wToProperty.value(property, 0)) { - QSize s = m_values[prop].val; - s.setWidth(value); - q_ptr->setValue(prop, s); - } else if (QtProperty *prop = m_hToProperty.value(property, 0)) { - QSize s = m_values[prop].val; - s.setHeight(value); - q_ptr->setValue(prop, s); - } -} - -void QtSizePropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) -{ - if (QtProperty *pointProp = m_wToProperty.value(property, 0)) { - m_propertyToW[pointProp] = 0; - m_wToProperty.remove(property); - } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) { - m_propertyToH[pointProp] = 0; - m_hToProperty.remove(property); - } -} - -void QtSizePropertyManagerPrivate::setValue(QtProperty *property, const QSize &val) -{ - m_intPropertyManager->setValue(m_propertyToW.value(property), val.width()); - m_intPropertyManager->setValue(m_propertyToH.value(property), val.height()); -} - -void QtSizePropertyManagerPrivate::setRange(QtProperty *property, - const QSize &minVal, const QSize &maxVal, const QSize &val) -{ - QtProperty *wProperty = m_propertyToW.value(property); - QtProperty *hProperty = m_propertyToH.value(property); - m_intPropertyManager->setRange(wProperty, minVal.width(), maxVal.width()); - m_intPropertyManager->setValue(wProperty, val.width()); - m_intPropertyManager->setRange(hProperty, minVal.height(), maxVal.height()); - m_intPropertyManager->setValue(hProperty, val.height()); -} - -/*! - \class QtSizePropertyManager - - \brief The QtSizePropertyManager provides and manages QSize properties. - - A size property has nested \e width and \e height - subproperties. The top-level property's value can be retrieved - using the value() function, and set using the setValue() slot. - - The subproperties are created by a QtIntPropertyManager object. This - manager can be retrieved using the subIntPropertyManager() function. In - order to provide editing widgets for the subproperties in a - property browser widget, this manager must be associated with an - editor factory. - - A size property also has a range of valid values defined by a - minimum size and a maximum size. These sizes can be retrieved - using the minimum() and the maximum() functions, and set using the - setMinimum() and setMaximum() slots. Alternatively, the range can - be defined in one go using the setRange() slot. - - In addition, QtSizePropertyManager provides the valueChanged() signal - which is emitted whenever a property created by this manager - changes, and the rangeChanged() signal which is emitted whenever - such a property changes its range of valid sizes. - - \sa QtAbstractPropertyManager, QtIntPropertyManager, QtSizeFPropertyManager -*/ - -/*! - \fn void QtSizePropertyManager::valueChanged(QtProperty *property, const QSize &value) - - This signal is emitted whenever a property created by this manager - changes its value, passing a pointer to the \a property and the new - \a value as parameters. - - \sa setValue() -*/ - -/*! - \fn void QtSizePropertyManager::rangeChanged(QtProperty *property, const QSize &minimum, const QSize &maximum) - - This signal is emitted whenever a property created by this manager - changes its range of valid sizes, passing a pointer to the \a - property and the new \a minimum and \a maximum sizes. - - \sa setRange() -*/ - -/*! - Creates a manager with the given \a parent. -*/ -QtSizePropertyManager::QtSizePropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) -{ - d_ptr = new QtSizePropertyManagerPrivate; - d_ptr->q_ptr = this; - - d_ptr->m_intPropertyManager = new QtIntPropertyManager(this); - connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotIntChanged(QtProperty *, int))); - connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)), - this, SLOT(slotPropertyDestroyed(QtProperty *))); -} - -/*! - Destroys this manager, and all the properties it has created. -*/ -QtSizePropertyManager::~QtSizePropertyManager() -{ - clear(); - delete d_ptr; -} - -/*! - Returns the manager that creates the nested \e width and \e height - subproperties. - - In order to provide editing widgets for the \e width and \e height - properties in a property browser widget, this manager must be - associated with an editor factory. - - \sa QtAbstractPropertyBrowser::setFactoryForManager() -*/ -QtIntPropertyManager *QtSizePropertyManager::subIntPropertyManager() const -{ - return d_ptr->m_intPropertyManager; -} - -/*! - Returns the given \a property's value. - - If the given \a property is not managed by this manager, this - function returns an invalid size - - \sa setValue() -*/ -QSize QtSizePropertyManager::value(const QtProperty *property) const -{ - return getValue(d_ptr->m_values, property); -} - -/*! - Returns the given \a property's minimum size value. - - \sa setMinimum(), maximum(), setRange() -*/ -QSize QtSizePropertyManager::minimum(const QtProperty *property) const -{ - return getMinimum(d_ptr->m_values, property); -} - -/*! - Returns the given \a property's maximum size value. - - \sa setMaximum(), minimum(), setRange() -*/ -QSize QtSizePropertyManager::maximum(const QtProperty *property) const -{ - return getMaximum(d_ptr->m_values, property); -} - -/*! - \reimp -*/ -QString QtSizePropertyManager::valueText(const QtProperty *property) const -{ - const QtSizePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QString(); - const QSize v = it.value().val; - return QString(tr("%1 x %2").arg(QString::number(v.width())) - .arg(QString::number(v.height()))); -} - -/*! - \fn void QtSizePropertyManager::setValue(QtProperty *property, const QSize &value) - - Sets the value of the given \a property to \a value. - - If the specified \a value is not valid according to the given \a - property's size range, the \a value is adjusted to the nearest - valid value within the size range. - - \sa value(), setRange(), valueChanged() -*/ -void QtSizePropertyManager::setValue(QtProperty *property, const QSize &val) -{ - setValueInRange(this, d_ptr, - &QtSizePropertyManager::propertyChanged, - &QtSizePropertyManager::valueChanged, - property, val, &QtSizePropertyManagerPrivate::setValue); -} - -/*! - Sets the minimum size value for the given \a property to \a minVal. - - When setting the minimum size value, the maximum and current - values are adjusted if necessary (ensuring that the size range - remains valid and that the current value is within the range). - - \sa minimum(), setRange(), rangeChanged() -*/ -void QtSizePropertyManager::setMinimum(QtProperty *property, const QSize &minVal) -{ - setBorderValue(this, d_ptr, - &QtSizePropertyManager::propertyChanged, - &QtSizePropertyManager::valueChanged, - &QtSizePropertyManager::rangeChanged, - property, - &QtSizePropertyManagerPrivate::Data::minimumValue, - &QtSizePropertyManagerPrivate::Data::setMinimumValue, - minVal, &QtSizePropertyManagerPrivate::setRange); -} - -/*! - Sets the maximum size value for the given \a property to \a maxVal. - - When setting the maximum size value, the minimum and current - values are adjusted if necessary (ensuring that the size range - remains valid and that the current value is within the range). - - \sa maximum(), setRange(), rangeChanged() -*/ -void QtSizePropertyManager::setMaximum(QtProperty *property, const QSize &maxVal) -{ - setBorderValue(this, d_ptr, - &QtSizePropertyManager::propertyChanged, - &QtSizePropertyManager::valueChanged, - &QtSizePropertyManager::rangeChanged, - property, - &QtSizePropertyManagerPrivate::Data::maximumValue, - &QtSizePropertyManagerPrivate::Data::setMaximumValue, - maxVal, &QtSizePropertyManagerPrivate::setRange); -} - -/*! - \fn void QtSizePropertyManager::setRange(QtProperty *property, const QSize &minimum, const QSize &maximum) - - Sets the range of valid values. - - This is a convenience function defining the range of valid values - in one go; setting the \a minimum and \a maximum values for the - given \a property with a single function call. - - When setting a new range, the current value is adjusted if - necessary (ensuring that the value remains within the range). - - \sa setMinimum(), setMaximum(), rangeChanged() -*/ -void QtSizePropertyManager::setRange(QtProperty *property, const QSize &minVal, const QSize &maxVal) -{ - setBorderValues(this, d_ptr, - &QtSizePropertyManager::propertyChanged, - &QtSizePropertyManager::valueChanged, - &QtSizePropertyManager::rangeChanged, - property, minVal, maxVal, &QtSizePropertyManagerPrivate::setRange); -} - -/*! - \reimp -*/ -void QtSizePropertyManager::initializeProperty(QtProperty *property) -{ - d_ptr->m_values[property] = QtSizePropertyManagerPrivate::Data(); - - QtProperty *wProp = d_ptr->m_intPropertyManager->addProperty(); - wProp->setPropertyName(tr("Width")); - d_ptr->m_intPropertyManager->setValue(wProp, 0); - d_ptr->m_intPropertyManager->setMinimum(wProp, 0); - d_ptr->m_propertyToW[property] = wProp; - d_ptr->m_wToProperty[wProp] = property; - property->addSubProperty(wProp); - - QtProperty *hProp = d_ptr->m_intPropertyManager->addProperty(); - hProp->setPropertyName(tr("Height")); - d_ptr->m_intPropertyManager->setValue(hProp, 0); - d_ptr->m_intPropertyManager->setMinimum(hProp, 0); - d_ptr->m_propertyToH[property] = hProp; - d_ptr->m_hToProperty[hProp] = property; - property->addSubProperty(hProp); -} - -/*! - \reimp -*/ -void QtSizePropertyManager::uninitializeProperty(QtProperty *property) -{ - QtProperty *wProp = d_ptr->m_propertyToW[property]; - if (wProp) { - d_ptr->m_wToProperty.remove(wProp); - delete wProp; - } - d_ptr->m_propertyToW.remove(property); - - QtProperty *hProp = d_ptr->m_propertyToH[property]; - if (hProp) { - d_ptr->m_hToProperty.remove(hProp); - delete hProp; - } - d_ptr->m_propertyToH.remove(property); - - d_ptr->m_values.remove(property); -} - -// QtSizeFPropertyManager - -class QtSizeFPropertyManagerPrivate -{ - QtSizeFPropertyManager *q_ptr; - Q_DECLARE_PUBLIC(QtSizeFPropertyManager) -public: - - void slotDoubleChanged(QtProperty *property, double value); - void slotPropertyDestroyed(QtProperty *property); - void setValue(QtProperty *property, const QSizeF &val); - void setRange(QtProperty *property, - const QSizeF &minVal, const QSizeF &maxVal, const QSizeF &val); - - struct Data - { - Data() : val(QSizeF(0, 0)), minVal(QSizeF(0, 0)), maxVal(QSizeF(INT_MAX, INT_MAX)), decimals(2) {} - QSizeF val; - QSizeF minVal; - QSizeF maxVal; - int decimals; - QSizeF minimumValue() const { return minVal; } - QSizeF maximumValue() const { return maxVal; } - void setMinimumValue(const QSizeF &newMinVal) { setSizeMinimumData(this, newMinVal); } - void setMaximumValue(const QSizeF &newMaxVal) { setSizeMaximumData(this, newMaxVal); } - }; - - typedef QMap PropertyValueMap; - PropertyValueMap m_values; - - QtDoublePropertyManager *m_doublePropertyManager; - - QMap m_propertyToW; - QMap m_propertyToH; - - QMap m_wToProperty; - QMap m_hToProperty; -}; - -void QtSizeFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value) -{ - if (QtProperty *prop = m_wToProperty.value(property, 0)) { - QSizeF s = m_values[prop].val; - s.setWidth(value); - q_ptr->setValue(prop, s); - } else if (QtProperty *prop = m_hToProperty.value(property, 0)) { - QSizeF s = m_values[prop].val; - s.setHeight(value); - q_ptr->setValue(prop, s); - } -} - -void QtSizeFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) -{ - if (QtProperty *pointProp = m_wToProperty.value(property, 0)) { - m_propertyToW[pointProp] = 0; - m_wToProperty.remove(property); - } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) { - m_propertyToH[pointProp] = 0; - m_hToProperty.remove(property); - } -} - -void QtSizeFPropertyManagerPrivate::setValue(QtProperty *property, const QSizeF &val) -{ - m_doublePropertyManager->setValue(m_propertyToW.value(property), val.width()); - m_doublePropertyManager->setValue(m_propertyToH.value(property), val.height()); -} - -void QtSizeFPropertyManagerPrivate::setRange(QtProperty *property, - const QSizeF &minVal, const QSizeF &maxVal, const QSizeF &val) -{ - m_doublePropertyManager->setRange(m_propertyToW[property], minVal.width(), maxVal.width()); - m_doublePropertyManager->setValue(m_propertyToW[property], val.width()); - m_doublePropertyManager->setRange(m_propertyToH[property], minVal.height(), maxVal.height()); - m_doublePropertyManager->setValue(m_propertyToH[property], val.height()); -} - -/*! - \class QtSizeFPropertyManager - - \brief The QtSizeFPropertyManager provides and manages QSizeF properties. - - A size property has nested \e width and \e height - subproperties. The top-level property's value can be retrieved - using the value() function, and set using the setValue() slot. - - The subproperties are created by a QtDoublePropertyManager object. This - manager can be retrieved using the subDoublePropertyManager() function. In - order to provide editing widgets for the subproperties in a - property browser widget, this manager must be associated with an - editor factory. - - A size property also has a range of valid values defined by a - minimum size and a maximum size. These sizes can be retrieved - using the minimum() and the maximum() functions, and set using the - setMinimum() and setMaximum() slots. Alternatively, the range can - be defined in one go using the setRange() slot. - - In addition, QtSizeFPropertyManager provides the valueChanged() signal - which is emitted whenever a property created by this manager - changes, and the rangeChanged() signal which is emitted whenever - such a property changes its range of valid sizes. - - \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtSizePropertyManager -*/ - -/*! - \fn void QtSizeFPropertyManager::valueChanged(QtProperty *property, const QSizeF &value) - - This signal is emitted whenever a property created by this manager - changes its value, passing a pointer to the \a property and the new - \a value as parameters. - - \sa setValue() -*/ - -/*! - \fn void QtSizeFPropertyManager::rangeChanged(QtProperty *property, const QSizeF &minimum, const QSizeF &maximum) - - This signal is emitted whenever a property created by this manager - changes its range of valid sizes, passing a pointer to the \a - property and the new \a minimum and \a maximum sizes. - - \sa setRange() -*/ - -/*! - \fn void QtSizeFPropertyManager::decimalsChanged(QtProperty *property, int prec) - - This signal is emitted whenever a property created by this manager - changes its precision of value, passing a pointer to the - \a property and the new \a prec value - - \sa setDecimals() -*/ - -/*! - Creates a manager with the given \a parent. -*/ -QtSizeFPropertyManager::QtSizeFPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) -{ - d_ptr = new QtSizeFPropertyManagerPrivate; - d_ptr->q_ptr = this; - - d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this); - connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty *, double)), - this, SLOT(slotDoubleChanged(QtProperty *, double))); - connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty *)), - this, SLOT(slotPropertyDestroyed(QtProperty *))); -} - -/*! - Destroys this manager, and all the properties it has created. -*/ -QtSizeFPropertyManager::~QtSizeFPropertyManager() -{ - clear(); - delete d_ptr; -} - -/*! - Returns the manager that creates the nested \e width and \e height - subproperties. - - In order to provide editing widgets for the \e width and \e height - properties in a property browser widget, this manager must be - associated with an editor factory. - - \sa QtAbstractPropertyBrowser::setFactoryForManager() -*/ -QtDoublePropertyManager *QtSizeFPropertyManager::subDoublePropertyManager() const -{ - return d_ptr->m_doublePropertyManager; -} - -/*! - Returns the given \a property's value. - - If the given \a property is not managed by this manager, this - function returns an invalid size - - \sa setValue() -*/ -QSizeF QtSizeFPropertyManager::value(const QtProperty *property) const -{ - return getValue(d_ptr->m_values, property); -} - -/*! - Returns the given \a property's precision, in decimals. - - \sa setDecimals() -*/ -int QtSizeFPropertyManager::decimals(const QtProperty *property) const -{ - return getData(d_ptr->m_values, &QtSizeFPropertyManagerPrivate::Data::decimals, property, 0); -} - -/*! - Returns the given \a property's minimum size value. - - \sa setMinimum(), maximum(), setRange() -*/ -QSizeF QtSizeFPropertyManager::minimum(const QtProperty *property) const -{ - return getMinimum(d_ptr->m_values, property); -} - -/*! - Returns the given \a property's maximum size value. - - \sa setMaximum(), minimum(), setRange() -*/ -QSizeF QtSizeFPropertyManager::maximum(const QtProperty *property) const -{ - return getMaximum(d_ptr->m_values, property); -} - -/*! - \reimp -*/ -QString QtSizeFPropertyManager::valueText(const QtProperty *property) const -{ - const QtSizeFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QString(); - const QSizeF v = it.value().val; - const int dec = it.value().decimals; - return QString(tr("%1 x %2").arg(QString::number(v.width(), 'f', dec)) - .arg(QString::number(v.height(), 'f', dec))); -} - -/*! - \fn void QtSizeFPropertyManager::setValue(QtProperty *property, const QSizeF &value) - - Sets the value of the given \a property to \a value. - - If the specified \a value is not valid according to the given \a - property's size range, the \a value is adjusted to the nearest - valid value within the size range. - - \sa value(), setRange(), valueChanged() -*/ -void QtSizeFPropertyManager::setValue(QtProperty *property, const QSizeF &val) -{ - setValueInRange(this, d_ptr, - &QtSizeFPropertyManager::propertyChanged, - &QtSizeFPropertyManager::valueChanged, - property, val, &QtSizeFPropertyManagerPrivate::setValue); -} - -/*! - \fn void QtSizeFPropertyManager::setDecimals(QtProperty *property, int prec) - - Sets the precision of the given \a property to \a prec. - - The valid decimal range is 0-13. The default is 2. - - \sa decimals() -*/ -void QtSizeFPropertyManager::setDecimals(QtProperty *property, int prec) -{ - const QtSizeFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); - if (it == d_ptr->m_values.end()) - return; - - QtSizeFPropertyManagerPrivate::Data data = it.value(); - - if (prec > 13) - prec = 13; - else if (prec < 0) - prec = 0; - - if (data.decimals == prec) - return; - - data.decimals = prec; - d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToW[property], prec); - d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToH[property], prec); - - it.value() = data; - - emit decimalsChanged(property, data.decimals); -} - -/*! - Sets the minimum size value for the given \a property to \a minVal. - - When setting the minimum size value, the maximum and current - values are adjusted if necessary (ensuring that the size range - remains valid and that the current value is within the range). - - \sa minimum(), setRange(), rangeChanged() -*/ -void QtSizeFPropertyManager::setMinimum(QtProperty *property, const QSizeF &minVal) -{ - setBorderValue(this, d_ptr, - &QtSizeFPropertyManager::propertyChanged, - &QtSizeFPropertyManager::valueChanged, - &QtSizeFPropertyManager::rangeChanged, - property, - &QtSizeFPropertyManagerPrivate::Data::minimumValue, - &QtSizeFPropertyManagerPrivate::Data::setMinimumValue, - minVal, &QtSizeFPropertyManagerPrivate::setRange); -} - -/*! - Sets the maximum size value for the given \a property to \a maxVal. - - When setting the maximum size value, the minimum and current - values are adjusted if necessary (ensuring that the size range - remains valid and that the current value is within the range). - - \sa maximum(), setRange(), rangeChanged() -*/ -void QtSizeFPropertyManager::setMaximum(QtProperty *property, const QSizeF &maxVal) -{ - setBorderValue(this, d_ptr, - &QtSizeFPropertyManager::propertyChanged, - &QtSizeFPropertyManager::valueChanged, - &QtSizeFPropertyManager::rangeChanged, - property, - &QtSizeFPropertyManagerPrivate::Data::maximumValue, - &QtSizeFPropertyManagerPrivate::Data::setMaximumValue, - maxVal, &QtSizeFPropertyManagerPrivate::setRange); -} - -/*! - \fn void QtSizeFPropertyManager::setRange(QtProperty *property, const QSizeF &minimum, const QSizeF &maximum) - - Sets the range of valid values. - - This is a convenience function defining the range of valid values - in one go; setting the \a minimum and \a maximum values for the - given \a property with a single function call. - - When setting a new range, the current value is adjusted if - necessary (ensuring that the value remains within the range). - - \sa setMinimum(), setMaximum(), rangeChanged() -*/ -void QtSizeFPropertyManager::setRange(QtProperty *property, const QSizeF &minVal, const QSizeF &maxVal) -{ - setBorderValues(this, d_ptr, - &QtSizeFPropertyManager::propertyChanged, - &QtSizeFPropertyManager::valueChanged, - &QtSizeFPropertyManager::rangeChanged, - property, minVal, maxVal, &QtSizeFPropertyManagerPrivate::setRange); -} - -/*! - \reimp -*/ -void QtSizeFPropertyManager::initializeProperty(QtProperty *property) -{ - d_ptr->m_values[property] = QtSizeFPropertyManagerPrivate::Data(); - - QtProperty *wProp = d_ptr->m_doublePropertyManager->addProperty(); - wProp->setPropertyName(tr("Width")); - d_ptr->m_doublePropertyManager->setDecimals(wProp, decimals(property)); - d_ptr->m_doublePropertyManager->setValue(wProp, 0); - d_ptr->m_doublePropertyManager->setMinimum(wProp, 0); - d_ptr->m_propertyToW[property] = wProp; - d_ptr->m_wToProperty[wProp] = property; - property->addSubProperty(wProp); - - QtProperty *hProp = d_ptr->m_doublePropertyManager->addProperty(); - hProp->setPropertyName(tr("Height")); - d_ptr->m_doublePropertyManager->setDecimals(hProp, decimals(property)); - d_ptr->m_doublePropertyManager->setValue(hProp, 0); - d_ptr->m_doublePropertyManager->setMinimum(hProp, 0); - d_ptr->m_propertyToH[property] = hProp; - d_ptr->m_hToProperty[hProp] = property; - property->addSubProperty(hProp); -} - -/*! - \reimp -*/ -void QtSizeFPropertyManager::uninitializeProperty(QtProperty *property) -{ - QtProperty *wProp = d_ptr->m_propertyToW[property]; - if (wProp) { - d_ptr->m_wToProperty.remove(wProp); - delete wProp; - } - d_ptr->m_propertyToW.remove(property); - - QtProperty *hProp = d_ptr->m_propertyToH[property]; - if (hProp) { - d_ptr->m_hToProperty.remove(hProp); - delete hProp; - } - d_ptr->m_propertyToH.remove(property); - - d_ptr->m_values.remove(property); -} - -// QtRectPropertyManager - -class QtRectPropertyManagerPrivate -{ - QtRectPropertyManager *q_ptr; - Q_DECLARE_PUBLIC(QtRectPropertyManager) -public: - - void slotIntChanged(QtProperty *property, int value); - void slotPropertyDestroyed(QtProperty *property); - void setConstraint(QtProperty *property, const QRect &constraint, const QRect &val); - - struct Data - { - Data() : val(0, 0, 0, 0) {} - QRect val; - QRect constraint; - }; - - typedef QMap PropertyValueMap; - PropertyValueMap m_values; - - QtIntPropertyManager *m_intPropertyManager; - - QMap m_propertyToX; - QMap m_propertyToY; - QMap m_propertyToW; - QMap m_propertyToH; - - QMap m_xToProperty; - QMap m_yToProperty; - QMap m_wToProperty; - QMap m_hToProperty; -}; - -void QtRectPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value) -{ - if (QtProperty *prop = m_xToProperty.value(property, 0)) { - QRect r = m_values[prop].val; - r.moveLeft(value); - q_ptr->setValue(prop, r); - } else if (QtProperty *prop = m_yToProperty.value(property)) { - QRect r = m_values[prop].val; - r.moveTop(value); - q_ptr->setValue(prop, r); - } else if (QtProperty *prop = m_wToProperty.value(property, 0)) { - Data data = m_values[prop]; - QRect r = data.val; - r.setWidth(value); - if (!data.constraint.isNull() && data.constraint.x() + data.constraint.width() < r.x() + r.width()) { - r.moveLeft(data.constraint.left() + data.constraint.width() - r.width()); - } - q_ptr->setValue(prop, r); - } else if (QtProperty *prop = m_hToProperty.value(property, 0)) { - Data data = m_values[prop]; - QRect r = data.val; - r.setHeight(value); - if (!data.constraint.isNull() && data.constraint.y() + data.constraint.height() < r.y() + r.height()) { - r.moveTop(data.constraint.top() + data.constraint.height() - r.height()); - } - q_ptr->setValue(prop, r); - } -} - -void QtRectPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) -{ - if (QtProperty *pointProp = m_xToProperty.value(property, 0)) { - m_propertyToX[pointProp] = 0; - m_xToProperty.remove(property); - } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) { - m_propertyToY[pointProp] = 0; - m_yToProperty.remove(property); - } else if (QtProperty *pointProp = m_wToProperty.value(property, 0)) { - m_propertyToW[pointProp] = 0; - m_wToProperty.remove(property); - } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) { - m_propertyToH[pointProp] = 0; - m_hToProperty.remove(property); - } -} - -void QtRectPropertyManagerPrivate::setConstraint(QtProperty *property, - const QRect &constraint, const QRect &val) -{ - const bool isNull = constraint.isNull(); - const int left = isNull ? INT_MIN : constraint.left(); - const int right = isNull ? INT_MAX : constraint.left() + constraint.width(); - const int top = isNull ? INT_MIN : constraint.top(); - const int bottom = isNull ? INT_MAX : constraint.top() + constraint.height(); - const int width = isNull ? INT_MAX : constraint.width(); - const int height = isNull ? INT_MAX : constraint.height(); - - m_intPropertyManager->setRange(m_propertyToX[property], left, right); - m_intPropertyManager->setRange(m_propertyToY[property], top, bottom); - m_intPropertyManager->setRange(m_propertyToW[property], 0, width); - m_intPropertyManager->setRange(m_propertyToH[property], 0, height); - - m_intPropertyManager->setValue(m_propertyToX[property], val.x()); - m_intPropertyManager->setValue(m_propertyToY[property], val.y()); - m_intPropertyManager->setValue(m_propertyToW[property], val.width()); - m_intPropertyManager->setValue(m_propertyToH[property], val.height()); -} - -/*! - \class QtRectPropertyManager - - \brief The QtRectPropertyManager provides and manages QRect properties. - - A rectangle property has nested \e x, \e y, \e width and \e height - subproperties. The top-level property's value can be retrieved - using the value() function, and set using the setValue() slot. - - The subproperties are created by a QtIntPropertyManager object. This - manager can be retrieved using the subIntPropertyManager() function. In - order to provide editing widgets for the subproperties in a - property browser widget, this manager must be associated with an - editor factory. - - A rectangle property also has a constraint rectangle which can be - retrieved using the constraint() function, and set using the - setConstraint() slot. - - In addition, QtRectPropertyManager provides the valueChanged() signal - which is emitted whenever a property created by this manager - changes, and the constraintChanged() signal which is emitted - whenever such a property changes its constraint rectangle. - - \sa QtAbstractPropertyManager, QtIntPropertyManager, QtRectFPropertyManager -*/ - -/*! - \fn void QtRectPropertyManager::valueChanged(QtProperty *property, const QRect &value) - - This signal is emitted whenever a property created by this manager - changes its value, passing a pointer to the \a property and the new - \a value as parameters. - - \sa setValue() -*/ - -/*! - \fn void QtRectPropertyManager::constraintChanged(QtProperty *property, const QRect &constraint) - - This signal is emitted whenever property changes its constraint - rectangle, passing a pointer to the \a property and the new \a - constraint rectangle as parameters. - - \sa setConstraint() -*/ - -/*! - Creates a manager with the given \a parent. -*/ -QtRectPropertyManager::QtRectPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) -{ - d_ptr = new QtRectPropertyManagerPrivate; - d_ptr->q_ptr = this; - - d_ptr->m_intPropertyManager = new QtIntPropertyManager(this); - connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotIntChanged(QtProperty *, int))); - connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)), - this, SLOT(slotPropertyDestroyed(QtProperty *))); -} - -/*! - Destroys this manager, and all the properties it has created. -*/ -QtRectPropertyManager::~QtRectPropertyManager() -{ - clear(); - delete d_ptr; -} - -/*! - Returns the manager that creates the nested \e x, \e y, \e width - and \e height subproperties. - - In order to provide editing widgets for the mentioned - subproperties in a property browser widget, this manager must be - associated with an editor factory. - - \sa QtAbstractPropertyBrowser::setFactoryForManager() -*/ -QtIntPropertyManager *QtRectPropertyManager::subIntPropertyManager() const -{ - return d_ptr->m_intPropertyManager; -} - -/*! - Returns the given \a property's value. - - If the given \a property is not managed by this manager, this - function returns an invalid rectangle. - - \sa setValue(), constraint() -*/ -QRect QtRectPropertyManager::value(const QtProperty *property) const -{ - return getValue(d_ptr->m_values, property); -} - -/*! - Returns the given \a property's constraining rectangle. If returned value is null QRect it means there is no constraint applied. - - \sa value(), setConstraint() -*/ -QRect QtRectPropertyManager::constraint(const QtProperty *property) const -{ - return getData(d_ptr->m_values, &QtRectPropertyManagerPrivate::Data::constraint, property, QRect()); -} - -/*! - \reimp -*/ -QString QtRectPropertyManager::valueText(const QtProperty *property) const -{ - const QtRectPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QString(); - const QRect v = it.value().val; - return QString(tr("[(%1, %2), %3 x %4]").arg(QString::number(v.x())) - .arg(QString::number(v.y())) - .arg(QString::number(v.width())) - .arg(QString::number(v.height()))); -} - -/*! - \fn void QtRectPropertyManager::setValue(QtProperty *property, const QRect &value) - - Sets the value of the given \a property to \a value. Nested - properties are updated automatically. - - If the specified \a value is not inside the given \a property's - constraining rectangle, the value is adjusted accordingly to fit - within the constraint. - - \sa value(), setConstraint(), valueChanged() -*/ -void QtRectPropertyManager::setValue(QtProperty *property, const QRect &val) -{ - const QtRectPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); - if (it == d_ptr->m_values.end()) - return; - - QtRectPropertyManagerPrivate::Data data = it.value(); - - QRect newRect = val.normalized(); - if (!data.constraint.isNull() && !data.constraint.contains(newRect)) { - const QRect r1 = data.constraint; - const QRect r2 = newRect; - newRect.setLeft(qMax(r1.left(), r2.left())); - newRect.setRight(qMin(r1.right(), r2.right())); - newRect.setTop(qMax(r1.top(), r2.top())); - newRect.setBottom(qMin(r1.bottom(), r2.bottom())); - if (newRect.width() < 0 || newRect.height() < 0) - return; - } - - if (data.val == newRect) - return; - - data.val = newRect; - - it.value() = data; - d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToX[property], newRect.x()); - d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToY[property], newRect.y()); - d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToW[property], newRect.width()); - d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToH[property], newRect.height()); - - emit propertyChanged(property); - emit valueChanged(property, data.val); -} - -/*! - Sets the given \a property's constraining rectangle to \a - constraint. - - When setting the constraint, the current value is adjusted if - necessary (ensuring that the current rectangle value is inside the - constraint). In order to reset the constraint pass a null QRect value. - - \sa setValue(), constraint(), constraintChanged() -*/ -void QtRectPropertyManager::setConstraint(QtProperty *property, const QRect &constraint) -{ - const QtRectPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); - if (it == d_ptr->m_values.end()) - return; - - QtRectPropertyManagerPrivate::Data data = it.value(); - - QRect newConstraint = constraint.normalized(); - if (data.constraint == newConstraint) - return; - - const QRect oldVal = data.val; - - data.constraint = newConstraint; - - if (!data.constraint.isNull() && !data.constraint.contains(oldVal)) { - QRect r1 = data.constraint; - QRect r2 = data.val; - - if (r2.width() > r1.width()) - r2.setWidth(r1.width()); - if (r2.height() > r1.height()) - r2.setHeight(r1.height()); - if (r2.left() < r1.left()) - r2.moveLeft(r1.left()); - else if (r2.right() > r1.right()) - r2.moveRight(r1.right()); - if (r2.top() < r1.top()) - r2.moveTop(r1.top()); - else if (r2.bottom() > r1.bottom()) - r2.moveBottom(r1.bottom()); - - data.val = r2; - } - - it.value() = data; - - emit constraintChanged(property, data.constraint); - - d_ptr->setConstraint(property, data.constraint, data.val); - - if (data.val == oldVal) - return; - - emit propertyChanged(property); - emit valueChanged(property, data.val); -} - -/*! - \reimp -*/ -void QtRectPropertyManager::initializeProperty(QtProperty *property) -{ - d_ptr->m_values[property] = QtRectPropertyManagerPrivate::Data(); - - QtProperty *xProp = d_ptr->m_intPropertyManager->addProperty(); - xProp->setPropertyName(tr("X")); - d_ptr->m_intPropertyManager->setValue(xProp, 0); - d_ptr->m_propertyToX[property] = xProp; - d_ptr->m_xToProperty[xProp] = property; - property->addSubProperty(xProp); - - QtProperty *yProp = d_ptr->m_intPropertyManager->addProperty(); - yProp->setPropertyName(tr("Y")); - d_ptr->m_intPropertyManager->setValue(yProp, 0); - d_ptr->m_propertyToY[property] = yProp; - d_ptr->m_yToProperty[yProp] = property; - property->addSubProperty(yProp); - - QtProperty *wProp = d_ptr->m_intPropertyManager->addProperty(); - wProp->setPropertyName(tr("Width")); - d_ptr->m_intPropertyManager->setValue(wProp, 0); - d_ptr->m_intPropertyManager->setMinimum(wProp, 0); - d_ptr->m_propertyToW[property] = wProp; - d_ptr->m_wToProperty[wProp] = property; - property->addSubProperty(wProp); - - QtProperty *hProp = d_ptr->m_intPropertyManager->addProperty(); - hProp->setPropertyName(tr("Height")); - d_ptr->m_intPropertyManager->setValue(hProp, 0); - d_ptr->m_intPropertyManager->setMinimum(hProp, 0); - d_ptr->m_propertyToH[property] = hProp; - d_ptr->m_hToProperty[hProp] = property; - property->addSubProperty(hProp); -} - -/*! - \reimp -*/ -void QtRectPropertyManager::uninitializeProperty(QtProperty *property) -{ - QtProperty *xProp = d_ptr->m_propertyToX[property]; - if (xProp) { - d_ptr->m_xToProperty.remove(xProp); - delete xProp; - } - d_ptr->m_propertyToX.remove(property); - - QtProperty *yProp = d_ptr->m_propertyToY[property]; - if (yProp) { - d_ptr->m_yToProperty.remove(yProp); - delete yProp; - } - d_ptr->m_propertyToY.remove(property); - - QtProperty *wProp = d_ptr->m_propertyToW[property]; - if (wProp) { - d_ptr->m_wToProperty.remove(wProp); - delete wProp; - } - d_ptr->m_propertyToW.remove(property); - - QtProperty *hProp = d_ptr->m_propertyToH[property]; - if (hProp) { - d_ptr->m_hToProperty.remove(hProp); - delete hProp; - } - d_ptr->m_propertyToH.remove(property); - - d_ptr->m_values.remove(property); -} - -// QtRectFPropertyManager - -class QtRectFPropertyManagerPrivate -{ - QtRectFPropertyManager *q_ptr; - Q_DECLARE_PUBLIC(QtRectFPropertyManager) -public: - - void slotDoubleChanged(QtProperty *property, double value); - void slotPropertyDestroyed(QtProperty *property); - void setConstraint(QtProperty *property, const QRectF &constraint, const QRectF &val); - - struct Data - { - Data() : val(0, 0, 0, 0), decimals(2) {} - QRectF val; - QRectF constraint; - int decimals; - }; - - typedef QMap PropertyValueMap; - PropertyValueMap m_values; - - QtDoublePropertyManager *m_doublePropertyManager; - - QMap m_propertyToX; - QMap m_propertyToY; - QMap m_propertyToW; - QMap m_propertyToH; - - QMap m_xToProperty; - QMap m_yToProperty; - QMap m_wToProperty; - QMap m_hToProperty; -}; - -void QtRectFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value) -{ - if (QtProperty *prop = m_xToProperty.value(property, 0)) { - QRectF r = m_values[prop].val; - r.moveLeft(value); - q_ptr->setValue(prop, r); - } else if (QtProperty *prop = m_yToProperty.value(property, 0)) { - QRectF r = m_values[prop].val; - r.moveTop(value); - q_ptr->setValue(prop, r); - } else if (QtProperty *prop = m_wToProperty.value(property, 0)) { - Data data = m_values[prop]; - QRectF r = data.val; - r.setWidth(value); - if (!data.constraint.isNull() && data.constraint.x() + data.constraint.width() < r.x() + r.width()) { - r.moveLeft(data.constraint.left() + data.constraint.width() - r.width()); - } - q_ptr->setValue(prop, r); - } else if (QtProperty *prop = m_hToProperty.value(property, 0)) { - Data data = m_values[prop]; - QRectF r = data.val; - r.setHeight(value); - if (!data.constraint.isNull() && data.constraint.y() + data.constraint.height() < r.y() + r.height()) { - r.moveTop(data.constraint.top() + data.constraint.height() - r.height()); - } - q_ptr->setValue(prop, r); - } -} - -void QtRectFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) -{ - if (QtProperty *pointProp = m_xToProperty.value(property, 0)) { - m_propertyToX[pointProp] = 0; - m_xToProperty.remove(property); - } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) { - m_propertyToY[pointProp] = 0; - m_yToProperty.remove(property); - } else if (QtProperty *pointProp = m_wToProperty.value(property, 0)) { - m_propertyToW[pointProp] = 0; - m_wToProperty.remove(property); - } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) { - m_propertyToH[pointProp] = 0; - m_hToProperty.remove(property); - } -} - -void QtRectFPropertyManagerPrivate::setConstraint(QtProperty *property, - const QRectF &constraint, const QRectF &val) -{ - const bool isNull = constraint.isNull(); - const float left = isNull ? FLT_MIN : constraint.left(); - const float right = isNull ? FLT_MAX : constraint.left() + constraint.width(); - const float top = isNull ? FLT_MIN : constraint.top(); - const float bottom = isNull ? FLT_MAX : constraint.top() + constraint.height(); - const float width = isNull ? FLT_MAX : constraint.width(); - const float height = isNull ? FLT_MAX : constraint.height(); - - m_doublePropertyManager->setRange(m_propertyToX[property], left, right); - m_doublePropertyManager->setRange(m_propertyToY[property], top, bottom); - m_doublePropertyManager->setRange(m_propertyToW[property], 0, width); - m_doublePropertyManager->setRange(m_propertyToH[property], 0, height); - - m_doublePropertyManager->setValue(m_propertyToX[property], val.x()); - m_doublePropertyManager->setValue(m_propertyToY[property], val.y()); - m_doublePropertyManager->setValue(m_propertyToW[property], val.width()); - m_doublePropertyManager->setValue(m_propertyToH[property], val.height()); -} - -/*! - \class QtRectFPropertyManager - - \brief The QtRectFPropertyManager provides and manages QRectF properties. - - A rectangle property has nested \e x, \e y, \e width and \e height - subproperties. The top-level property's value can be retrieved - using the value() function, and set using the setValue() slot. - - The subproperties are created by a QtDoublePropertyManager object. This - manager can be retrieved using the subDoublePropertyManager() function. In - order to provide editing widgets for the subproperties in a - property browser widget, this manager must be associated with an - editor factory. - - A rectangle property also has a constraint rectangle which can be - retrieved using the constraint() function, and set using the - setConstraint() slot. - - In addition, QtRectFPropertyManager provides the valueChanged() signal - which is emitted whenever a property created by this manager - changes, and the constraintChanged() signal which is emitted - whenever such a property changes its constraint rectangle. - - \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtRectPropertyManager -*/ - -/*! - \fn void QtRectFPropertyManager::valueChanged(QtProperty *property, const QRectF &value) - - This signal is emitted whenever a property created by this manager - changes its value, passing a pointer to the \a property and the new - \a value as parameters. - - \sa setValue() -*/ - -/*! - \fn void QtRectFPropertyManager::constraintChanged(QtProperty *property, const QRectF &constraint) - - This signal is emitted whenever property changes its constraint - rectangle, passing a pointer to the \a property and the new \a - constraint rectangle as parameters. - - \sa setConstraint() -*/ - -/*! - \fn void QtRectFPropertyManager::decimalsChanged(QtProperty *property, int prec) - - This signal is emitted whenever a property created by this manager - changes its precision of value, passing a pointer to the - \a property and the new \a prec value - - \sa setDecimals() -*/ - -/*! - Creates a manager with the given \a parent. -*/ -QtRectFPropertyManager::QtRectFPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) -{ - d_ptr = new QtRectFPropertyManagerPrivate; - d_ptr->q_ptr = this; - - d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this); - connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty *, double)), - this, SLOT(slotDoubleChanged(QtProperty *, double))); - connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty *)), - this, SLOT(slotPropertyDestroyed(QtProperty *))); -} - -/*! - Destroys this manager, and all the properties it has created. -*/ -QtRectFPropertyManager::~QtRectFPropertyManager() -{ - clear(); - delete d_ptr; -} - -/*! - Returns the manager that creates the nested \e x, \e y, \e width - and \e height subproperties. - - In order to provide editing widgets for the mentioned - subproperties in a property browser widget, this manager must be - associated with an editor factory. - - \sa QtAbstractPropertyBrowser::setFactoryForManager() -*/ -QtDoublePropertyManager *QtRectFPropertyManager::subDoublePropertyManager() const -{ - return d_ptr->m_doublePropertyManager; -} - -/*! - Returns the given \a property's value. - - If the given \a property is not managed by this manager, this - function returns an invalid rectangle. - - \sa setValue(), constraint() -*/ -QRectF QtRectFPropertyManager::value(const QtProperty *property) const -{ - return getValue(d_ptr->m_values, property); -} - -/*! - Returns the given \a property's precision, in decimals. - - \sa setDecimals() -*/ -int QtRectFPropertyManager::decimals(const QtProperty *property) const -{ - return getData(d_ptr->m_values, &QtRectFPropertyManagerPrivate::Data::decimals, property, 0); -} - -/*! - Returns the given \a property's constraining rectangle. If returned value is null QRectF it means there is no constraint applied. - - \sa value(), setConstraint() -*/ -QRectF QtRectFPropertyManager::constraint(const QtProperty *property) const -{ - return getData(d_ptr->m_values, &QtRectFPropertyManagerPrivate::Data::constraint, property, QRect()); -} - -/*! - \reimp -*/ -QString QtRectFPropertyManager::valueText(const QtProperty *property) const -{ - const QtRectFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QString(); - const QRectF v = it.value().val; - const int dec = it.value().decimals; - return QString(tr("[(%1, %2), %3 x %4]").arg(QString::number(v.x(), 'f', dec)) - .arg(QString::number(v.y(), 'f', dec)) - .arg(QString::number(v.width(), 'f', dec)) - .arg(QString::number(v.height(), 'f', dec))); -} - -/*! - \fn void QtRectFPropertyManager::setValue(QtProperty *property, const QRectF &value) - - Sets the value of the given \a property to \a value. Nested - properties are updated automatically. - - If the specified \a value is not inside the given \a property's - constraining rectangle, the value is adjusted accordingly to fit - within the constraint. - - \sa value(), setConstraint(), valueChanged() -*/ -void QtRectFPropertyManager::setValue(QtProperty *property, const QRectF &val) -{ - const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); - if (it == d_ptr->m_values.end()) - return; - - QtRectFPropertyManagerPrivate::Data data = it.value(); - - QRectF newRect = val.normalized(); - if (!data.constraint.isNull() && !data.constraint.contains(newRect)) { - const QRectF r1 = data.constraint; - const QRectF r2 = newRect; - newRect.setLeft(qMax(r1.left(), r2.left())); - newRect.setRight(qMin(r1.right(), r2.right())); - newRect.setTop(qMax(r1.top(), r2.top())); - newRect.setBottom(qMin(r1.bottom(), r2.bottom())); - if (newRect.width() < 0 || newRect.height() < 0) - return; - } - - if (data.val == newRect) - return; - - data.val = newRect; - - it.value() = data; - d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToX[property], newRect.x()); - d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToY[property], newRect.y()); - d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToW[property], newRect.width()); - d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToH[property], newRect.height()); - - emit propertyChanged(property); - emit valueChanged(property, data.val); -} - -/*! - Sets the given \a property's constraining rectangle to \a - constraint. - - When setting the constraint, the current value is adjusted if - necessary (ensuring that the current rectangle value is inside the - constraint). In order to reset the constraint pass a null QRectF value. - - \sa setValue(), constraint(), constraintChanged() -*/ -void QtRectFPropertyManager::setConstraint(QtProperty *property, const QRectF &constraint) -{ - const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); - if (it == d_ptr->m_values.end()) - return; - - QtRectFPropertyManagerPrivate::Data data = it.value(); - - QRectF newConstraint = constraint.normalized(); - if (data.constraint == newConstraint) - return; - - const QRectF oldVal = data.val; - - data.constraint = newConstraint; - - if (!data.constraint.isNull() && !data.constraint.contains(oldVal)) { - QRectF r1 = data.constraint; - QRectF r2 = data.val; - - if (r2.width() > r1.width()) - r2.setWidth(r1.width()); - if (r2.height() > r1.height()) - r2.setHeight(r1.height()); - if (r2.left() < r1.left()) - r2.moveLeft(r1.left()); - else if (r2.right() > r1.right()) - r2.moveRight(r1.right()); - if (r2.top() < r1.top()) - r2.moveTop(r1.top()); - else if (r2.bottom() > r1.bottom()) - r2.moveBottom(r1.bottom()); - - data.val = r2; - } - - it.value() = data; - - emit constraintChanged(property, data.constraint); - - d_ptr->setConstraint(property, data.constraint, data.val); - - if (data.val == oldVal) - return; - - emit propertyChanged(property); - emit valueChanged(property, data.val); -} - -/*! - \fn void QtRectFPropertyManager::setDecimals(QtProperty *property, int prec) - - Sets the precision of the given \a property to \a prec. - - The valid decimal range is 0-13. The default is 2. - - \sa decimals() -*/ -void QtRectFPropertyManager::setDecimals(QtProperty *property, int prec) -{ - const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); - if (it == d_ptr->m_values.end()) - return; - - QtRectFPropertyManagerPrivate::Data data = it.value(); - - if (prec > 13) - prec = 13; - else if (prec < 0) - prec = 0; - - if (data.decimals == prec) - return; - - data.decimals = prec; - d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToX[property], prec); - d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToY[property], prec); - d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToW[property], prec); - d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToH[property], prec); - - it.value() = data; - - emit decimalsChanged(property, data.decimals); -} - -/*! - \reimp -*/ -void QtRectFPropertyManager::initializeProperty(QtProperty *property) -{ - d_ptr->m_values[property] = QtRectFPropertyManagerPrivate::Data(); - - QtProperty *xProp = d_ptr->m_doublePropertyManager->addProperty(); - xProp->setPropertyName(tr("X")); - d_ptr->m_doublePropertyManager->setDecimals(xProp, decimals(property)); - d_ptr->m_doublePropertyManager->setValue(xProp, 0); - d_ptr->m_propertyToX[property] = xProp; - d_ptr->m_xToProperty[xProp] = property; - property->addSubProperty(xProp); - - QtProperty *yProp = d_ptr->m_doublePropertyManager->addProperty(); - yProp->setPropertyName(tr("Y")); - d_ptr->m_doublePropertyManager->setDecimals(yProp, decimals(property)); - d_ptr->m_doublePropertyManager->setValue(yProp, 0); - d_ptr->m_propertyToY[property] = yProp; - d_ptr->m_yToProperty[yProp] = property; - property->addSubProperty(yProp); - - QtProperty *wProp = d_ptr->m_doublePropertyManager->addProperty(); - wProp->setPropertyName(tr("Width")); - d_ptr->m_doublePropertyManager->setDecimals(wProp, decimals(property)); - d_ptr->m_doublePropertyManager->setValue(wProp, 0); - d_ptr->m_doublePropertyManager->setMinimum(wProp, 0); - d_ptr->m_propertyToW[property] = wProp; - d_ptr->m_wToProperty[wProp] = property; - property->addSubProperty(wProp); - - QtProperty *hProp = d_ptr->m_doublePropertyManager->addProperty(); - hProp->setPropertyName(tr("Height")); - d_ptr->m_doublePropertyManager->setDecimals(hProp, decimals(property)); - d_ptr->m_doublePropertyManager->setValue(hProp, 0); - d_ptr->m_doublePropertyManager->setMinimum(hProp, 0); - d_ptr->m_propertyToH[property] = hProp; - d_ptr->m_hToProperty[hProp] = property; - property->addSubProperty(hProp); -} - -/*! - \reimp -*/ -void QtRectFPropertyManager::uninitializeProperty(QtProperty *property) -{ - QtProperty *xProp = d_ptr->m_propertyToX[property]; - if (xProp) { - d_ptr->m_xToProperty.remove(xProp); - delete xProp; - } - d_ptr->m_propertyToX.remove(property); - - QtProperty *yProp = d_ptr->m_propertyToY[property]; - if (yProp) { - d_ptr->m_yToProperty.remove(yProp); - delete yProp; - } - d_ptr->m_propertyToY.remove(property); - - QtProperty *wProp = d_ptr->m_propertyToW[property]; - if (wProp) { - d_ptr->m_wToProperty.remove(wProp); - delete wProp; - } - d_ptr->m_propertyToW.remove(property); - - QtProperty *hProp = d_ptr->m_propertyToH[property]; - if (hProp) { - d_ptr->m_hToProperty.remove(hProp); - delete hProp; - } - d_ptr->m_propertyToH.remove(property); - - d_ptr->m_values.remove(property); -} - -// QtEnumPropertyManager - -class QtEnumPropertyManagerPrivate -{ - QtEnumPropertyManager *q_ptr; - Q_DECLARE_PUBLIC(QtEnumPropertyManager) -public: - - struct Data - { - Data() : val(-1) {} - int val; - QStringList enumNames; - QMap enumIcons; - }; - - typedef QMap PropertyValueMap; - PropertyValueMap m_values; -}; - -/*! - \class QtEnumPropertyManager - - \brief The QtEnumPropertyManager provides and manages enum properties. - - Each enum property has an associated list of enum names which can - be retrieved using the enumNames() function, and set using the - corresponding setEnumNames() function. An enum property's value is - represented by an index in this list, and can be retrieved and set - using the value() and setValue() slots respectively. - - Each enum value can also have an associated icon. The mapping from - values to icons can be set using the setEnumIcons() function and - queried with the enumIcons() function. - - In addition, QtEnumPropertyManager provides the valueChanged() signal - which is emitted whenever a property created by this manager - changes. The enumNamesChanged() or enumIconsChanged() signal is emitted - whenever the list of enum names or icons is altered. - - \sa QtAbstractPropertyManager, QtEnumEditorFactory -*/ - -/*! - \fn void QtEnumPropertyManager::valueChanged(QtProperty *property, int value) - - This signal is emitted whenever a property created by this manager - changes its value, passing a pointer to the \a property and the new - \a value as parameters. - - \sa setValue() -*/ - -/*! - \fn void QtEnumPropertyManager::enumNamesChanged(QtProperty *property, const QStringList &names) - - This signal is emitted whenever a property created by this manager - changes its enum names, passing a pointer to the \a property and - the new \a names as parameters. - - \sa setEnumNames() -*/ - -/*! - \fn void QtEnumPropertyManager::enumIconsChanged(QtProperty *property, const QMap &icons) - - This signal is emitted whenever a property created by this manager - changes its enum icons, passing a pointer to the \a property and - the new mapping of values to \a icons as parameters. - - \sa setEnumIcons() -*/ - -/*! - Creates a manager with the given \a parent. -*/ -QtEnumPropertyManager::QtEnumPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) -{ - d_ptr = new QtEnumPropertyManagerPrivate; - d_ptr->q_ptr = this; -} - -/*! - Destroys this manager, and all the properties it has created. -*/ -QtEnumPropertyManager::~QtEnumPropertyManager() -{ - clear(); - delete d_ptr; -} - -/*! - Returns the given \a property's value which is an index in the - list returned by enumNames() - - If the given property is not managed by this manager, this - function returns -1. - - \sa enumNames(), setValue() -*/ -int QtEnumPropertyManager::value(const QtProperty *property) const -{ - return getValue(d_ptr->m_values, property, -1); -} - -/*! - Returns the given \a property's list of enum names. - - \sa value(), setEnumNames() -*/ -QStringList QtEnumPropertyManager::enumNames(const QtProperty *property) const -{ - return getData(d_ptr->m_values, &QtEnumPropertyManagerPrivate::Data::enumNames, property, QStringList()); -} - -/*! - Returns the given \a property's map of enum values to their icons. - - \sa value(), setEnumIcons() -*/ -QMap QtEnumPropertyManager::enumIcons(const QtProperty *property) const -{ - return getData >(d_ptr->m_values, &QtEnumPropertyManagerPrivate::Data::enumIcons, property, QMap()); -} - -/*! - \reimp -*/ -QString QtEnumPropertyManager::valueText(const QtProperty *property) const -{ - const QtEnumPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QString(); - - const QtEnumPropertyManagerPrivate::Data &data = it.value(); - - const int v = data.val; - if (v >= 0 && v < data.enumNames.count()) - return data.enumNames.at(v); - return QString(); -} - -/*! - \reimp -*/ -QIcon QtEnumPropertyManager::valueIcon(const QtProperty *property) const -{ - const QtEnumPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QIcon(); - - const QtEnumPropertyManagerPrivate::Data &data = it.value(); - - const int v = data.val; - return data.enumIcons.value(v); -} - -/*! - \fn void QtEnumPropertyManager::setValue(QtProperty *property, int value) - - Sets the value of the given \a property to \a value. - - The specified \a value must be less than the size of the given \a - property's enumNames() list, and larger than (or equal to) 0. - - \sa value(), valueChanged() -*/ -void QtEnumPropertyManager::setValue(QtProperty *property, int val) -{ - const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); - if (it == d_ptr->m_values.end()) - return; - - QtEnumPropertyManagerPrivate::Data data = it.value(); - - if (val >= data.enumNames.count()) - return; - - if (val < 0 && data.enumNames.count() > 0) - return; - - if (val < 0) - val = -1; - - if (data.val == val) - return; - - data.val = val; - - it.value() = data; - - emit propertyChanged(property); - emit valueChanged(property, data.val); -} - -/*! - Sets the given \a property's list of enum names to \a - enumNames. The \a property's current value is reset to 0 - indicating the first item of the list. - - If the specified \a enumNames list is empty, the \a property's - current value is set to -1. - - \sa enumNames(), enumNamesChanged() -*/ -void QtEnumPropertyManager::setEnumNames(QtProperty *property, const QStringList &enumNames) -{ - const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); - if (it == d_ptr->m_values.end()) - return; - - QtEnumPropertyManagerPrivate::Data data = it.value(); - - if (data.enumNames == enumNames) - return; - - data.enumNames = enumNames; - - data.val = -1; - - if (enumNames.count() > 0) - data.val = 0; - - it.value() = data; - - emit enumNamesChanged(property, data.enumNames); - - emit propertyChanged(property); - emit valueChanged(property, data.val); -} - -/*! - Sets the given \a property's map of enum values to their icons to \a - enumIcons. - - Each enum value can have associated icon. This association is represented with passed \a enumIcons map. - - \sa enumNames(), enumNamesChanged() -*/ -void QtEnumPropertyManager::setEnumIcons(QtProperty *property, const QMap &enumIcons) -{ - const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); - if (it == d_ptr->m_values.end()) - return; - - it.value().enumIcons = enumIcons; - - emit enumIconsChanged(property, it.value().enumIcons); - - emit propertyChanged(property); -} - -/*! - \reimp -*/ -void QtEnumPropertyManager::initializeProperty(QtProperty *property) -{ - d_ptr->m_values[property] = QtEnumPropertyManagerPrivate::Data(); -} - -/*! - \reimp -*/ -void QtEnumPropertyManager::uninitializeProperty(QtProperty *property) -{ - d_ptr->m_values.remove(property); -} - -// QtFlagPropertyManager - -class QtFlagPropertyManagerPrivate -{ - QtFlagPropertyManager *q_ptr; - Q_DECLARE_PUBLIC(QtFlagPropertyManager) -public: - - void slotBoolChanged(QtProperty *property, bool value); - void slotPropertyDestroyed(QtProperty *property); - - struct Data - { - Data() : val(-1) {} - int val; - QStringList flagNames; - }; - - typedef QMap PropertyValueMap; - PropertyValueMap m_values; - - QtBoolPropertyManager *m_boolPropertyManager; - - QMap > m_propertyToFlags; - - QMap m_flagToProperty; -}; - -void QtFlagPropertyManagerPrivate::slotBoolChanged(QtProperty *property, bool value) -{ - QtProperty *prop = m_flagToProperty.value(property, 0); - if (prop == 0) - return; - - QListIterator itProp(m_propertyToFlags[prop]); - int level = 0; - while (itProp.hasNext()) { - QtProperty *p = itProp.next(); - if (p == property) { - int v = m_values[prop].val; - if (value) { - v |= (1 << level); - } else { - v &= ~(1 << level); - } - q_ptr->setValue(prop, v); - return; - } - level++; - } -} - -void QtFlagPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) -{ - QtProperty *flagProperty = m_flagToProperty.value(property, 0); - if (flagProperty == 0) - return; - - m_propertyToFlags[flagProperty].replace(m_propertyToFlags[flagProperty].indexOf(property), 0); - m_flagToProperty.remove(property); -} - -/*! - \class QtFlagPropertyManager - - \brief The QtFlagPropertyManager provides and manages flag properties. - - Each flag property has an associated list of flag names which can - be retrieved using the flagNames() function, and set using the - corresponding setFlagNames() function. - - The flag manager provides properties with nested boolean - subproperties representing each flag, i.e. a flag property's value - is the binary combination of the subproperties' values. A - property's value can be retrieved and set using the value() and - setValue() slots respectively. The combination of flags is represented - by single int value - that's why it's possible to store up to - 32 independent flags in one flag property. - - The subproperties are created by a QtBoolPropertyManager object. This - manager can be retrieved using the subBoolPropertyManager() function. In - order to provide editing widgets for the subproperties in a - property browser widget, this manager must be associated with an - editor factory. - - In addition, QtFlagPropertyManager provides the valueChanged() signal - which is emitted whenever a property created by this manager - changes, and the flagNamesChanged() signal which is emitted - whenever the list of flag names is altered. - - \sa QtAbstractPropertyManager, QtBoolPropertyManager -*/ - -/*! - \fn void QtFlagPropertyManager::valueChanged(QtProperty *property, int value) - - This signal is emitted whenever a property created by this manager - changes its value, passing a pointer to the \a property and the new - \a value as parameters. - - \sa setValue() -*/ - -/*! - \fn void QtFlagPropertyManager::flagNamesChanged(QtProperty *property, const QStringList &names) - - This signal is emitted whenever a property created by this manager - changes its flag names, passing a pointer to the \a property and the - new \a names as parameters. - - \sa setFlagNames() -*/ - -/*! - Creates a manager with the given \a parent. -*/ -QtFlagPropertyManager::QtFlagPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) -{ - d_ptr = new QtFlagPropertyManagerPrivate; - d_ptr->q_ptr = this; - - d_ptr->m_boolPropertyManager = new QtBoolPropertyManager(this); - connect(d_ptr->m_boolPropertyManager, SIGNAL(valueChanged(QtProperty *, bool)), - this, SLOT(slotBoolChanged(QtProperty *, bool))); - connect(d_ptr->m_boolPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)), - this, SLOT(slotPropertyDestroyed(QtProperty *))); -} - -/*! - Destroys this manager, and all the properties it has created. -*/ -QtFlagPropertyManager::~QtFlagPropertyManager() -{ - clear(); - delete d_ptr; -} - -/*! - Returns the manager that produces the nested boolean subproperties - representing each flag. - - In order to provide editing widgets for the subproperties in a - property browser widget, this manager must be associated with an - editor factory. - - \sa QtAbstractPropertyBrowser::setFactoryForManager() -*/ -QtBoolPropertyManager *QtFlagPropertyManager::subBoolPropertyManager() const -{ - return d_ptr->m_boolPropertyManager; -} - -/*! - Returns the given \a property's value. - - If the given property is not managed by this manager, this - function returns 0. - - \sa flagNames(), setValue() -*/ -int QtFlagPropertyManager::value(const QtProperty *property) const -{ - return getValue(d_ptr->m_values, property, 0); -} - -/*! - Returns the given \a property's list of flag names. - - \sa value(), setFlagNames() -*/ -QStringList QtFlagPropertyManager::flagNames(const QtProperty *property) const -{ - return getData(d_ptr->m_values, &QtFlagPropertyManagerPrivate::Data::flagNames, property, QStringList()); -} - -/*! - \reimp -*/ -QString QtFlagPropertyManager::valueText(const QtProperty *property) const -{ - const QtFlagPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QString(); - - const QtFlagPropertyManagerPrivate::Data &data = it.value(); - - QString str; - int level = 0; - const QChar bar = QLatin1Char('|'); - const QStringList::const_iterator fncend = data.flagNames.constEnd(); - for (QStringList::const_iterator it = data.flagNames.constBegin(); it != fncend; ++it) { - if (data.val & (1 << level)) { - if (!str.isEmpty()) - str += bar; - str += *it; - } - - level++; - } - return str; -} - -/*! - \fn void QtFlagPropertyManager::setValue(QtProperty *property, int value) - - Sets the value of the given \a property to \a value. Nested - properties are updated automatically. - - The specified \a value must be less than the binary combination of - the property's flagNames() list size (i.e. less than 2\sup n, - where \c n is the size of the list) and larger than (or equal to) - 0. - - \sa value(), valueChanged() -*/ -void QtFlagPropertyManager::setValue(QtProperty *property, int val) -{ - const QtFlagPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); - if (it == d_ptr->m_values.end()) - return; - - QtFlagPropertyManagerPrivate::Data data = it.value(); - - if (data.val == val) - return; - - if (val > (1 << data.flagNames.count()) - 1) - return; - - if (val < 0) - return; - - data.val = val; - - it.value() = data; - - QListIterator itProp(d_ptr->m_propertyToFlags[property]); - int level = 0; - while (itProp.hasNext()) { - QtProperty *prop = itProp.next(); - if (prop) - d_ptr->m_boolPropertyManager->setValue(prop, val & (1 << level)); - level++; - } - - emit propertyChanged(property); - emit valueChanged(property, data.val); -} - -/*! - Sets the given \a property's list of flag names to \a flagNames. The - property's current value is reset to 0 indicating the first item - of the list. - - \sa flagNames(), flagNamesChanged() -*/ -void QtFlagPropertyManager::setFlagNames(QtProperty *property, const QStringList &flagNames) -{ - const QtFlagPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); - if (it == d_ptr->m_values.end()) - return; - - QtFlagPropertyManagerPrivate::Data data = it.value(); - - if (data.flagNames == flagNames) - return; - - data.flagNames = flagNames; - data.val = 0; - - it.value() = data; - - QListIterator itProp(d_ptr->m_propertyToFlags[property]); - while (itProp.hasNext()) { - QtProperty *prop = itProp.next(); - if (prop) { - delete prop; - d_ptr->m_flagToProperty.remove(prop); - } - } - d_ptr->m_propertyToFlags[property].clear(); - - QStringListIterator itFlag(flagNames); - while (itFlag.hasNext()) { - const QString flagName = itFlag.next(); - QtProperty *prop = d_ptr->m_boolPropertyManager->addProperty(); - prop->setPropertyName(flagName); - property->addSubProperty(prop); - d_ptr->m_propertyToFlags[property].append(prop); - d_ptr->m_flagToProperty[prop] = property; - } - - emit flagNamesChanged(property, data.flagNames); - - emit propertyChanged(property); - emit valueChanged(property, data.val); -} - -/*! - \reimp -*/ -void QtFlagPropertyManager::initializeProperty(QtProperty *property) -{ - d_ptr->m_values[property] = QtFlagPropertyManagerPrivate::Data(); - - d_ptr->m_propertyToFlags[property] = QList(); -} - -/*! - \reimp -*/ -void QtFlagPropertyManager::uninitializeProperty(QtProperty *property) -{ - QListIterator itProp(d_ptr->m_propertyToFlags[property]); - while (itProp.hasNext()) { - QtProperty *prop = itProp.next(); - if (prop) { - delete prop; - d_ptr->m_flagToProperty.remove(prop); - } - } - d_ptr->m_propertyToFlags.remove(property); - - d_ptr->m_values.remove(property); -} - -// QtSizePolicyPropertyManager - -class QtSizePolicyPropertyManagerPrivate -{ - QtSizePolicyPropertyManager *q_ptr; - Q_DECLARE_PUBLIC(QtSizePolicyPropertyManager) -public: - - QtSizePolicyPropertyManagerPrivate(); - - void slotIntChanged(QtProperty *property, int value); - void slotEnumChanged(QtProperty *property, int value); - void slotPropertyDestroyed(QtProperty *property); - - typedef QMap PropertyValueMap; - PropertyValueMap m_values; - - QtIntPropertyManager *m_intPropertyManager; - QtEnumPropertyManager *m_enumPropertyManager; - - QMap m_propertyToHPolicy; - QMap m_propertyToVPolicy; - QMap m_propertyToHStretch; - QMap m_propertyToVStretch; - - QMap m_hPolicyToProperty; - QMap m_vPolicyToProperty; - QMap m_hStretchToProperty; - QMap m_vStretchToProperty; -}; - -QtSizePolicyPropertyManagerPrivate::QtSizePolicyPropertyManagerPrivate() -{ -} - -void QtSizePolicyPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value) -{ - if (QtProperty *prop = m_hStretchToProperty.value(property, 0)) { - QSizePolicy sp = m_values[prop]; - sp.setHorizontalStretch(value); - q_ptr->setValue(prop, sp); - } else if (QtProperty *prop = m_vStretchToProperty.value(property, 0)) { - QSizePolicy sp = m_values[prop]; - sp.setVerticalStretch(value); - q_ptr->setValue(prop, sp); - } -} - -void QtSizePolicyPropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value) -{ - if (QtProperty *prop = m_hPolicyToProperty.value(property, 0)) { - QSizePolicy sp = m_values[prop]; - sp.setHorizontalPolicy(metaEnumProvider()->indexToSizePolicy(value)); - q_ptr->setValue(prop, sp); - } else if (QtProperty *prop = m_vPolicyToProperty.value(property, 0)) { - QSizePolicy sp = m_values[prop]; - sp.setVerticalPolicy(metaEnumProvider()->indexToSizePolicy(value)); - q_ptr->setValue(prop, sp); - } -} - -void QtSizePolicyPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) -{ - if (QtProperty *pointProp = m_hStretchToProperty.value(property, 0)) { - m_propertyToHStretch[pointProp] = 0; - m_hStretchToProperty.remove(property); - } else if (QtProperty *pointProp = m_vStretchToProperty.value(property, 0)) { - m_propertyToVStretch[pointProp] = 0; - m_vStretchToProperty.remove(property); - } else if (QtProperty *pointProp = m_hPolicyToProperty.value(property, 0)) { - m_propertyToHPolicy[pointProp] = 0; - m_hPolicyToProperty.remove(property); - } else if (QtProperty *pointProp = m_vPolicyToProperty.value(property, 0)) { - m_propertyToVPolicy[pointProp] = 0; - m_vPolicyToProperty.remove(property); - } -} - -/*! - \class QtSizePolicyPropertyManager - - \brief The QtSizePolicyPropertyManager provides and manages QSizePolicy properties. - - A size policy property has nested \e horizontalPolicy, \e - verticalPolicy, \e horizontalStretch and \e verticalStretch - subproperties. The top-level property's value can be retrieved - using the value() function, and set using the setValue() slot. - - The subproperties are created by QtIntPropertyManager and QtEnumPropertyManager - objects. These managers can be retrieved using the subIntPropertyManager() - and subEnumPropertyManager() functions respectively. In order to provide - editing widgets for the subproperties in a property browser widget, - these managers must be associated with editor factories. - - In addition, QtSizePolicyPropertyManager provides the valueChanged() - signal which is emitted whenever a property created by this - manager changes. - - \sa QtAbstractPropertyManager, QtIntPropertyManager, QtEnumPropertyManager -*/ - -/*! - \fn void QtSizePolicyPropertyManager::valueChanged(QtProperty *property, const QSizePolicy &value) - - This signal is emitted whenever a property created by this manager - changes its value, passing a pointer to the \a property and the - new \a value as parameters. - - \sa setValue() -*/ - -/*! - Creates a manager with the given \a parent. -*/ -QtSizePolicyPropertyManager::QtSizePolicyPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) -{ - d_ptr = new QtSizePolicyPropertyManagerPrivate; - d_ptr->q_ptr = this; - - d_ptr->m_intPropertyManager = new QtIntPropertyManager(this); - connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotIntChanged(QtProperty *, int))); - d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this); - connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotEnumChanged(QtProperty *, int))); - - connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)), - this, SLOT(slotPropertyDestroyed(QtProperty *))); - connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)), - this, SLOT(slotPropertyDestroyed(QtProperty *))); -} - -/*! - Destroys this manager, and all the properties it has created. -*/ -QtSizePolicyPropertyManager::~QtSizePolicyPropertyManager() -{ - clear(); - delete d_ptr; -} - -/*! - Returns the manager that creates the nested \e horizontalStretch - and \e verticalStretch subproperties. - - In order to provide editing widgets for the mentioned subproperties - in a property browser widget, this manager must be associated with - an editor factory. - - \sa QtAbstractPropertyBrowser::setFactoryForManager() -*/ -QtIntPropertyManager *QtSizePolicyPropertyManager::subIntPropertyManager() const -{ - return d_ptr->m_intPropertyManager; -} - -/*! - Returns the manager that creates the nested \e horizontalPolicy - and \e verticalPolicy subproperties. - - In order to provide editing widgets for the mentioned subproperties - in a property browser widget, this manager must be associated with - an editor factory. - - \sa QtAbstractPropertyBrowser::setFactoryForManager() -*/ -QtEnumPropertyManager *QtSizePolicyPropertyManager::subEnumPropertyManager() const -{ - return d_ptr->m_enumPropertyManager; -} - -/*! - Returns the given \a property's value. - - If the given property is not managed by this manager, this - function returns the default size policy. - - \sa setValue() -*/ -QSizePolicy QtSizePolicyPropertyManager::value(const QtProperty *property) const -{ - return d_ptr->m_values.value(property, QSizePolicy()); -} - -/*! - \reimp -*/ -QString QtSizePolicyPropertyManager::valueText(const QtProperty *property) const -{ - const QtSizePolicyPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QString(); - - const QSizePolicy sp = it.value(); - const QtMetaEnumProvider *mep = metaEnumProvider(); - const int hIndex = mep->sizePolicyToIndex(sp.horizontalPolicy()); - const int vIndex = mep->sizePolicyToIndex(sp.verticalPolicy()); - //! Unknown size policy on reading invalid uic3 files - const QString hPolicy = hIndex != -1 ? mep->policyEnumNames().at(hIndex) : tr(""); - const QString vPolicy = vIndex != -1 ? mep->policyEnumNames().at(vIndex) : tr(""); - const QString str = tr("[%1, %2, %3, %4]").arg(hPolicy, vPolicy).arg(sp.horizontalStretch()).arg(sp.verticalStretch()); - return str; -} - -/*! - \fn void QtSizePolicyPropertyManager::setValue(QtProperty *property, const QSizePolicy &value) - - Sets the value of the given \a property to \a value. Nested - properties are updated automatically. - - \sa value(), valueChanged() -*/ -void QtSizePolicyPropertyManager::setValue(QtProperty *property, const QSizePolicy &val) -{ - const QtSizePolicyPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); - if (it == d_ptr->m_values.end()) - return; - - if (it.value() == val) - return; - - it.value() = val; - - d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToHPolicy[property], - metaEnumProvider()->sizePolicyToIndex(val.horizontalPolicy())); - d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToVPolicy[property], - metaEnumProvider()->sizePolicyToIndex(val.verticalPolicy())); - d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToHStretch[property], - val.horizontalStretch()); - d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToVStretch[property], - val.verticalStretch()); - - emit propertyChanged(property); - emit valueChanged(property, val); -} - -/*! - \reimp -*/ -void QtSizePolicyPropertyManager::initializeProperty(QtProperty *property) -{ - QSizePolicy val; - d_ptr->m_values[property] = val; - - QtProperty *hPolicyProp = d_ptr->m_enumPropertyManager->addProperty(); - hPolicyProp->setPropertyName(tr("Horizontal Policy")); - d_ptr->m_enumPropertyManager->setEnumNames(hPolicyProp, metaEnumProvider()->policyEnumNames()); - d_ptr->m_enumPropertyManager->setValue(hPolicyProp, - metaEnumProvider()->sizePolicyToIndex(val.horizontalPolicy())); - d_ptr->m_propertyToHPolicy[property] = hPolicyProp; - d_ptr->m_hPolicyToProperty[hPolicyProp] = property; - property->addSubProperty(hPolicyProp); - - QtProperty *vPolicyProp = d_ptr->m_enumPropertyManager->addProperty(); - vPolicyProp->setPropertyName(tr("Vertical Policy")); - d_ptr->m_enumPropertyManager->setEnumNames(vPolicyProp, metaEnumProvider()->policyEnumNames()); - d_ptr->m_enumPropertyManager->setValue(vPolicyProp, - metaEnumProvider()->sizePolicyToIndex(val.verticalPolicy())); - d_ptr->m_propertyToVPolicy[property] = vPolicyProp; - d_ptr->m_vPolicyToProperty[vPolicyProp] = property; - property->addSubProperty(vPolicyProp); - - QtProperty *hStretchProp = d_ptr->m_intPropertyManager->addProperty(); - hStretchProp->setPropertyName(tr("Horizontal Stretch")); - d_ptr->m_intPropertyManager->setValue(hStretchProp, val.horizontalStretch()); - d_ptr->m_intPropertyManager->setRange(hStretchProp, 0, 0xff); - d_ptr->m_propertyToHStretch[property] = hStretchProp; - d_ptr->m_hStretchToProperty[hStretchProp] = property; - property->addSubProperty(hStretchProp); - - QtProperty *vStretchProp = d_ptr->m_intPropertyManager->addProperty(); - vStretchProp->setPropertyName(tr("Vertical Stretch")); - d_ptr->m_intPropertyManager->setValue(vStretchProp, val.verticalStretch()); - d_ptr->m_intPropertyManager->setRange(vStretchProp, 0, 0xff); - d_ptr->m_propertyToVStretch[property] = vStretchProp; - d_ptr->m_vStretchToProperty[vStretchProp] = property; - property->addSubProperty(vStretchProp); - -} - -/*! - \reimp -*/ -void QtSizePolicyPropertyManager::uninitializeProperty(QtProperty *property) -{ - QtProperty *hPolicyProp = d_ptr->m_propertyToHPolicy[property]; - if (hPolicyProp) { - d_ptr->m_hPolicyToProperty.remove(hPolicyProp); - delete hPolicyProp; - } - d_ptr->m_propertyToHPolicy.remove(property); - - QtProperty *vPolicyProp = d_ptr->m_propertyToVPolicy[property]; - if (vPolicyProp) { - d_ptr->m_vPolicyToProperty.remove(vPolicyProp); - delete vPolicyProp; - } - d_ptr->m_propertyToVPolicy.remove(property); - - QtProperty *hStretchProp = d_ptr->m_propertyToHStretch[property]; - if (hStretchProp) { - d_ptr->m_hStretchToProperty.remove(hStretchProp); - delete hStretchProp; - } - d_ptr->m_propertyToHStretch.remove(property); - - QtProperty *vStretchProp = d_ptr->m_propertyToVStretch[property]; - if (vStretchProp) { - d_ptr->m_vStretchToProperty.remove(vStretchProp); - delete vStretchProp; - } - d_ptr->m_propertyToVStretch.remove(property); - - d_ptr->m_values.remove(property); -} - -// QtFontPropertyManager: -// QtFontPropertyManagerPrivate has a mechanism for reacting -// to QApplication::fontDatabaseChanged() [4.5], which is emitted -// when someone loads an application font. The signals are compressed -// using a timer with interval 0, which then causes the family -// enumeration manager to re-set its strings and index values -// for each property. - -Q_GLOBAL_STATIC(QFontDatabase, fontDatabase) - -class QtFontPropertyManagerPrivate -{ - QtFontPropertyManager *q_ptr; - Q_DECLARE_PUBLIC(QtFontPropertyManager) -public: - - QtFontPropertyManagerPrivate(); - - void slotIntChanged(QtProperty *property, int value); - void slotEnumChanged(QtProperty *property, int value); - void slotBoolChanged(QtProperty *property, bool value); - void slotPropertyDestroyed(QtProperty *property); - void slotFontDatabaseChanged(); - void slotFontDatabaseDelayedChange(); - - QStringList m_familyNames; - - typedef QMap PropertyValueMap; - PropertyValueMap m_values; - - QtIntPropertyManager *m_intPropertyManager; - QtEnumPropertyManager *m_enumPropertyManager; - QtBoolPropertyManager *m_boolPropertyManager; - - QMap m_propertyToFamily; - QMap m_propertyToPointSize; - QMap m_propertyToBold; - QMap m_propertyToItalic; - QMap m_propertyToUnderline; - QMap m_propertyToStrikeOut; - QMap m_propertyToKerning; - - QMap m_familyToProperty; - QMap m_pointSizeToProperty; - QMap m_boldToProperty; - QMap m_italicToProperty; - QMap m_underlineToProperty; - QMap m_strikeOutToProperty; - QMap m_kerningToProperty; - - bool m_settingValue; - QTimer *m_fontDatabaseChangeTimer; -}; - -QtFontPropertyManagerPrivate::QtFontPropertyManagerPrivate() : - m_settingValue(false), - m_fontDatabaseChangeTimer(0) -{ -} - -void QtFontPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value) -{ - if (m_settingValue) - return; - if (QtProperty *prop = m_pointSizeToProperty.value(property, 0)) { - QFont f = m_values[prop]; - f.setPointSize(value); - q_ptr->setValue(prop, f); - } -} - -void QtFontPropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value) -{ - if (m_settingValue) - return; - if (QtProperty *prop = m_familyToProperty.value(property, 0)) { - QFont f = m_values[prop]; - f.setFamily(m_familyNames.at(value)); - q_ptr->setValue(prop, f); - } -} - -void QtFontPropertyManagerPrivate::slotBoolChanged(QtProperty *property, bool value) -{ - if (m_settingValue) - return; - if (QtProperty *prop = m_boldToProperty.value(property, 0)) { - QFont f = m_values[prop]; - f.setBold(value); - q_ptr->setValue(prop, f); - } else if (QtProperty *prop = m_italicToProperty.value(property, 0)) { - QFont f = m_values[prop]; - f.setItalic(value); - q_ptr->setValue(prop, f); - } else if (QtProperty *prop = m_underlineToProperty.value(property, 0)) { - QFont f = m_values[prop]; - f.setUnderline(value); - q_ptr->setValue(prop, f); - } else if (QtProperty *prop = m_strikeOutToProperty.value(property, 0)) { - QFont f = m_values[prop]; - f.setStrikeOut(value); - q_ptr->setValue(prop, f); - } else if (QtProperty *prop = m_kerningToProperty.value(property, 0)) { - QFont f = m_values[prop]; - f.setKerning(value); - q_ptr->setValue(prop, f); - } -} - -void QtFontPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) -{ - if (QtProperty *pointProp = m_pointSizeToProperty.value(property, 0)) { - m_propertyToPointSize[pointProp] = 0; - m_pointSizeToProperty.remove(property); - } else if (QtProperty *pointProp = m_familyToProperty.value(property, 0)) { - m_propertyToFamily[pointProp] = 0; - m_familyToProperty.remove(property); - } else if (QtProperty *pointProp = m_boldToProperty.value(property, 0)) { - m_propertyToBold[pointProp] = 0; - m_boldToProperty.remove(property); - } else if (QtProperty *pointProp = m_italicToProperty.value(property, 0)) { - m_propertyToItalic[pointProp] = 0; - m_italicToProperty.remove(property); - } else if (QtProperty *pointProp = m_underlineToProperty.value(property, 0)) { - m_propertyToUnderline[pointProp] = 0; - m_underlineToProperty.remove(property); - } else if (QtProperty *pointProp = m_strikeOutToProperty.value(property, 0)) { - m_propertyToStrikeOut[pointProp] = 0; - m_strikeOutToProperty.remove(property); - } else if (QtProperty *pointProp = m_kerningToProperty.value(property, 0)) { - m_propertyToKerning[pointProp] = 0; - m_kerningToProperty.remove(property); - } -} - -void QtFontPropertyManagerPrivate::slotFontDatabaseChanged() -{ - if (!m_fontDatabaseChangeTimer) { - m_fontDatabaseChangeTimer = new QTimer(q_ptr); - m_fontDatabaseChangeTimer->setInterval(0); - m_fontDatabaseChangeTimer->setSingleShot(true); - QObject::connect(m_fontDatabaseChangeTimer, SIGNAL(timeout()), q_ptr, SLOT(slotFontDatabaseDelayedChange())); - } - if (!m_fontDatabaseChangeTimer->isActive()) - m_fontDatabaseChangeTimer->start(); -} - -void QtFontPropertyManagerPrivate::slotFontDatabaseDelayedChange() -{ - typedef QMap PropertyPropertyMap; - // rescan available font names - const QStringList oldFamilies = m_familyNames; - m_familyNames = fontDatabase()->families(); - - // Adapt all existing properties - if (!m_propertyToFamily.empty()) { - PropertyPropertyMap::const_iterator cend = m_propertyToFamily.constEnd(); - for (PropertyPropertyMap::const_iterator it = m_propertyToFamily.constBegin(); it != cend; ++it) { - QtProperty *familyProp = it.value(); - const int oldIdx = m_enumPropertyManager->value(familyProp); - int newIdx = m_familyNames.indexOf(oldFamilies.at(oldIdx)); - if (newIdx < 0) - newIdx = 0; - m_enumPropertyManager->setEnumNames(familyProp, m_familyNames); - m_enumPropertyManager->setValue(familyProp, newIdx); - } - } -} - -/*! - \class QtFontPropertyManager - - \brief The QtFontPropertyManager provides and manages QFont properties. - - A font property has nested \e family, \e pointSize, \e bold, \e - italic, \e underline, \e strikeOut and \e kerning subproperties. The top-level - property's value can be retrieved using the value() function, and - set using the setValue() slot. - - The subproperties are created by QtIntPropertyManager, QtEnumPropertyManager and - QtBoolPropertyManager objects. These managers can be retrieved using the - corresponding subIntPropertyManager(), subEnumPropertyManager() and - subBoolPropertyManager() functions. In order to provide editing widgets - for the subproperties in a property browser widget, these managers - must be associated with editor factories. - - In addition, QtFontPropertyManager provides the valueChanged() signal - which is emitted whenever a property created by this manager - changes. - - \sa QtAbstractPropertyManager, QtEnumPropertyManager, QtIntPropertyManager, QtBoolPropertyManager -*/ - -/*! - \fn void QtFontPropertyManager::valueChanged(QtProperty *property, const QFont &value) - - This signal is emitted whenever a property created by this manager - changes its value, passing a pointer to the \a property and the - new \a value as parameters. - - \sa setValue() -*/ - -/*! - Creates a manager with the given \a parent. -*/ -QtFontPropertyManager::QtFontPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) -{ - d_ptr = new QtFontPropertyManagerPrivate; - d_ptr->q_ptr = this; -#if QT_VERSION >= 0x040500 - QObject::connect(qApp, SIGNAL(fontDatabaseChanged()), this, SLOT(slotFontDatabaseChanged())); -#endif - - d_ptr->m_intPropertyManager = new QtIntPropertyManager(this); - connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotIntChanged(QtProperty *, int))); - d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this); - connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotEnumChanged(QtProperty *, int))); - d_ptr->m_boolPropertyManager = new QtBoolPropertyManager(this); - connect(d_ptr->m_boolPropertyManager, SIGNAL(valueChanged(QtProperty *, bool)), - this, SLOT(slotBoolChanged(QtProperty *, bool))); - - connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)), - this, SLOT(slotPropertyDestroyed(QtProperty *))); - connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)), - this, SLOT(slotPropertyDestroyed(QtProperty *))); - connect(d_ptr->m_boolPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)), - this, SLOT(slotPropertyDestroyed(QtProperty *))); -} - -/*! - Destroys this manager, and all the properties it has created. -*/ -QtFontPropertyManager::~QtFontPropertyManager() -{ - clear(); - delete d_ptr; -} - -/*! - Returns the manager that creates the \e pointSize subproperty. - - In order to provide editing widgets for the \e pointSize property - in a property browser widget, this manager must be associated - with an editor factory. - - \sa QtAbstractPropertyBrowser::setFactoryForManager() -*/ -QtIntPropertyManager *QtFontPropertyManager::subIntPropertyManager() const -{ - return d_ptr->m_intPropertyManager; -} - -/*! - Returns the manager that create the \e family subproperty. - - In order to provide editing widgets for the \e family property - in a property browser widget, this manager must be associated - with an editor factory. - - \sa QtAbstractPropertyBrowser::setFactoryForManager() -*/ -QtEnumPropertyManager *QtFontPropertyManager::subEnumPropertyManager() const -{ - return d_ptr->m_enumPropertyManager; -} - -/*! - Returns the manager that creates the \e bold, \e italic, \e underline, - \e strikeOut and \e kerning subproperties. - - In order to provide editing widgets for the mentioned properties - in a property browser widget, this manager must be associated with - an editor factory. - - \sa QtAbstractPropertyBrowser::setFactoryForManager() -*/ -QtBoolPropertyManager *QtFontPropertyManager::subBoolPropertyManager() const -{ - return d_ptr->m_boolPropertyManager; -} - -/*! - Returns the given \a property's value. - - If the given property is not managed by this manager, this - function returns a font object that uses the application's default - font. - - \sa setValue() -*/ -QFont QtFontPropertyManager::value(const QtProperty *property) const -{ - return d_ptr->m_values.value(property, QFont()); -} - -/*! - \reimp -*/ -QString QtFontPropertyManager::valueText(const QtProperty *property) const -{ - const QtFontPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QString(); - - return QtPropertyBrowserUtils::fontValueText(it.value()); -} - -/*! - \reimp -*/ -QIcon QtFontPropertyManager::valueIcon(const QtProperty *property) const -{ - const QtFontPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QIcon(); - - return QtPropertyBrowserUtils::fontValueIcon(it.value()); -} - -/*! - \fn void QtFontPropertyManager::setValue(QtProperty *property, const QFont &value) - - Sets the value of the given \a property to \a value. Nested - properties are updated automatically. - - \sa value(), valueChanged() -*/ -void QtFontPropertyManager::setValue(QtProperty *property, const QFont &val) -{ - const QtFontPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); - if (it == d_ptr->m_values.end()) - return; - - const QFont oldVal = it.value(); - if (oldVal == val && oldVal.resolve() == val.resolve()) - return; - - it.value() = val; - - int idx = d_ptr->m_familyNames.indexOf(val.family()); - if (idx == -1) - idx = 0; - bool settingValue = d_ptr->m_settingValue; - d_ptr->m_settingValue = true; - d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToFamily[property], idx); - d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToPointSize[property], val.pointSize()); - d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToBold[property], val.bold()); - d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToItalic[property], val.italic()); - d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToUnderline[property], val.underline()); - d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToStrikeOut[property], val.strikeOut()); - d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToKerning[property], val.kerning()); - d_ptr->m_settingValue = settingValue; - - emit propertyChanged(property); - emit valueChanged(property, val); -} - -/*! - \reimp -*/ -void QtFontPropertyManager::initializeProperty(QtProperty *property) -{ - QFont val; - d_ptr->m_values[property] = val; - - QtProperty *familyProp = d_ptr->m_enumPropertyManager->addProperty(); - familyProp->setPropertyName(tr("Family")); - if (d_ptr->m_familyNames.empty()) - d_ptr->m_familyNames = fontDatabase()->families(); - d_ptr->m_enumPropertyManager->setEnumNames(familyProp, d_ptr->m_familyNames); - int idx = d_ptr->m_familyNames.indexOf(val.family()); - if (idx == -1) - idx = 0; - d_ptr->m_enumPropertyManager->setValue(familyProp, idx); - d_ptr->m_propertyToFamily[property] = familyProp; - d_ptr->m_familyToProperty[familyProp] = property; - property->addSubProperty(familyProp); - - QtProperty *pointSizeProp = d_ptr->m_intPropertyManager->addProperty(); - pointSizeProp->setPropertyName(tr("Point Size")); - d_ptr->m_intPropertyManager->setValue(pointSizeProp, val.pointSize()); - d_ptr->m_intPropertyManager->setMinimum(pointSizeProp, 1); - d_ptr->m_propertyToPointSize[property] = pointSizeProp; - d_ptr->m_pointSizeToProperty[pointSizeProp] = property; - property->addSubProperty(pointSizeProp); - - QtProperty *boldProp = d_ptr->m_boolPropertyManager->addProperty(); - boldProp->setPropertyName(tr("Bold")); - d_ptr->m_boolPropertyManager->setValue(boldProp, val.bold()); - d_ptr->m_propertyToBold[property] = boldProp; - d_ptr->m_boldToProperty[boldProp] = property; - property->addSubProperty(boldProp); - - QtProperty *italicProp = d_ptr->m_boolPropertyManager->addProperty(); - italicProp->setPropertyName(tr("Italic")); - d_ptr->m_boolPropertyManager->setValue(italicProp, val.italic()); - d_ptr->m_propertyToItalic[property] = italicProp; - d_ptr->m_italicToProperty[italicProp] = property; - property->addSubProperty(italicProp); - - QtProperty *underlineProp = d_ptr->m_boolPropertyManager->addProperty(); - underlineProp->setPropertyName(tr("Underline")); - d_ptr->m_boolPropertyManager->setValue(underlineProp, val.underline()); - d_ptr->m_propertyToUnderline[property] = underlineProp; - d_ptr->m_underlineToProperty[underlineProp] = property; - property->addSubProperty(underlineProp); - - QtProperty *strikeOutProp = d_ptr->m_boolPropertyManager->addProperty(); - strikeOutProp->setPropertyName(tr("Strikeout")); - d_ptr->m_boolPropertyManager->setValue(strikeOutProp, val.strikeOut()); - d_ptr->m_propertyToStrikeOut[property] = strikeOutProp; - d_ptr->m_strikeOutToProperty[strikeOutProp] = property; - property->addSubProperty(strikeOutProp); - - QtProperty *kerningProp = d_ptr->m_boolPropertyManager->addProperty(); - kerningProp->setPropertyName(tr("Kerning")); - d_ptr->m_boolPropertyManager->setValue(kerningProp, val.kerning()); - d_ptr->m_propertyToKerning[property] = kerningProp; - d_ptr->m_kerningToProperty[kerningProp] = property; - property->addSubProperty(kerningProp); -} - -/*! - \reimp -*/ -void QtFontPropertyManager::uninitializeProperty(QtProperty *property) -{ - QtProperty *familyProp = d_ptr->m_propertyToFamily[property]; - if (familyProp) { - d_ptr->m_familyToProperty.remove(familyProp); - delete familyProp; - } - d_ptr->m_propertyToFamily.remove(property); - - QtProperty *pointSizeProp = d_ptr->m_propertyToPointSize[property]; - if (pointSizeProp) { - d_ptr->m_pointSizeToProperty.remove(pointSizeProp); - delete pointSizeProp; - } - d_ptr->m_propertyToPointSize.remove(property); - - QtProperty *boldProp = d_ptr->m_propertyToBold[property]; - if (boldProp) { - d_ptr->m_boldToProperty.remove(boldProp); - delete boldProp; - } - d_ptr->m_propertyToBold.remove(property); - - QtProperty *italicProp = d_ptr->m_propertyToItalic[property]; - if (italicProp) { - d_ptr->m_italicToProperty.remove(italicProp); - delete italicProp; - } - d_ptr->m_propertyToItalic.remove(property); - - QtProperty *underlineProp = d_ptr->m_propertyToUnderline[property]; - if (underlineProp) { - d_ptr->m_underlineToProperty.remove(underlineProp); - delete underlineProp; - } - d_ptr->m_propertyToUnderline.remove(property); - - QtProperty *strikeOutProp = d_ptr->m_propertyToStrikeOut[property]; - if (strikeOutProp) { - d_ptr->m_strikeOutToProperty.remove(strikeOutProp); - delete strikeOutProp; - } - d_ptr->m_propertyToStrikeOut.remove(property); - - QtProperty *kerningProp = d_ptr->m_propertyToKerning[property]; - if (kerningProp) { - d_ptr->m_kerningToProperty.remove(kerningProp); - delete kerningProp; - } - d_ptr->m_propertyToKerning.remove(property); - - d_ptr->m_values.remove(property); -} - -// QtColorPropertyManager - -class QtColorPropertyManagerPrivate -{ - QtColorPropertyManager *q_ptr; - Q_DECLARE_PUBLIC(QtColorPropertyManager) -public: - - void slotIntChanged(QtProperty *property, int value); - void slotPropertyDestroyed(QtProperty *property); - - typedef QMap PropertyValueMap; - PropertyValueMap m_values; - - QtIntPropertyManager *m_intPropertyManager; - - QMap m_propertyToR; - QMap m_propertyToG; - QMap m_propertyToB; - QMap m_propertyToA; - - QMap m_rToProperty; - QMap m_gToProperty; - QMap m_bToProperty; - QMap m_aToProperty; -}; - -void QtColorPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value) -{ - if (QtProperty *prop = m_rToProperty.value(property, 0)) { - QColor c = m_values[prop]; - c.setRed(value); - q_ptr->setValue(prop, c); - } else if (QtProperty *prop = m_gToProperty.value(property, 0)) { - QColor c = m_values[prop]; - c.setGreen(value); - q_ptr->setValue(prop, c); - } else if (QtProperty *prop = m_bToProperty.value(property, 0)) { - QColor c = m_values[prop]; - c.setBlue(value); - q_ptr->setValue(prop, c); - } else if (QtProperty *prop = m_aToProperty.value(property, 0)) { - QColor c = m_values[prop]; - c.setAlpha(value); - q_ptr->setValue(prop, c); - } -} - -void QtColorPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) -{ - if (QtProperty *pointProp = m_rToProperty.value(property, 0)) { - m_propertyToR[pointProp] = 0; - m_rToProperty.remove(property); - } else if (QtProperty *pointProp = m_gToProperty.value(property, 0)) { - m_propertyToG[pointProp] = 0; - m_gToProperty.remove(property); - } else if (QtProperty *pointProp = m_bToProperty.value(property, 0)) { - m_propertyToB[pointProp] = 0; - m_bToProperty.remove(property); - } else if (QtProperty *pointProp = m_aToProperty.value(property, 0)) { - m_propertyToA[pointProp] = 0; - m_aToProperty.remove(property); - } -} - -/*! - \class QtColorPropertyManager - - \brief The QtColorPropertyManager provides and manages QColor properties. - - A color property has nested \e red, \e green and \e blue - subproperties. The top-level property's value can be retrieved - using the value() function, and set using the setValue() slot. - - The subproperties are created by a QtIntPropertyManager object. This - manager can be retrieved using the subIntPropertyManager() function. In - order to provide editing widgets for the subproperties in a - property browser widget, this manager must be associated with an - editor factory. - - In addition, QtColorPropertyManager provides the valueChanged() signal - which is emitted whenever a property created by this manager - changes. - - \sa QtAbstractPropertyManager, QtAbstractPropertyBrowser, QtIntPropertyManager -*/ - -/*! - \fn void QtColorPropertyManager::valueChanged(QtProperty *property, const QColor &value) - - This signal is emitted whenever a property created by this manager - changes its value, passing a pointer to the \a property and the new - \a value as parameters. - - \sa setValue() -*/ - -/*! - Creates a manager with the given \a parent. -*/ -QtColorPropertyManager::QtColorPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) -{ - d_ptr = new QtColorPropertyManagerPrivate; - d_ptr->q_ptr = this; - - d_ptr->m_intPropertyManager = new QtIntPropertyManager(this); - connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotIntChanged(QtProperty *, int))); - - connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)), - this, SLOT(slotPropertyDestroyed(QtProperty *))); -} - -/*! - Destroys this manager, and all the properties it has created. -*/ -QtColorPropertyManager::~QtColorPropertyManager() -{ - clear(); - delete d_ptr; -} - -/*! - Returns the manager that produces the nested \e red, \e green and - \e blue subproperties. - - In order to provide editing widgets for the subproperties in a - property browser widget, this manager must be associated with an - editor factory. - - \sa QtAbstractPropertyBrowser::setFactoryForManager() -*/ -QtIntPropertyManager *QtColorPropertyManager::subIntPropertyManager() const -{ - return d_ptr->m_intPropertyManager; -} - -/*! - Returns the given \a property's value. - - If the given \a property is not managed by \e this manager, this - function returns an invalid color. - - \sa setValue() -*/ -QColor QtColorPropertyManager::value(const QtProperty *property) const -{ - return d_ptr->m_values.value(property, QColor()); -} - -/*! - \reimp -*/ - -QString QtColorPropertyManager::valueText(const QtProperty *property) const -{ - const QtColorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QString(); - - return QtPropertyBrowserUtils::colorValueText(it.value()); -} - -/*! - \reimp -*/ - -QIcon QtColorPropertyManager::valueIcon(const QtProperty *property) const -{ - const QtColorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QIcon(); - return QtPropertyBrowserUtils::brushValueIcon(QBrush(it.value())); -} - -/*! - \fn void QtColorPropertyManager::setValue(QtProperty *property, const QColor &value) - - Sets the value of the given \a property to \a value. Nested - properties are updated automatically. - - \sa value(), valueChanged() -*/ -void QtColorPropertyManager::setValue(QtProperty *property, const QColor &val) -{ - const QtColorPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); - if (it == d_ptr->m_values.end()) - return; - - if (it.value() == val) - return; - - it.value() = val; - - d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToR[property], val.red()); - d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToG[property], val.green()); - d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToB[property], val.blue()); - d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToA[property], val.alpha()); - - emit propertyChanged(property); - emit valueChanged(property, val); -} - -/*! - \reimp -*/ -void QtColorPropertyManager::initializeProperty(QtProperty *property) -{ - QColor val; - d_ptr->m_values[property] = val; - - QtProperty *rProp = d_ptr->m_intPropertyManager->addProperty(); - rProp->setPropertyName(tr("Red")); - d_ptr->m_intPropertyManager->setValue(rProp, val.red()); - d_ptr->m_intPropertyManager->setRange(rProp, 0, 0xFF); - d_ptr->m_propertyToR[property] = rProp; - d_ptr->m_rToProperty[rProp] = property; - property->addSubProperty(rProp); - - QtProperty *gProp = d_ptr->m_intPropertyManager->addProperty(); - gProp->setPropertyName(tr("Green")); - d_ptr->m_intPropertyManager->setValue(gProp, val.green()); - d_ptr->m_intPropertyManager->setRange(gProp, 0, 0xFF); - d_ptr->m_propertyToG[property] = gProp; - d_ptr->m_gToProperty[gProp] = property; - property->addSubProperty(gProp); - - QtProperty *bProp = d_ptr->m_intPropertyManager->addProperty(); - bProp->setPropertyName(tr("Blue")); - d_ptr->m_intPropertyManager->setValue(bProp, val.blue()); - d_ptr->m_intPropertyManager->setRange(bProp, 0, 0xFF); - d_ptr->m_propertyToB[property] = bProp; - d_ptr->m_bToProperty[bProp] = property; - property->addSubProperty(bProp); - - QtProperty *aProp = d_ptr->m_intPropertyManager->addProperty(); - aProp->setPropertyName(tr("Alpha")); - d_ptr->m_intPropertyManager->setValue(aProp, val.alpha()); - d_ptr->m_intPropertyManager->setRange(aProp, 0, 0xFF); - d_ptr->m_propertyToA[property] = aProp; - d_ptr->m_aToProperty[aProp] = property; - property->addSubProperty(aProp); -} - -/*! - \reimp -*/ -void QtColorPropertyManager::uninitializeProperty(QtProperty *property) -{ - QtProperty *rProp = d_ptr->m_propertyToR[property]; - if (rProp) { - d_ptr->m_rToProperty.remove(rProp); - delete rProp; - } - d_ptr->m_propertyToR.remove(property); - - QtProperty *gProp = d_ptr->m_propertyToG[property]; - if (gProp) { - d_ptr->m_gToProperty.remove(gProp); - delete gProp; - } - d_ptr->m_propertyToG.remove(property); - - QtProperty *bProp = d_ptr->m_propertyToB[property]; - if (bProp) { - d_ptr->m_bToProperty.remove(bProp); - delete bProp; - } - d_ptr->m_propertyToB.remove(property); - - QtProperty *aProp = d_ptr->m_propertyToA[property]; - if (aProp) { - d_ptr->m_aToProperty.remove(aProp); - delete aProp; - } - d_ptr->m_propertyToA.remove(property); - - d_ptr->m_values.remove(property); -} - -// QtCursorPropertyManager - -Q_GLOBAL_STATIC(QtCursorDatabase, cursorDatabase) - -class QtCursorPropertyManagerPrivate -{ - QtCursorPropertyManager *q_ptr; - Q_DECLARE_PUBLIC(QtCursorPropertyManager) -public: - typedef QMap PropertyValueMap; - PropertyValueMap m_values; -}; - -/*! - \class QtCursorPropertyManager - - \brief The QtCursorPropertyManager provides and manages QCursor properties. - - A cursor property has a current value which can be - retrieved using the value() function, and set using the setValue() - slot. In addition, QtCursorPropertyManager provides the - valueChanged() signal which is emitted whenever a property created - by this manager changes. - - \sa QtAbstractPropertyManager -*/ - -/*! - \fn void QtCursorPropertyManager::valueChanged(QtProperty *property, const QCursor &value) - - This signal is emitted whenever a property created by this manager - changes its value, passing a pointer to the \a property and the new - \a value as parameters. - - \sa setValue() -*/ - -/*! - Creates a manager with the given \a parent. -*/ -QtCursorPropertyManager::QtCursorPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) -{ - d_ptr = new QtCursorPropertyManagerPrivate; - d_ptr->q_ptr = this; -} - -/*! - Destroys this manager, and all the properties it has created. -*/ -QtCursorPropertyManager::~QtCursorPropertyManager() -{ - clear(); - delete d_ptr; -} - -/*! - Returns the given \a property's value. - - If the given \a property is not managed by this manager, this - function returns a default QCursor object. - - \sa setValue() -*/ -#ifndef QT_NO_CURSOR -QCursor QtCursorPropertyManager::value(const QtProperty *property) const -{ - return d_ptr->m_values.value(property, QCursor()); -} -#endif - -/*! - \reimp -*/ -QString QtCursorPropertyManager::valueText(const QtProperty *property) const -{ - const QtCursorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QString(); - - return cursorDatabase()->cursorToShapeName(it.value()); -} - -/*! - \reimp -*/ -QIcon QtCursorPropertyManager::valueIcon(const QtProperty *property) const -{ - const QtCursorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); - if (it == d_ptr->m_values.constEnd()) - return QIcon(); - - return cursorDatabase()->cursorToShapeIcon(it.value()); -} - -/*! - \fn void QtCursorPropertyManager::setValue(QtProperty *property, const QCursor &value) - - Sets the value of the given \a property to \a value. - - \sa value(), valueChanged() -*/ -void QtCursorPropertyManager::setValue(QtProperty *property, const QCursor &value) -{ -#ifndef QT_NO_CURSOR - const QtCursorPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); - if (it == d_ptr->m_values.end()) - return; - - if (it.value().shape() == value.shape() && value.shape() != Qt::BitmapCursor) - return; - - it.value() = value; - - emit propertyChanged(property); - emit valueChanged(property, value); -#endif -} - -/*! - \reimp -*/ -void QtCursorPropertyManager::initializeProperty(QtProperty *property) -{ -#ifndef QT_NO_CURSOR - d_ptr->m_values[property] = QCursor(); -#endif -} - -/*! - \reimp -*/ -void QtCursorPropertyManager::uninitializeProperty(QtProperty *property) -{ - d_ptr->m_values.remove(property); -} - -#if QT_VERSION >= 0x040400 -QT_END_NAMESPACE -#endif - -#include "moc_qtpropertymanager.cxx" -#include "qtpropertymanager.moc" diff --git a/QtPropertyBrowser/qtpropertymanager.h b/QtPropertyBrowser/qtpropertymanager.h deleted file mode 100644 index 709f2abf77..0000000000 --- a/QtPropertyBrowser/qtpropertymanager.h +++ /dev/null @@ -1,796 +0,0 @@ -/**************************************************************************** -** -** This file is part of a Qt Solutions component. -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Solutions Commercial License Agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** Please note Third Party Software included with Qt Solutions may impose -** additional restrictions and it is the user's responsibility to ensure -** that they have met the licensing requirements of the GPL, LGPL, or Qt -** Solutions Commercial license and the relevant license of the Third -** Party Software they are using. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTPROPERTYMANAGER_H -#define QTPROPERTYMANAGER_H - -#include "qtpropertybrowser.h" - -#if QT_VERSION >= 0x040400 -QT_BEGIN_NAMESPACE -#endif - -class QDate; -class QTime; -class QDateTime; -class QLocale; - -class QT_QTPROPERTYBROWSER_EXPORT QtGroupPropertyManager : public QtAbstractPropertyManager -{ - Q_OBJECT -public: - QtGroupPropertyManager(QObject *parent = 0); - ~QtGroupPropertyManager(); - -protected: - virtual bool hasValue(const QtProperty *property) const; - - virtual void initializeProperty(QtProperty *property); - virtual void uninitializeProperty(QtProperty *property); -}; - -class QtIntPropertyManagerPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtIntPropertyManager : public QtAbstractPropertyManager -{ - Q_OBJECT -public: - QtIntPropertyManager(QObject *parent = 0); - ~QtIntPropertyManager(); - - int value(const QtProperty *property) const; - int minimum(const QtProperty *property) const; - int maximum(const QtProperty *property) const; - int singleStep(const QtProperty *property) const; - -public Q_SLOTS: - void setValue(QtProperty *property, int val); - void setMinimum(QtProperty *property, int minVal); - void setMaximum(QtProperty *property, int maxVal); - void setRange(QtProperty *property, int minVal, int maxVal); - void setSingleStep(QtProperty *property, int step); -Q_SIGNALS: - void valueChanged(QtProperty *property, int val); - void rangeChanged(QtProperty *property, int minVal, int maxVal); - void singleStepChanged(QtProperty *property, int step); -protected: - QString valueText(const QtProperty *property) const; - virtual void initializeProperty(QtProperty *property); - virtual void uninitializeProperty(QtProperty *property); -private: - QtIntPropertyManagerPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtIntPropertyManager) - Q_DISABLE_COPY(QtIntPropertyManager) -}; - -class QtBoolPropertyManagerPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtBoolPropertyManager : public QtAbstractPropertyManager -{ - Q_OBJECT -public: - QtBoolPropertyManager(QObject *parent = 0); - ~QtBoolPropertyManager(); - - bool value(const QtProperty *property) const; - -public Q_SLOTS: - void setValue(QtProperty *property, bool val); -Q_SIGNALS: - void valueChanged(QtProperty *property, bool val); -protected: - QString valueText(const QtProperty *property) const; - QIcon valueIcon(const QtProperty *property) const; - virtual void initializeProperty(QtProperty *property); - virtual void uninitializeProperty(QtProperty *property); -private: - QtBoolPropertyManagerPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtBoolPropertyManager) - Q_DISABLE_COPY(QtBoolPropertyManager) -}; - -class QtDoublePropertyManagerPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtDoublePropertyManager : public QtAbstractPropertyManager -{ - Q_OBJECT -public: - QtDoublePropertyManager(QObject *parent = 0); - ~QtDoublePropertyManager(); - - double value(const QtProperty *property) const; - double minimum(const QtProperty *property) const; - double maximum(const QtProperty *property) const; - double singleStep(const QtProperty *property) const; - int decimals(const QtProperty *property) const; - -public Q_SLOTS: - void setValue(QtProperty *property, double val); - void setMinimum(QtProperty *property, double minVal); - void setMaximum(QtProperty *property, double maxVal); - void setRange(QtProperty *property, double minVal, double maxVal); - void setSingleStep(QtProperty *property, double step); - void setDecimals(QtProperty *property, int prec); -Q_SIGNALS: - void valueChanged(QtProperty *property, double val); - void rangeChanged(QtProperty *property, double minVal, double maxVal); - void singleStepChanged(QtProperty *property, double step); - void decimalsChanged(QtProperty *property, int prec); -protected: - QString valueText(const QtProperty *property) const; - virtual void initializeProperty(QtProperty *property); - virtual void uninitializeProperty(QtProperty *property); -private: - QtDoublePropertyManagerPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtDoublePropertyManager) - Q_DISABLE_COPY(QtDoublePropertyManager) -}; - -class QtStringPropertyManagerPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtStringPropertyManager : public QtAbstractPropertyManager -{ - Q_OBJECT -public: - QtStringPropertyManager(QObject *parent = 0); - ~QtStringPropertyManager(); - - QString value(const QtProperty *property) const; - QRegExp regExp(const QtProperty *property) const; - -public Q_SLOTS: - void setValue(QtProperty *property, const QString &val); - void setRegExp(QtProperty *property, const QRegExp ®Exp); -Q_SIGNALS: - void valueChanged(QtProperty *property, const QString &val); - void regExpChanged(QtProperty *property, const QRegExp ®Exp); -protected: - QString valueText(const QtProperty *property) const; - virtual void initializeProperty(QtProperty *property); - virtual void uninitializeProperty(QtProperty *property); -private: - QtStringPropertyManagerPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtStringPropertyManager) - Q_DISABLE_COPY(QtStringPropertyManager) -}; - -class QtDatePropertyManagerPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtDatePropertyManager : public QtAbstractPropertyManager -{ - Q_OBJECT -public: - QtDatePropertyManager(QObject *parent = 0); - ~QtDatePropertyManager(); - - QDate value(const QtProperty *property) const; - QDate minimum(const QtProperty *property) const; - QDate maximum(const QtProperty *property) const; - -public Q_SLOTS: - void setValue(QtProperty *property, const QDate &val); - void setMinimum(QtProperty *property, const QDate &minVal); - void setMaximum(QtProperty *property, const QDate &maxVal); - void setRange(QtProperty *property, const QDate &minVal, const QDate &maxVal); -Q_SIGNALS: - void valueChanged(QtProperty *property, const QDate &val); - void rangeChanged(QtProperty *property, const QDate &minVal, const QDate &maxVal); -protected: - QString valueText(const QtProperty *property) const; - virtual void initializeProperty(QtProperty *property); - virtual void uninitializeProperty(QtProperty *property); -private: - QtDatePropertyManagerPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtDatePropertyManager) - Q_DISABLE_COPY(QtDatePropertyManager) -}; - -class QtTimePropertyManagerPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtTimePropertyManager : public QtAbstractPropertyManager -{ - Q_OBJECT -public: - QtTimePropertyManager(QObject *parent = 0); - ~QtTimePropertyManager(); - - QTime value(const QtProperty *property) const; - -public Q_SLOTS: - void setValue(QtProperty *property, const QTime &val); -Q_SIGNALS: - void valueChanged(QtProperty *property, const QTime &val); -protected: - QString valueText(const QtProperty *property) const; - virtual void initializeProperty(QtProperty *property); - virtual void uninitializeProperty(QtProperty *property); -private: - QtTimePropertyManagerPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtTimePropertyManager) - Q_DISABLE_COPY(QtTimePropertyManager) -}; - -class QtDateTimePropertyManagerPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtDateTimePropertyManager : public QtAbstractPropertyManager -{ - Q_OBJECT -public: - QtDateTimePropertyManager(QObject *parent = 0); - ~QtDateTimePropertyManager(); - - QDateTime value(const QtProperty *property) const; - -public Q_SLOTS: - void setValue(QtProperty *property, const QDateTime &val); -Q_SIGNALS: - void valueChanged(QtProperty *property, const QDateTime &val); -protected: - QString valueText(const QtProperty *property) const; - virtual void initializeProperty(QtProperty *property); - virtual void uninitializeProperty(QtProperty *property); -private: - QtDateTimePropertyManagerPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtDateTimePropertyManager) - Q_DISABLE_COPY(QtDateTimePropertyManager) -}; - -class QtKeySequencePropertyManagerPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtKeySequencePropertyManager : public QtAbstractPropertyManager -{ - Q_OBJECT -public: - QtKeySequencePropertyManager(QObject *parent = 0); - ~QtKeySequencePropertyManager(); - - QKeySequence value(const QtProperty *property) const; - -public Q_SLOTS: - void setValue(QtProperty *property, const QKeySequence &val); -Q_SIGNALS: - void valueChanged(QtProperty *property, const QKeySequence &val); -protected: - QString valueText(const QtProperty *property) const; - virtual void initializeProperty(QtProperty *property); - virtual void uninitializeProperty(QtProperty *property); -private: - QtKeySequencePropertyManagerPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtKeySequencePropertyManager) - Q_DISABLE_COPY(QtKeySequencePropertyManager) -}; - -class QtCharPropertyManagerPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtCharPropertyManager : public QtAbstractPropertyManager -{ - Q_OBJECT -public: - QtCharPropertyManager(QObject *parent = 0); - ~QtCharPropertyManager(); - - QChar value(const QtProperty *property) const; - -public Q_SLOTS: - void setValue(QtProperty *property, const QChar &val); -Q_SIGNALS: - void valueChanged(QtProperty *property, const QChar &val); -protected: - QString valueText(const QtProperty *property) const; - virtual void initializeProperty(QtProperty *property); - virtual void uninitializeProperty(QtProperty *property); -private: - QtCharPropertyManagerPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtCharPropertyManager) - Q_DISABLE_COPY(QtCharPropertyManager) -}; - -class QtEnumPropertyManager; -class QtLocalePropertyManagerPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtLocalePropertyManager : public QtAbstractPropertyManager -{ - Q_OBJECT -public: - QtLocalePropertyManager(QObject *parent = 0); - ~QtLocalePropertyManager(); - - QtEnumPropertyManager *subEnumPropertyManager() const; - - QLocale value(const QtProperty *property) const; - -public Q_SLOTS: - void setValue(QtProperty *property, const QLocale &val); -Q_SIGNALS: - void valueChanged(QtProperty *property, const QLocale &val); -protected: - QString valueText(const QtProperty *property) const; - virtual void initializeProperty(QtProperty *property); - virtual void uninitializeProperty(QtProperty *property); -private: - QtLocalePropertyManagerPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtLocalePropertyManager) - Q_DISABLE_COPY(QtLocalePropertyManager) - Q_PRIVATE_SLOT(d_func(), void slotEnumChanged(QtProperty *, int)) - Q_PRIVATE_SLOT(d_func(), void slotPropertyDestroyed(QtProperty *)) -}; - -class QtPointPropertyManagerPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtPointPropertyManager : public QtAbstractPropertyManager -{ - Q_OBJECT -public: - QtPointPropertyManager(QObject *parent = 0); - ~QtPointPropertyManager(); - - QtIntPropertyManager *subIntPropertyManager() const; - - QPoint value(const QtProperty *property) const; - -public Q_SLOTS: - void setValue(QtProperty *property, const QPoint &val); -Q_SIGNALS: - void valueChanged(QtProperty *property, const QPoint &val); -protected: - QString valueText(const QtProperty *property) const; - virtual void initializeProperty(QtProperty *property); - virtual void uninitializeProperty(QtProperty *property); -private: - QtPointPropertyManagerPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtPointPropertyManager) - Q_DISABLE_COPY(QtPointPropertyManager) - Q_PRIVATE_SLOT(d_func(), void slotIntChanged(QtProperty *, int)) - Q_PRIVATE_SLOT(d_func(), void slotPropertyDestroyed(QtProperty *)) -}; - -class QtPointFPropertyManagerPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtPointFPropertyManager : public QtAbstractPropertyManager -{ - Q_OBJECT -public: - QtPointFPropertyManager(QObject *parent = 0); - ~QtPointFPropertyManager(); - - QtDoublePropertyManager *subDoublePropertyManager() const; - - QPointF value(const QtProperty *property) const; - int decimals(const QtProperty *property) const; - -public Q_SLOTS: - void setValue(QtProperty *property, const QPointF &val); - void setDecimals(QtProperty *property, int prec); -Q_SIGNALS: - void valueChanged(QtProperty *property, const QPointF &val); - void decimalsChanged(QtProperty *property, int prec); -protected: - QString valueText(const QtProperty *property) const; - virtual void initializeProperty(QtProperty *property); - virtual void uninitializeProperty(QtProperty *property); -private: - QtPointFPropertyManagerPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtPointFPropertyManager) - Q_DISABLE_COPY(QtPointFPropertyManager) - Q_PRIVATE_SLOT(d_func(), void slotDoubleChanged(QtProperty *, double)) - Q_PRIVATE_SLOT(d_func(), void slotPropertyDestroyed(QtProperty *)) -}; - -class QtSizePropertyManagerPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtSizePropertyManager : public QtAbstractPropertyManager -{ - Q_OBJECT -public: - QtSizePropertyManager(QObject *parent = 0); - ~QtSizePropertyManager(); - - QtIntPropertyManager *subIntPropertyManager() const; - - QSize value(const QtProperty *property) const; - QSize minimum(const QtProperty *property) const; - QSize maximum(const QtProperty *property) const; - -public Q_SLOTS: - void setValue(QtProperty *property, const QSize &val); - void setMinimum(QtProperty *property, const QSize &minVal); - void setMaximum(QtProperty *property, const QSize &maxVal); - void setRange(QtProperty *property, const QSize &minVal, const QSize &maxVal); -Q_SIGNALS: - void valueChanged(QtProperty *property, const QSize &val); - void rangeChanged(QtProperty *property, const QSize &minVal, const QSize &maxVal); -protected: - QString valueText(const QtProperty *property) const; - virtual void initializeProperty(QtProperty *property); - virtual void uninitializeProperty(QtProperty *property); -private: - QtSizePropertyManagerPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtSizePropertyManager) - Q_DISABLE_COPY(QtSizePropertyManager) - Q_PRIVATE_SLOT(d_func(), void slotIntChanged(QtProperty *, int)) - Q_PRIVATE_SLOT(d_func(), void slotPropertyDestroyed(QtProperty *)) -}; - -class QtSizeFPropertyManagerPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtSizeFPropertyManager : public QtAbstractPropertyManager -{ - Q_OBJECT -public: - QtSizeFPropertyManager(QObject *parent = 0); - ~QtSizeFPropertyManager(); - - QtDoublePropertyManager *subDoublePropertyManager() const; - - QSizeF value(const QtProperty *property) const; - QSizeF minimum(const QtProperty *property) const; - QSizeF maximum(const QtProperty *property) const; - int decimals(const QtProperty *property) const; - -public Q_SLOTS: - void setValue(QtProperty *property, const QSizeF &val); - void setMinimum(QtProperty *property, const QSizeF &minVal); - void setMaximum(QtProperty *property, const QSizeF &maxVal); - void setRange(QtProperty *property, const QSizeF &minVal, const QSizeF &maxVal); - void setDecimals(QtProperty *property, int prec); -Q_SIGNALS: - void valueChanged(QtProperty *property, const QSizeF &val); - void rangeChanged(QtProperty *property, const QSizeF &minVal, const QSizeF &maxVal); - void decimalsChanged(QtProperty *property, int prec); -protected: - QString valueText(const QtProperty *property) const; - virtual void initializeProperty(QtProperty *property); - virtual void uninitializeProperty(QtProperty *property); -private: - QtSizeFPropertyManagerPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtSizeFPropertyManager) - Q_DISABLE_COPY(QtSizeFPropertyManager) - Q_PRIVATE_SLOT(d_func(), void slotDoubleChanged(QtProperty *, double)) - Q_PRIVATE_SLOT(d_func(), void slotPropertyDestroyed(QtProperty *)) -}; - -class QtRectPropertyManagerPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtRectPropertyManager : public QtAbstractPropertyManager -{ - Q_OBJECT -public: - QtRectPropertyManager(QObject *parent = 0); - ~QtRectPropertyManager(); - - QtIntPropertyManager *subIntPropertyManager() const; - - QRect value(const QtProperty *property) const; - QRect constraint(const QtProperty *property) const; - -public Q_SLOTS: - void setValue(QtProperty *property, const QRect &val); - void setConstraint(QtProperty *property, const QRect &constraint); -Q_SIGNALS: - void valueChanged(QtProperty *property, const QRect &val); - void constraintChanged(QtProperty *property, const QRect &constraint); -protected: - QString valueText(const QtProperty *property) const; - virtual void initializeProperty(QtProperty *property); - virtual void uninitializeProperty(QtProperty *property); -private: - QtRectPropertyManagerPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtRectPropertyManager) - Q_DISABLE_COPY(QtRectPropertyManager) - Q_PRIVATE_SLOT(d_func(), void slotIntChanged(QtProperty *, int)) - Q_PRIVATE_SLOT(d_func(), void slotPropertyDestroyed(QtProperty *)) -}; - -class QtRectFPropertyManagerPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtRectFPropertyManager : public QtAbstractPropertyManager -{ - Q_OBJECT -public: - QtRectFPropertyManager(QObject *parent = 0); - ~QtRectFPropertyManager(); - - QtDoublePropertyManager *subDoublePropertyManager() const; - - QRectF value(const QtProperty *property) const; - QRectF constraint(const QtProperty *property) const; - int decimals(const QtProperty *property) const; - -public Q_SLOTS: - void setValue(QtProperty *property, const QRectF &val); - void setConstraint(QtProperty *property, const QRectF &constraint); - void setDecimals(QtProperty *property, int prec); -Q_SIGNALS: - void valueChanged(QtProperty *property, const QRectF &val); - void constraintChanged(QtProperty *property, const QRectF &constraint); - void decimalsChanged(QtProperty *property, int prec); -protected: - QString valueText(const QtProperty *property) const; - virtual void initializeProperty(QtProperty *property); - virtual void uninitializeProperty(QtProperty *property); -private: - QtRectFPropertyManagerPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtRectFPropertyManager) - Q_DISABLE_COPY(QtRectFPropertyManager) - Q_PRIVATE_SLOT(d_func(), void slotDoubleChanged(QtProperty *, double)) - Q_PRIVATE_SLOT(d_func(), void slotPropertyDestroyed(QtProperty *)) -}; - -class QtEnumPropertyManagerPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtEnumPropertyManager : public QtAbstractPropertyManager -{ - Q_OBJECT -public: - QtEnumPropertyManager(QObject *parent = 0); - ~QtEnumPropertyManager(); - - int value(const QtProperty *property) const; - QStringList enumNames(const QtProperty *property) const; - QMap enumIcons(const QtProperty *property) const; - -public Q_SLOTS: - void setValue(QtProperty *property, int val); - void setEnumNames(QtProperty *property, const QStringList &names); - void setEnumIcons(QtProperty *property, const QMap &icons); -Q_SIGNALS: - void valueChanged(QtProperty *property, int val); - void enumNamesChanged(QtProperty *property, const QStringList &names); - void enumIconsChanged(QtProperty *property, const QMap &icons); -protected: - QString valueText(const QtProperty *property) const; - QIcon valueIcon(const QtProperty *property) const; - virtual void initializeProperty(QtProperty *property); - virtual void uninitializeProperty(QtProperty *property); -private: - QtEnumPropertyManagerPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtEnumPropertyManager) - Q_DISABLE_COPY(QtEnumPropertyManager) -}; - -class QtFlagPropertyManagerPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtFlagPropertyManager : public QtAbstractPropertyManager -{ - Q_OBJECT -public: - QtFlagPropertyManager(QObject *parent = 0); - ~QtFlagPropertyManager(); - - QtBoolPropertyManager *subBoolPropertyManager() const; - - int value(const QtProperty *property) const; - QStringList flagNames(const QtProperty *property) const; - -public Q_SLOTS: - void setValue(QtProperty *property, int val); - void setFlagNames(QtProperty *property, const QStringList &names); -Q_SIGNALS: - void valueChanged(QtProperty *property, int val); - void flagNamesChanged(QtProperty *property, const QStringList &names); -protected: - QString valueText(const QtProperty *property) const; - virtual void initializeProperty(QtProperty *property); - virtual void uninitializeProperty(QtProperty *property); -private: - QtFlagPropertyManagerPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtFlagPropertyManager) - Q_DISABLE_COPY(QtFlagPropertyManager) - Q_PRIVATE_SLOT(d_func(), void slotBoolChanged(QtProperty *, bool)) - Q_PRIVATE_SLOT(d_func(), void slotPropertyDestroyed(QtProperty *)) -}; - -class QtSizePolicyPropertyManagerPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtSizePolicyPropertyManager : public QtAbstractPropertyManager -{ - Q_OBJECT -public: - QtSizePolicyPropertyManager(QObject *parent = 0); - ~QtSizePolicyPropertyManager(); - - QtIntPropertyManager *subIntPropertyManager() const; - QtEnumPropertyManager *subEnumPropertyManager() const; - - QSizePolicy value(const QtProperty *property) const; - -public Q_SLOTS: - void setValue(QtProperty *property, const QSizePolicy &val); -Q_SIGNALS: - void valueChanged(QtProperty *property, const QSizePolicy &val); -protected: - QString valueText(const QtProperty *property) const; - virtual void initializeProperty(QtProperty *property); - virtual void uninitializeProperty(QtProperty *property); -private: - QtSizePolicyPropertyManagerPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtSizePolicyPropertyManager) - Q_DISABLE_COPY(QtSizePolicyPropertyManager) - Q_PRIVATE_SLOT(d_func(), void slotIntChanged(QtProperty *, int)) - Q_PRIVATE_SLOT(d_func(), void slotEnumChanged(QtProperty *, int)) - Q_PRIVATE_SLOT(d_func(), void slotPropertyDestroyed(QtProperty *)) -}; - -class QtFontPropertyManagerPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtFontPropertyManager : public QtAbstractPropertyManager -{ - Q_OBJECT -public: - QtFontPropertyManager(QObject *parent = 0); - ~QtFontPropertyManager(); - - QtIntPropertyManager *subIntPropertyManager() const; - QtEnumPropertyManager *subEnumPropertyManager() const; - QtBoolPropertyManager *subBoolPropertyManager() const; - - QFont value(const QtProperty *property) const; - -public Q_SLOTS: - void setValue(QtProperty *property, const QFont &val); -Q_SIGNALS: - void valueChanged(QtProperty *property, const QFont &val); -protected: - QString valueText(const QtProperty *property) const; - QIcon valueIcon(const QtProperty *property) const; - virtual void initializeProperty(QtProperty *property); - virtual void uninitializeProperty(QtProperty *property); -private: - QtFontPropertyManagerPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtFontPropertyManager) - Q_DISABLE_COPY(QtFontPropertyManager) - Q_PRIVATE_SLOT(d_func(), void slotIntChanged(QtProperty *, int)) - Q_PRIVATE_SLOT(d_func(), void slotEnumChanged(QtProperty *, int)) - Q_PRIVATE_SLOT(d_func(), void slotBoolChanged(QtProperty *, bool)) - Q_PRIVATE_SLOT(d_func(), void slotPropertyDestroyed(QtProperty *)) - Q_PRIVATE_SLOT(d_func(), void slotFontDatabaseChanged()) - Q_PRIVATE_SLOT(d_func(), void slotFontDatabaseDelayedChange()) -}; - -class QtColorPropertyManagerPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtColorPropertyManager : public QtAbstractPropertyManager -{ - Q_OBJECT -public: - QtColorPropertyManager(QObject *parent = 0); - ~QtColorPropertyManager(); - - QtIntPropertyManager *subIntPropertyManager() const; - - QColor value(const QtProperty *property) const; - -public Q_SLOTS: - void setValue(QtProperty *property, const QColor &val); -Q_SIGNALS: - void valueChanged(QtProperty *property, const QColor &val); -protected: - QString valueText(const QtProperty *property) const; - QIcon valueIcon(const QtProperty *property) const; - virtual void initializeProperty(QtProperty *property); - virtual void uninitializeProperty(QtProperty *property); -private: - QtColorPropertyManagerPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtColorPropertyManager) - Q_DISABLE_COPY(QtColorPropertyManager) - Q_PRIVATE_SLOT(d_func(), void slotIntChanged(QtProperty *, int)) - Q_PRIVATE_SLOT(d_func(), void slotPropertyDestroyed(QtProperty *)) -}; - -class QtCursorPropertyManagerPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtCursorPropertyManager : public QtAbstractPropertyManager -{ - Q_OBJECT -public: - QtCursorPropertyManager(QObject *parent = 0); - ~QtCursorPropertyManager(); - -#ifndef QT_NO_CURSOR - QCursor value(const QtProperty *property) const; -#endif - -public Q_SLOTS: - void setValue(QtProperty *property, const QCursor &val); -Q_SIGNALS: - void valueChanged(QtProperty *property, const QCursor &val); -protected: - QString valueText(const QtProperty *property) const; - QIcon valueIcon(const QtProperty *property) const; - virtual void initializeProperty(QtProperty *property); - virtual void uninitializeProperty(QtProperty *property); -private: - QtCursorPropertyManagerPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtCursorPropertyManager) - Q_DISABLE_COPY(QtCursorPropertyManager) -}; - -#if QT_VERSION >= 0x040400 -QT_END_NAMESPACE -#endif - -#endif diff --git a/QtPropertyBrowser/qttreepropertybrowser.cpp b/QtPropertyBrowser/qttreepropertybrowser.cpp deleted file mode 100644 index 223df9b329..0000000000 --- a/QtPropertyBrowser/qttreepropertybrowser.cpp +++ /dev/null @@ -1,1091 +0,0 @@ -/**************************************************************************** -** -** This file is part of a Qt Solutions component. -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Solutions Commercial License Agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** Please note Third Party Software included with Qt Solutions may impose -** additional restrictions and it is the user's responsibility to ensure -** that they have met the licensing requirements of the GPL, LGPL, or Qt -** Solutions Commercial license and the relevant license of the Third -** Party Software they are using. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qttreepropertybrowser.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if QT_VERSION >= 0x040400 -QT_BEGIN_NAMESPACE -#endif - -class QtPropertyEditorView; - -class QtTreePropertyBrowserPrivate -{ - QtTreePropertyBrowser *q_ptr; - Q_DECLARE_PUBLIC(QtTreePropertyBrowser) - -public: - QtTreePropertyBrowserPrivate(); - void init(QWidget *parent); - - void propertyInserted(QtBrowserItem *index, QtBrowserItem *afterIndex); - void propertyRemoved(QtBrowserItem *index); - void propertyChanged(QtBrowserItem *index); - QWidget *createEditor(QtProperty *property, QWidget *parent) const - { return q_ptr->createEditor(property, parent); } - QtProperty *indexToProperty(const QModelIndex &index) const; - QTreeWidgetItem *indexToItem(const QModelIndex &index) const; - QtBrowserItem *indexToBrowserItem(const QModelIndex &index) const; - bool lastColumn(int column) const; - void disableItem(QTreeWidgetItem *item) const; - void enableItem(QTreeWidgetItem *item) const; - bool hasValue(QTreeWidgetItem *item) const; - - void slotCollapsed(const QModelIndex &index); - void slotExpanded(const QModelIndex &index); - - QColor calculatedBackgroundColor(QtBrowserItem *item) const; - - QtPropertyEditorView *treeWidget() const { return m_treeWidget; } - bool markPropertiesWithoutValue() const { return m_markPropertiesWithoutValue; } - - QtBrowserItem *currentItem() const; - void setCurrentItem(QtBrowserItem *browserItem, bool block); - void editItem(QtBrowserItem *browserItem); - - void slotCurrentBrowserItemChanged(QtBrowserItem *item); - void slotCurrentTreeItemChanged(QTreeWidgetItem *newItem, QTreeWidgetItem *); - - QTreeWidgetItem *editedItem() const; - -private: - void updateItem(QTreeWidgetItem *item); - - QMap m_indexToItem; - QMap m_itemToIndex; - - QMap m_indexToBackgroundColor; - - QtPropertyEditorView *m_treeWidget; - - bool m_headerVisible; - QtTreePropertyBrowser::ResizeMode m_resizeMode; - class QtPropertyEditorDelegate *m_delegate; - bool m_markPropertiesWithoutValue; - bool m_browserChangedBlocked; - QIcon m_expandIcon; -}; - -// ------------ QtPropertyEditorView -class QtPropertyEditorView : public QTreeWidget -{ - Q_OBJECT -public: - QtPropertyEditorView(QWidget *parent = 0); - - void setEditorPrivate(QtTreePropertyBrowserPrivate *editorPrivate) - { m_editorPrivate = editorPrivate; } - - QTreeWidgetItem *indexToItem(const QModelIndex &index) const - { return itemFromIndex(index); } - -protected: - void keyPressEvent(QKeyEvent *event); - void mousePressEvent(QMouseEvent *event); - void drawRow(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; - -private: - QtTreePropertyBrowserPrivate *m_editorPrivate; -}; - -QtPropertyEditorView::QtPropertyEditorView(QWidget *parent) : - QTreeWidget(parent), - m_editorPrivate(0) -{ - connect(header(), SIGNAL(sectionDoubleClicked(int)), this, SLOT(resizeColumnToContents(int))); -} - -void QtPropertyEditorView::drawRow(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - QStyleOptionViewItemV3 opt = option; - bool hasValue = true; - if (m_editorPrivate) { - QtProperty *property = m_editorPrivate->indexToProperty(index); - if (property) - hasValue = property->hasValue(); - } - if (!hasValue && m_editorPrivate->markPropertiesWithoutValue()) { - const QColor c = option.palette.color(QPalette::Dark); - painter->fillRect(option.rect, c); - opt.palette.setColor(QPalette::AlternateBase, c); - } else { - const QColor c = m_editorPrivate->calculatedBackgroundColor(m_editorPrivate->indexToBrowserItem(index)); - if (c.isValid()) { - painter->fillRect(option.rect, c); - opt.palette.setColor(QPalette::AlternateBase, c.lighter(112)); - } - } - QTreeWidget::drawRow(painter, opt, index); - QColor color = static_cast(QApplication::style()->styleHint(QStyle::SH_Table_GridLineColor, &opt)); - painter->save(); - painter->setPen(QPen(color)); - painter->drawLine(opt.rect.x(), opt.rect.bottom(), opt.rect.right(), opt.rect.bottom()); - painter->restore(); -} - -void QtPropertyEditorView::keyPressEvent(QKeyEvent *event) -{ - switch (event->key()) { - case Qt::Key_Return: - case Qt::Key_Enter: - case Qt::Key_Space: // Trigger Edit - if (!m_editorPrivate->editedItem()) - if (const QTreeWidgetItem *item = currentItem()) - if (item->columnCount() >= 2 && ((item->flags() & (Qt::ItemIsEditable | Qt::ItemIsEnabled)) == (Qt::ItemIsEditable | Qt::ItemIsEnabled))) { - event->accept(); - // If the current position is at column 0, move to 1. - QModelIndex index = currentIndex(); - if (index.column() == 0) { - index = index.sibling(index.row(), 1); - setCurrentIndex(index); - } - edit(index); - return; - } - break; - default: - break; - } - QTreeWidget::keyPressEvent(event); -} - -void QtPropertyEditorView::mousePressEvent(QMouseEvent *event) -{ - QTreeWidget::mousePressEvent(event); - QTreeWidgetItem *item = itemAt(event->pos()); - - if (item) { - if ((item != m_editorPrivate->editedItem()) && (event->button() == Qt::LeftButton) - && (header()->logicalIndexAt(event->pos().x()) == 1) - && ((item->flags() & (Qt::ItemIsEditable | Qt::ItemIsEnabled)) == (Qt::ItemIsEditable | Qt::ItemIsEnabled))) { - editItem(item, 1); - } else if (!m_editorPrivate->hasValue(item) && m_editorPrivate->markPropertiesWithoutValue() && !rootIsDecorated()) { - if (event->pos().x() + header()->offset() < 20) - item->setExpanded(!item->isExpanded()); - } - } -} - -// ------------ QtPropertyEditorDelegate -class QtPropertyEditorDelegate : public QItemDelegate -{ - Q_OBJECT -public: - QtPropertyEditorDelegate(QObject *parent = 0) - : QItemDelegate(parent), m_editorPrivate(0), m_editedItem(0), m_editedWidget(0) - {} - - void setEditorPrivate(QtTreePropertyBrowserPrivate *editorPrivate) - { m_editorPrivate = editorPrivate; } - - QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, - const QModelIndex &index) const; - - void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, - const QModelIndex &index) const; - - void paint(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index) const; - - QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; - - void setModelData(QWidget *, QAbstractItemModel *, - const QModelIndex &) const {} - - void setEditorData(QWidget *, const QModelIndex &) const {} - - bool eventFilter(QObject *object, QEvent *event); - void closeEditor(QtProperty *property); - - QTreeWidgetItem *editedItem() const { return m_editedItem; } - -private slots: - void slotEditorDestroyed(QObject *object); - -private: - int indentation(const QModelIndex &index) const; - - typedef QMap EditorToPropertyMap; - mutable EditorToPropertyMap m_editorToProperty; - - typedef QMap PropertyToEditorMap; - mutable PropertyToEditorMap m_propertyToEditor; - QtTreePropertyBrowserPrivate *m_editorPrivate; - mutable QTreeWidgetItem *m_editedItem; - mutable QWidget *m_editedWidget; -}; - -int QtPropertyEditorDelegate::indentation(const QModelIndex &index) const -{ - if (!m_editorPrivate) - return 0; - - QTreeWidgetItem *item = m_editorPrivate->indexToItem(index); - int indent = 0; - while (item->parent()) { - item = item->parent(); - ++indent; - } - if (m_editorPrivate->treeWidget()->rootIsDecorated()) - ++indent; - return indent * m_editorPrivate->treeWidget()->indentation(); -} - -void QtPropertyEditorDelegate::slotEditorDestroyed(QObject *object) -{ - if (QWidget *w = qobject_cast(object)) { - const EditorToPropertyMap::iterator it = m_editorToProperty.find(w); - if (it != m_editorToProperty.end()) { - m_propertyToEditor.remove(it.value()); - m_editorToProperty.erase(it); - } - if (m_editedWidget == w) { - m_editedWidget = 0; - m_editedItem = 0; - } - } -} - -void QtPropertyEditorDelegate::closeEditor(QtProperty *property) -{ - if (QWidget *w = m_propertyToEditor.value(property, 0)) - w->deleteLater(); -} - -QWidget *QtPropertyEditorDelegate::createEditor(QWidget *parent, - const QStyleOptionViewItem &, const QModelIndex &index) const -{ - if (index.column() == 1 && m_editorPrivate) { - QtProperty *property = m_editorPrivate->indexToProperty(index); - QTreeWidgetItem *item = m_editorPrivate->indexToItem(index); - if (property && item && (item->flags() & Qt::ItemIsEnabled)) { - QWidget *editor = m_editorPrivate->createEditor(property, parent); - if (editor) { - editor->setAutoFillBackground(true); - editor->installEventFilter(const_cast(this)); - connect(editor, SIGNAL(destroyed(QObject *)), this, SLOT(slotEditorDestroyed(QObject *))); - m_propertyToEditor[property] = editor; - m_editorToProperty[editor] = property; - m_editedItem = item; - m_editedWidget = editor; - } - return editor; - } - } - return 0; -} - -void QtPropertyEditorDelegate::updateEditorGeometry(QWidget *editor, - const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - Q_UNUSED(index) - editor->setGeometry(option.rect.adjusted(0, 0, 0, -1)); -} - -void QtPropertyEditorDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index) const -{ - bool hasValue = true; - if (m_editorPrivate) { - QtProperty *property = m_editorPrivate->indexToProperty(index); - if (property) - hasValue = property->hasValue(); - } - QStyleOptionViewItemV3 opt = option; - if ((m_editorPrivate && index.column() == 0) || !hasValue) { - QtProperty *property = m_editorPrivate->indexToProperty(index); - if (property && property->isModified()) { - opt.font.setBold(true); - opt.fontMetrics = QFontMetrics(opt.font); - } - } - QColor c; - if (!hasValue && m_editorPrivate->markPropertiesWithoutValue()) { - c = opt.palette.color(QPalette::Dark); - opt.palette.setColor(QPalette::Text, opt.palette.color(QPalette::BrightText)); - } else { - c = m_editorPrivate->calculatedBackgroundColor(m_editorPrivate->indexToBrowserItem(index)); - if (c.isValid() && (opt.features & QStyleOptionViewItemV2::Alternate)) - c = c.lighter(112); - } - if (c.isValid()) - painter->fillRect(option.rect, c); - opt.state &= ~QStyle::State_HasFocus; - QItemDelegate::paint(painter, opt, index); - - opt.palette.setCurrentColorGroup(QPalette::Active); - QColor color = static_cast(QApplication::style()->styleHint(QStyle::SH_Table_GridLineColor, &opt)); - painter->save(); - painter->setPen(QPen(color)); - if (!m_editorPrivate || (!m_editorPrivate->lastColumn(index.column()) && hasValue)) { - int right = (option.direction == Qt::LeftToRight) ? option.rect.right() : option.rect.left(); - painter->drawLine(right, option.rect.y(), right, option.rect.bottom()); - } - painter->restore(); -} - -QSize QtPropertyEditorDelegate::sizeHint(const QStyleOptionViewItem &option, - const QModelIndex &index) const -{ - return QItemDelegate::sizeHint(option, index) + QSize(3, 4); -} - -bool QtPropertyEditorDelegate::eventFilter(QObject *object, QEvent *event) -{ - if (event->type() == QEvent::FocusOut) { - QFocusEvent *fe = static_cast(event); - if (fe->reason() == Qt::ActiveWindowFocusReason) - return false; - } - return QItemDelegate::eventFilter(object, event); -} - -// -------- QtTreePropertyBrowserPrivate implementation -QtTreePropertyBrowserPrivate::QtTreePropertyBrowserPrivate() : - m_treeWidget(0), - m_headerVisible(true), - m_resizeMode(QtTreePropertyBrowser::Stretch), - m_delegate(0), - m_markPropertiesWithoutValue(false), - m_browserChangedBlocked(false) -{ -} - -// Draw an icon indicating opened/closing branches -static QIcon drawIndicatorIcon(const QPalette &palette, QStyle *style) -{ - QPixmap pix(14, 14); - pix.fill(Qt::transparent); - QStyleOption branchOption; - QRect r(QPoint(0, 0), pix.size()); - branchOption.rect = QRect(2, 2, 9, 9); // ### hardcoded in qcommonstyle.cpp - branchOption.palette = palette; - branchOption.state = QStyle::State_Children; - - QPainter p; - // Draw closed state - p.begin(&pix); - style->drawPrimitive(QStyle::PE_IndicatorBranch, &branchOption, &p); - p.end(); - QIcon rc = pix; - rc.addPixmap(pix, QIcon::Selected, QIcon::Off); - // Draw opened state - branchOption.state |= QStyle::State_Open; - pix.fill(Qt::transparent); - p.begin(&pix); - style->drawPrimitive(QStyle::PE_IndicatorBranch, &branchOption, &p); - p.end(); - - rc.addPixmap(pix, QIcon::Normal, QIcon::On); - rc.addPixmap(pix, QIcon::Selected, QIcon::On); - return rc; -} - -void QtTreePropertyBrowserPrivate::init(QWidget *parent) -{ - QHBoxLayout *layout = new QHBoxLayout(parent); - layout->setMargin(0); - m_treeWidget = new QtPropertyEditorView(parent); - m_treeWidget->setEditorPrivate(this); - m_treeWidget->setIconSize(QSize(18, 18)); - layout->addWidget(m_treeWidget); - - m_treeWidget->setColumnCount(2); - QStringList labels; - labels.append(QApplication::translate("QtTreePropertyBrowser", "Property", 0, QApplication::UnicodeUTF8)); - labels.append(QApplication::translate("QtTreePropertyBrowser", "Value", 0, QApplication::UnicodeUTF8)); - m_treeWidget->setHeaderLabels(labels); - m_treeWidget->setAlternatingRowColors(true); - m_treeWidget->setEditTriggers(QAbstractItemView::EditKeyPressed); - m_delegate = new QtPropertyEditorDelegate(parent); - m_delegate->setEditorPrivate(this); - m_treeWidget->setItemDelegate(m_delegate); - m_treeWidget->header()->setMovable(false); - m_treeWidget->header()->setResizeMode(QHeaderView::Interactive); - - m_expandIcon = drawIndicatorIcon(q_ptr->palette(), q_ptr->style()); - - QObject::connect(m_treeWidget, SIGNAL(collapsed(const QModelIndex &)), q_ptr, SLOT(slotCollapsed(const QModelIndex &))); - QObject::connect(m_treeWidget, SIGNAL(expanded(const QModelIndex &)), q_ptr, SLOT(slotExpanded(const QModelIndex &))); - QObject::connect(m_treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), q_ptr, SLOT(slotCurrentTreeItemChanged(QTreeWidgetItem*,QTreeWidgetItem*))); -} - -QtBrowserItem *QtTreePropertyBrowserPrivate::currentItem() const -{ - if (QTreeWidgetItem *treeItem = m_treeWidget->currentItem()) - return m_itemToIndex.value(treeItem); - return 0; -} - -void QtTreePropertyBrowserPrivate::setCurrentItem(QtBrowserItem *browserItem, bool block) -{ - const bool blocked = block ? m_treeWidget->blockSignals(true) : false; - if (browserItem == 0) - m_treeWidget->setCurrentItem(0); - else - m_treeWidget->setCurrentItem(m_indexToItem.value(browserItem)); - if (block) - m_treeWidget->blockSignals(blocked); -} - -QtProperty *QtTreePropertyBrowserPrivate::indexToProperty(const QModelIndex &index) const -{ - QTreeWidgetItem *item = m_treeWidget->indexToItem(index); - QtBrowserItem *idx = m_itemToIndex.value(item); - if (idx) - return idx->property(); - return 0; -} - -QtBrowserItem *QtTreePropertyBrowserPrivate::indexToBrowserItem(const QModelIndex &index) const -{ - QTreeWidgetItem *item = m_treeWidget->indexToItem(index); - return m_itemToIndex.value(item); -} - -QTreeWidgetItem *QtTreePropertyBrowserPrivate::indexToItem(const QModelIndex &index) const -{ - return m_treeWidget->indexToItem(index); -} - -bool QtTreePropertyBrowserPrivate::lastColumn(int column) const -{ - return m_treeWidget->header()->visualIndex(column) == m_treeWidget->columnCount() - 1; -} - -void QtTreePropertyBrowserPrivate::disableItem(QTreeWidgetItem *item) const -{ - Qt::ItemFlags flags = item->flags(); - if (flags & Qt::ItemIsEnabled) { - flags &= ~Qt::ItemIsEnabled; - item->setFlags(flags); - m_delegate->closeEditor(m_itemToIndex[item]->property()); - const int childCount = item->childCount(); - for (int i = 0; i < childCount; i++) { - QTreeWidgetItem *child = item->child(i); - disableItem(child); - } - } -} - -void QtTreePropertyBrowserPrivate::enableItem(QTreeWidgetItem *item) const -{ - Qt::ItemFlags flags = item->flags(); - flags |= Qt::ItemIsEnabled; - item->setFlags(flags); - const int childCount = item->childCount(); - for (int i = 0; i < childCount; i++) { - QTreeWidgetItem *child = item->child(i); - QtProperty *property = m_itemToIndex[child]->property(); - if (property->isEnabled()) { - enableItem(child); - } - } -} - -bool QtTreePropertyBrowserPrivate::hasValue(QTreeWidgetItem *item) const -{ - QtBrowserItem *browserItem = m_itemToIndex.value(item); - if (browserItem) - return browserItem->property()->hasValue(); - return false; -} - -void QtTreePropertyBrowserPrivate::propertyInserted(QtBrowserItem *index, QtBrowserItem *afterIndex) -{ - QTreeWidgetItem *afterItem = m_indexToItem.value(afterIndex); - QTreeWidgetItem *parentItem = m_indexToItem.value(index->parent()); - - QTreeWidgetItem *newItem = 0; - if (parentItem) { - newItem = new QTreeWidgetItem(parentItem, afterItem); - } else { - newItem = new QTreeWidgetItem(m_treeWidget, afterItem); - } - m_itemToIndex[newItem] = index; - m_indexToItem[index] = newItem; - - newItem->setFlags(newItem->flags() | Qt::ItemIsEditable); - m_treeWidget->setItemExpanded(newItem, true); - - updateItem(newItem); -} - -void QtTreePropertyBrowserPrivate::propertyRemoved(QtBrowserItem *index) -{ - QTreeWidgetItem *item = m_indexToItem.value(index); - - if (m_treeWidget->currentItem() == item) { - m_treeWidget->setCurrentItem(0); - } - - delete item; - - m_indexToItem.remove(index); - m_itemToIndex.remove(item); - m_indexToBackgroundColor.remove(index); -} - -void QtTreePropertyBrowserPrivate::propertyChanged(QtBrowserItem *index) -{ - QTreeWidgetItem *item = m_indexToItem.value(index); - - updateItem(item); -} - -void QtTreePropertyBrowserPrivate::updateItem(QTreeWidgetItem *item) -{ - QtProperty *property = m_itemToIndex[item]->property(); - QIcon expandIcon; - if (property->hasValue()) { - QString toolTip = property->toolTip(); - if (toolTip.isEmpty()) - toolTip = property->valueText(); - item->setToolTip(1, toolTip); - item->setIcon(1, property->valueIcon()); - item->setText(1, property->valueText()); - } else if (markPropertiesWithoutValue() && !m_treeWidget->rootIsDecorated()) { - expandIcon = m_expandIcon; - } - item->setIcon(0, expandIcon); - item->setFirstColumnSpanned(!property->hasValue()); - item->setToolTip(0, property->propertyName()); - item->setStatusTip(0, property->statusTip()); - item->setWhatsThis(0, property->whatsThis()); - item->setText(0, property->propertyName()); - bool wasEnabled = item->flags() & Qt::ItemIsEnabled; - bool isEnabled = wasEnabled; - if (property->isEnabled()) { - QTreeWidgetItem *parent = item->parent(); - if (!parent || (parent->flags() & Qt::ItemIsEnabled)) - isEnabled = true; - else - isEnabled = false; - } else { - isEnabled = false; - } - if (wasEnabled != isEnabled) { - if (isEnabled) - enableItem(item); - else - disableItem(item); - } - m_treeWidget->viewport()->update(); -} - -QColor QtTreePropertyBrowserPrivate::calculatedBackgroundColor(QtBrowserItem *item) const -{ - QtBrowserItem *i = item; - const QMap::const_iterator itEnd = m_indexToBackgroundColor.constEnd(); - while (i) { - QMap::const_iterator it = m_indexToBackgroundColor.constFind(i); - if (it != itEnd) - return it.value(); - i = i->parent(); - } - return QColor(); -} - -void QtTreePropertyBrowserPrivate::slotCollapsed(const QModelIndex &index) -{ - QTreeWidgetItem *item = indexToItem(index); - QtBrowserItem *idx = m_itemToIndex.value(item); - if (item) - emit q_ptr->collapsed(idx); -} - -void QtTreePropertyBrowserPrivate::slotExpanded(const QModelIndex &index) -{ - QTreeWidgetItem *item = indexToItem(index); - QtBrowserItem *idx = m_itemToIndex.value(item); - if (item) - emit q_ptr->expanded(idx); -} - -void QtTreePropertyBrowserPrivate::slotCurrentBrowserItemChanged(QtBrowserItem *item) -{ - if (!m_browserChangedBlocked && item != currentItem()) - setCurrentItem(item, true); -} - -void QtTreePropertyBrowserPrivate::slotCurrentTreeItemChanged(QTreeWidgetItem *newItem, QTreeWidgetItem *) -{ - QtBrowserItem *browserItem = newItem ? m_itemToIndex.value(newItem) : 0; - m_browserChangedBlocked = true; - q_ptr->setCurrentItem(browserItem); - m_browserChangedBlocked = false; -} - -QTreeWidgetItem *QtTreePropertyBrowserPrivate::editedItem() const -{ - return m_delegate->editedItem(); -} - -void QtTreePropertyBrowserPrivate::editItem(QtBrowserItem *browserItem) -{ - if (QTreeWidgetItem *treeItem = m_indexToItem.value(browserItem, 0)) { - m_treeWidget->setCurrentItem (treeItem, 1); - m_treeWidget->editItem(treeItem, 1); - } -} - -/*! - \class QtTreePropertyBrowser - - \brief The QtTreePropertyBrowser class provides QTreeWidget based - property browser. - - A property browser is a widget that enables the user to edit a - given set of properties. Each property is represented by a label - specifying the property's name, and an editing widget (e.g. a line - edit or a combobox) holding its value. A property can have zero or - more subproperties. - - QtTreePropertyBrowser provides a tree based view for all nested - properties, i.e. properties that have subproperties can be in an - expanded (subproperties are visible) or collapsed (subproperties - are hidden) state. For example: - - \image qttreepropertybrowser.png - - Use the QtAbstractPropertyBrowser API to add, insert and remove - properties from an instance of the QtTreePropertyBrowser class. - The properties themselves are created and managed by - implementations of the QtAbstractPropertyManager class. - - \sa QtGroupBoxPropertyBrowser, QtAbstractPropertyBrowser -*/ - -/*! - \fn void QtTreePropertyBrowser::collapsed(QtBrowserItem *item) - - This signal is emitted when the \a item is collapsed. - - \sa expanded(), setExpanded() -*/ - -/*! - \fn void QtTreePropertyBrowser::expanded(QtBrowserItem *item) - - This signal is emitted when the \a item is expanded. - - \sa collapsed(), setExpanded() -*/ - -/*! - Creates a property browser with the given \a parent. -*/ -QtTreePropertyBrowser::QtTreePropertyBrowser(QWidget *parent) - : QtAbstractPropertyBrowser(parent) -{ - d_ptr = new QtTreePropertyBrowserPrivate; - d_ptr->q_ptr = this; - - d_ptr->init(this); - connect(this, SIGNAL(currentItemChanged(QtBrowserItem*)), this, SLOT(slotCurrentBrowserItemChanged(QtBrowserItem*))); -} - -/*! - Destroys this property browser. - - Note that the properties that were inserted into this browser are - \e not destroyed since they may still be used in other - browsers. The properties are owned by the manager that created - them. - - \sa QtProperty, QtAbstractPropertyManager -*/ -QtTreePropertyBrowser::~QtTreePropertyBrowser() -{ - delete d_ptr; -} - -/*! - \property QtTreePropertyBrowser::indentation - \brief indentation of the items in the tree view. -*/ -int QtTreePropertyBrowser::indentation() const -{ - return d_ptr->m_treeWidget->indentation(); -} - -void QtTreePropertyBrowser::setIndentation(int i) -{ - d_ptr->m_treeWidget->setIndentation(i); -} - -/*! - \property QtTreePropertyBrowser::rootIsDecorated - \brief whether to show controls for expanding and collapsing root items. -*/ -bool QtTreePropertyBrowser::rootIsDecorated() const -{ - return d_ptr->m_treeWidget->rootIsDecorated(); -} - -void QtTreePropertyBrowser::setRootIsDecorated(bool show) -{ - d_ptr->m_treeWidget->setRootIsDecorated(show); - QMapIterator it(d_ptr->m_itemToIndex); - while (it.hasNext()) { - QtProperty *property = it.next().value()->property(); - if (!property->hasValue()) - d_ptr->updateItem(it.key()); - } -} - -/*! - \property QtTreePropertyBrowser::alternatingRowColors - \brief whether to draw the background using alternating colors. - By default this property is set to true. -*/ -bool QtTreePropertyBrowser::alternatingRowColors() const -{ - return d_ptr->m_treeWidget->alternatingRowColors(); -} - -void QtTreePropertyBrowser::setAlternatingRowColors(bool enable) -{ - d_ptr->m_treeWidget->setAlternatingRowColors(enable); - QMapIterator it(d_ptr->m_itemToIndex); -} - -/*! - \property QtTreePropertyBrowser::headerVisible - \brief whether to show the header. -*/ -bool QtTreePropertyBrowser::isHeaderVisible() const -{ - return d_ptr->m_headerVisible; -} - -void QtTreePropertyBrowser::setHeaderVisible(bool visible) -{ - if (d_ptr->m_headerVisible == visible) - return; - - d_ptr->m_headerVisible = visible; - d_ptr->m_treeWidget->header()->setVisible(visible); -} - -/*! - \enum QtTreePropertyBrowser::ResizeMode - - The resize mode specifies the behavior of the header sections. - - \value Interactive The user can resize the sections. - The sections can also be resized programmatically using setSplitterPosition(). - - \value Fixed The user cannot resize the section. - The section can only be resized programmatically using setSplitterPosition(). - - \value Stretch QHeaderView will automatically resize the section to fill the available space. - The size cannot be changed by the user or programmatically. - - \value ResizeToContents QHeaderView will automatically resize the section to its optimal - size based on the contents of the entire column. - The size cannot be changed by the user or programmatically. - - \sa setResizeMode() -*/ - -/*! - \property QtTreePropertyBrowser::resizeMode - \brief the resize mode of setions in the header. -*/ - -QtTreePropertyBrowser::ResizeMode QtTreePropertyBrowser::resizeMode() const -{ - return d_ptr->m_resizeMode; -} - -void QtTreePropertyBrowser::setResizeMode(QtTreePropertyBrowser::ResizeMode mode) -{ - if (d_ptr->m_resizeMode == mode) - return; - - d_ptr->m_resizeMode = mode; - QHeaderView::ResizeMode m = QHeaderView::Stretch; - switch (mode) { - case QtTreePropertyBrowser::Interactive: m = QHeaderView::Interactive; break; - case QtTreePropertyBrowser::Fixed: m = QHeaderView::Fixed; break; - case QtTreePropertyBrowser::ResizeToContents: m = QHeaderView::ResizeToContents; break; - case QtTreePropertyBrowser::Stretch: - default: m = QHeaderView::Stretch; break; - } - d_ptr->m_treeWidget->header()->setResizeMode(m); -} - -/*! - \property QtTreePropertyBrowser::splitterPosition - \brief the position of the splitter between the colunms. -*/ - -int QtTreePropertyBrowser::splitterPosition() const -{ - return d_ptr->m_treeWidget->header()->sectionSize(0); -} - -void QtTreePropertyBrowser::setSplitterPosition(int position) -{ - d_ptr->m_treeWidget->header()->resizeSection(0, position); -} - -/*! - Sets the \a item to either collapse or expanded, depending on the value of \a expanded. - - \sa isExpanded(), expanded(), collapsed() -*/ - -void QtTreePropertyBrowser::setExpanded(QtBrowserItem *item, bool expanded) -{ - QTreeWidgetItem *treeItem = d_ptr->m_indexToItem.value(item); - if (treeItem) - treeItem->setExpanded(expanded); -} - -/*! - Returns true if the \a item is expanded; otherwise returns false. - - \sa setExpanded() -*/ - -bool QtTreePropertyBrowser::isExpanded(QtBrowserItem *item) const -{ - QTreeWidgetItem *treeItem = d_ptr->m_indexToItem.value(item); - if (treeItem) - return treeItem->isExpanded(); - return false; -} - -/*! - Returns true if the \a item is visible; otherwise returns false. - - \sa setItemVisible() - \since 4.5 -*/ - -bool QtTreePropertyBrowser::isItemVisible(QtBrowserItem *item) const -{ - if (const QTreeWidgetItem *treeItem = d_ptr->m_indexToItem.value(item)) - return !treeItem->isHidden(); - return false; -} - -/*! - Sets the \a item to be visible, depending on the value of \a visible. - - \sa isItemVisible() - \since 4.5 -*/ - -void QtTreePropertyBrowser::setItemVisible(QtBrowserItem *item, bool visible) -{ - if (QTreeWidgetItem *treeItem = d_ptr->m_indexToItem.value(item)) - treeItem->setHidden(!visible); -} - -/*! - Sets the \a item's background color to \a color. Note that while item's background - is rendered every second row is being drawn with alternate color (which is a bit lighter than items \a color) - - \sa backgroundColor(), calculatedBackgroundColor() -*/ - -void QtTreePropertyBrowser::setBackgroundColor(QtBrowserItem *item, const QColor &color) -{ - if (!d_ptr->m_indexToItem.contains(item)) - return; - if (color.isValid()) - d_ptr->m_indexToBackgroundColor[item] = color; - else - d_ptr->m_indexToBackgroundColor.remove(item); - d_ptr->m_treeWidget->viewport()->update(); -} - -/*! - Returns the \a item's color. If there is no color set for item it returns invalid color. - - \sa calculatedBackgroundColor(), setBackgroundColor() -*/ - -QColor QtTreePropertyBrowser::backgroundColor(QtBrowserItem *item) const -{ - return d_ptr->m_indexToBackgroundColor.value(item); -} - -/*! - Returns the \a item's color. If there is no color set for item it returns parent \a item's - color (if there is no color set for parent it returns grandparent's color and so on). In case - the color is not set for \a item and it's top level item it returns invalid color. - - \sa backgroundColor(), setBackgroundColor() -*/ - -QColor QtTreePropertyBrowser::calculatedBackgroundColor(QtBrowserItem *item) const -{ - return d_ptr->calculatedBackgroundColor(item); -} - -/*! - \property QtTreePropertyBrowser::propertiesWithoutValueMarked - \brief whether to enable or disable marking properties without value. - - When marking is enabled the item's background is rendered in dark color and item's - foreground is rendered with light color. - - \sa propertiesWithoutValueMarked() -*/ -void QtTreePropertyBrowser::setPropertiesWithoutValueMarked(bool mark) -{ - if (d_ptr->m_markPropertiesWithoutValue == mark) - return; - - d_ptr->m_markPropertiesWithoutValue = mark; - QMapIterator it(d_ptr->m_itemToIndex); - while (it.hasNext()) { - QtProperty *property = it.next().value()->property(); - if (!property->hasValue()) - d_ptr->updateItem(it.key()); - } - d_ptr->m_treeWidget->viewport()->update(); -} - -bool QtTreePropertyBrowser::propertiesWithoutValueMarked() const -{ - return d_ptr->m_markPropertiesWithoutValue; -} - -/*! - \reimp -*/ -void QtTreePropertyBrowser::itemInserted(QtBrowserItem *item, QtBrowserItem *afterItem) -{ - d_ptr->propertyInserted(item, afterItem); -} - -/*! - \reimp -*/ -void QtTreePropertyBrowser::itemRemoved(QtBrowserItem *item) -{ - d_ptr->propertyRemoved(item); -} - -/*! - \reimp -*/ -void QtTreePropertyBrowser::itemChanged(QtBrowserItem *item) -{ - d_ptr->propertyChanged(item); -} - -/*! - Sets the current item to \a item and opens the relevant editor for it. -*/ -void QtTreePropertyBrowser::editItem(QtBrowserItem *item) -{ - d_ptr->editItem(item); -} - -#if QT_VERSION >= 0x040400 -QT_END_NAMESPACE -#endif - -#include "moc_qttreepropertybrowser.cxx" -#include "qttreepropertybrowser.moc" diff --git a/QtPropertyBrowser/qttreepropertybrowser.h b/QtPropertyBrowser/qttreepropertybrowser.h deleted file mode 100644 index f664609d79..0000000000 --- a/QtPropertyBrowser/qttreepropertybrowser.h +++ /dev/null @@ -1,184 +0,0 @@ -/**************************************************************************** -** -** This file is part of a Qt Solutions component. -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Solutions Commercial License Agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** Please note Third Party Software included with Qt Solutions may impose -** additional restrictions and it is the user's responsibility to ensure -** that they have met the licensing requirements of the GPL, LGPL, or Qt -** Solutions Commercial license and the relevant license of the Third -** Party Software they are using. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTTREEPROPERTYBROWSER_H -#define QTTREEPROPERTYBROWSER_H - -#include "qtpropertybrowser.h" - -#if QT_VERSION >= 0x040400 -QT_BEGIN_NAMESPACE -#endif - -class QTreeWidgetItem; -class QtTreePropertyBrowserPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtTreePropertyBrowser : public QtAbstractPropertyBrowser -{ - Q_OBJECT - Q_ENUMS(ResizeMode) - Q_PROPERTY(int indentation READ indentation WRITE setIndentation) - Q_PROPERTY(bool rootIsDecorated READ rootIsDecorated WRITE setRootIsDecorated) - Q_PROPERTY(bool alternatingRowColors READ alternatingRowColors WRITE setAlternatingRowColors) - Q_PROPERTY(bool headerVisible READ isHeaderVisible WRITE setHeaderVisible) - Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode) - Q_PROPERTY(int splitterPosition READ splitterPosition WRITE setSplitterPosition) - Q_PROPERTY(bool propertiesWithoutValueMarked READ propertiesWithoutValueMarked WRITE setPropertiesWithoutValueMarked) -public: - - enum ResizeMode - { - Interactive, - Stretch, - Fixed, - ResizeToContents - }; - - QtTreePropertyBrowser(QWidget *parent = 0); - ~QtTreePropertyBrowser(); - - int indentation() const; - void setIndentation(int i); - - bool rootIsDecorated() const; - void setRootIsDecorated(bool show); - - bool alternatingRowColors() const; - void setAlternatingRowColors(bool enable); - - bool isHeaderVisible() const; - void setHeaderVisible(bool visible); - - ResizeMode resizeMode() const; - void setResizeMode(ResizeMode mode); - - int splitterPosition() const; - void setSplitterPosition(int position); - - void setExpanded(QtBrowserItem *item, bool expanded); - bool isExpanded(QtBrowserItem *item) const; - - bool isItemVisible(QtBrowserItem *item) const; - void setItemVisible(QtBrowserItem *item, bool visible); - - void setBackgroundColor(QtBrowserItem *item, const QColor &color); - QColor backgroundColor(QtBrowserItem *item) const; - QColor calculatedBackgroundColor(QtBrowserItem *item) const; - - void setPropertiesWithoutValueMarked(bool mark); - bool propertiesWithoutValueMarked() const; - - void editItem(QtBrowserItem *item); - -Q_SIGNALS: - - void collapsed(QtBrowserItem *item); - void expanded(QtBrowserItem *item); - -protected: - virtual void itemInserted(QtBrowserItem *item, QtBrowserItem *afterItem); - virtual void itemRemoved(QtBrowserItem *item); - virtual void itemChanged(QtBrowserItem *item); - -private: - - QtTreePropertyBrowserPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtTreePropertyBrowser) - Q_DISABLE_COPY(QtTreePropertyBrowser) - - Q_PRIVATE_SLOT(d_func(), void slotCollapsed(const QModelIndex &)) - Q_PRIVATE_SLOT(d_func(), void slotExpanded(const QModelIndex &)) - Q_PRIVATE_SLOT(d_func(), void slotCurrentBrowserItemChanged(QtBrowserItem *)) - Q_PRIVATE_SLOT(d_func(), void slotCurrentTreeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)) - -}; - -#if QT_VERSION >= 0x040400 -QT_END_NAMESPACE -#endif - -#endif diff --git a/QtPropertyBrowser/qtvariantproperty.cpp b/QtPropertyBrowser/qtvariantproperty.cpp deleted file mode 100644 index 820e6e2f15..0000000000 --- a/QtPropertyBrowser/qtvariantproperty.cpp +++ /dev/null @@ -1,2329 +0,0 @@ -/**************************************************************************** -** -** This file is part of a Qt Solutions component. -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Solutions Commercial License Agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** Please note Third Party Software included with Qt Solutions may impose -** additional restrictions and it is the user's responsibility to ensure -** that they have met the licensing requirements of the GPL, LGPL, or Qt -** Solutions Commercial license and the relevant license of the Third -** Party Software they are using. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qtvariantproperty.h" -#include "qtpropertymanager.h" -#include "qteditorfactory.h" -#include -#include -#include -#include - -#if defined(Q_CC_MSVC) -# pragma warning(disable: 4786) /* MS VS 6: truncating debug info after 255 characters */ -#endif - -#if QT_VERSION >= 0x040400 -QT_BEGIN_NAMESPACE -#endif - -class QtEnumPropertyType -{ -}; - - -class QtFlagPropertyType -{ -}; - - -class QtGroupPropertyType -{ -}; - -#if QT_VERSION >= 0x040400 -QT_END_NAMESPACE -#endif - -Q_DECLARE_METATYPE(QtEnumPropertyType) -Q_DECLARE_METATYPE(QtFlagPropertyType) -Q_DECLARE_METATYPE(QtGroupPropertyType) - -#if QT_VERSION >= 0x040400 -QT_BEGIN_NAMESPACE -#endif - -/*! - Returns the type id for an enum property. - - Note that the property's value type can be retrieved using the - valueType() function (which is QVariant::Int for the enum property - type). - - \sa propertyType(), valueType() -*/ -int QtVariantPropertyManager::enumTypeId() -{ - return qMetaTypeId(); -} - -/*! - Returns the type id for a flag property. - - Note that the property's value type can be retrieved using the - valueType() function (which is QVariant::Int for the flag property - type). - - \sa propertyType(), valueType() -*/ -int QtVariantPropertyManager::flagTypeId() -{ - return qMetaTypeId(); -} - -/*! - Returns the type id for a group property. - - Note that the property's value type can be retrieved using the - valueType() function (which is QVariant::Invalid for the group - property type, since it doesn't provide any value). - - \sa propertyType(), valueType() -*/ -int QtVariantPropertyManager::groupTypeId() -{ - return qMetaTypeId(); -} - -/*! - Returns the type id for a icon map attribute. - - Note that the property's attribute type can be retrieved using the - attributeType() function. - - \sa attributeType(), QtEnumPropertyManager::enumIcons() -*/ -int QtVariantPropertyManager::iconMapTypeId() -{ - return qMetaTypeId(); -} - -typedef QMap PropertyMap; -Q_GLOBAL_STATIC(PropertyMap, propertyToWrappedProperty) - -static QtProperty *wrappedProperty(QtProperty *property) -{ - return propertyToWrappedProperty()->value(property, 0); -} - -class QtVariantPropertyPrivate -{ - QtVariantProperty *q_ptr; -public: - QtVariantPropertyPrivate(QtVariantPropertyManager *m) : manager(m) {} - - QtVariantPropertyManager *manager; -}; - -/*! - \class QtVariantProperty - - \brief The QtVariantProperty class is a convenience class handling - QVariant based properties. - - QtVariantProperty provides additional API: A property's type, - value type, attribute values and current value can easily be - retrieved using the propertyType(), valueType(), attributeValue() - and value() functions respectively. In addition, the attribute - values and the current value can be set using the corresponding - setValue() and setAttribute() functions. - - For example, instead of writing: - - \code - QtVariantPropertyManager *variantPropertyManager; - QtProperty *property; - - variantPropertyManager->setValue(property, 10); - \endcode - - you can write: - - \code - QtVariantPropertyManager *variantPropertyManager; - QtVariantProperty *property; - - property->setValue(10); - \endcode - - QtVariantProperty instances can only be created by the - QtVariantPropertyManager class. - - \sa QtProperty, QtVariantPropertyManager, QtVariantEditorFactory -*/ - -/*! - Creates a variant property using the given \a manager. - - Do not use this constructor to create variant property instances; - use the QtVariantPropertyManager::addProperty() function - instead. This constructor is used internally by the - QtVariantPropertyManager::createProperty() function. - - \sa QtVariantPropertyManager -*/ -QtVariantProperty::QtVariantProperty(QtVariantPropertyManager *manager) - : QtProperty(manager), d_ptr(new QtVariantPropertyPrivate(manager)) -{ - -} - -/*! - Destroys this property. - - \sa QtProperty::~QtProperty() -*/ -QtVariantProperty::~QtVariantProperty() -{ - delete d_ptr; -} - -/*! - Returns the property's current value. - - \sa valueType(), setValue() -*/ -QVariant QtVariantProperty::value() const -{ - return d_ptr->manager->value(this); -} - -/*! - Returns this property's value for the specified \a attribute. - - QtVariantPropertyManager provides a couple of related functions: - \l{QtVariantPropertyManager::attributes()}{attributes()} and - \l{QtVariantPropertyManager::attributeType()}{attributeType()}. - - \sa setAttribute() -*/ -QVariant QtVariantProperty::attributeValue(const QString &attribute) const -{ - return d_ptr->manager->attributeValue(this, attribute); -} - -/*! - Returns the type of this property's value. - - \sa propertyType() -*/ -int QtVariantProperty::valueType() const -{ - return d_ptr->manager->valueType(this); -} - -/*! - Returns this property's type. - - QtVariantPropertyManager provides several related functions: - \l{QtVariantPropertyManager::enumTypeId()}{enumTypeId()}, - \l{QtVariantPropertyManager::flagTypeId()}{flagTypeId()} and - \l{QtVariantPropertyManager::groupTypeId()}{groupTypeId()}. - - \sa valueType() -*/ -int QtVariantProperty::propertyType() const -{ - return d_ptr->manager->propertyType(this); -} - -/*! - Sets the value of this property to \a value. - - The specified \a value must be of the type returned by - valueType(), or of a type that can be converted to valueType() - using the QVariant::canConvert() function; otherwise this function - does nothing. - - \sa value() -*/ -void QtVariantProperty::setValue(const QVariant &value) -{ - d_ptr->manager->setValue(this, value); -} - -/*! - Sets the \a attribute of property to \a value. - - QtVariantPropertyManager provides the related - \l{QtVariantPropertyManager::setAttribute()}{setAttribute()} - function. - - \sa attributeValue() -*/ -void QtVariantProperty::setAttribute(const QString &attribute, const QVariant &value) -{ - d_ptr->manager->setAttribute(this, attribute, value); -} - -class QtVariantPropertyManagerPrivate -{ - QtVariantPropertyManager *q_ptr; - Q_DECLARE_PUBLIC(QtVariantPropertyManager) -public: - QtVariantPropertyManagerPrivate(); - - bool m_creatingProperty; - bool m_creatingSubProperties; - bool m_destroyingSubProperties; - int m_propertyType; - - void slotValueChanged(QtProperty *property, int val); - void slotRangeChanged(QtProperty *property, int min, int max); - void slotSingleStepChanged(QtProperty *property, int step); - void slotValueChanged(QtProperty *property, double val); - void slotRangeChanged(QtProperty *property, double min, double max); - void slotSingleStepChanged(QtProperty *property, double step); - void slotDecimalsChanged(QtProperty *property, int prec); - void slotValueChanged(QtProperty *property, bool val); - void slotValueChanged(QtProperty *property, const QString &val); - void slotRegExpChanged(QtProperty *property, const QRegExp ®Exp); - void slotValueChanged(QtProperty *property, const QDate &val); - void slotRangeChanged(QtProperty *property, const QDate &min, const QDate &max); - void slotValueChanged(QtProperty *property, const QTime &val); - void slotValueChanged(QtProperty *property, const QDateTime &val); - void slotValueChanged(QtProperty *property, const QKeySequence &val); - void slotValueChanged(QtProperty *property, const QChar &val); - void slotValueChanged(QtProperty *property, const QLocale &val); - void slotValueChanged(QtProperty *property, const QPoint &val); - void slotValueChanged(QtProperty *property, const QPointF &val); - void slotValueChanged(QtProperty *property, const QSize &val); - void slotRangeChanged(QtProperty *property, const QSize &min, const QSize &max); - void slotValueChanged(QtProperty *property, const QSizeF &val); - void slotRangeChanged(QtProperty *property, const QSizeF &min, const QSizeF &max); - void slotValueChanged(QtProperty *property, const QRect &val); - void slotConstraintChanged(QtProperty *property, const QRect &val); - void slotValueChanged(QtProperty *property, const QRectF &val); - void slotConstraintChanged(QtProperty *property, const QRectF &val); - void slotValueChanged(QtProperty *property, const QColor &val); - void slotEnumChanged(QtProperty *property, int val); - void slotEnumNamesChanged(QtProperty *property, const QStringList &enumNames); - void slotEnumIconsChanged(QtProperty *property, const QMap &enumIcons); - void slotValueChanged(QtProperty *property, const QSizePolicy &val); - void slotValueChanged(QtProperty *property, const QFont &val); - void slotValueChanged(QtProperty *property, const QCursor &val); - void slotFlagChanged(QtProperty *property, int val); - void slotFlagNamesChanged(QtProperty *property, const QStringList &flagNames); - void slotPropertyInserted(QtProperty *property, QtProperty *parent, QtProperty *after); - void slotPropertyRemoved(QtProperty *property, QtProperty *parent); - - void valueChanged(QtProperty *property, const QVariant &val); - - int internalPropertyToType(QtProperty *property) const; - QtVariantProperty *createSubProperty(QtVariantProperty *parent, QtVariantProperty *after, - QtProperty *internal); - void removeSubProperty(QtVariantProperty *property); - - QMap m_typeToPropertyManager; - QMap > m_typeToAttributeToAttributeType; - - QMap > m_propertyToType; - - QMap m_typeToValueType; - - - QMap m_internalToProperty; - - const QString m_constraintAttribute; - const QString m_singleStepAttribute; - const QString m_decimalsAttribute; - const QString m_enumIconsAttribute; - const QString m_enumNamesAttribute; - const QString m_flagNamesAttribute; - const QString m_maximumAttribute; - const QString m_minimumAttribute; - const QString m_regExpAttribute; -}; - -QtVariantPropertyManagerPrivate::QtVariantPropertyManagerPrivate() : - m_constraintAttribute(QLatin1String("constraint")), - m_singleStepAttribute(QLatin1String("singleStep")), - m_decimalsAttribute(QLatin1String("decimals")), - m_enumIconsAttribute(QLatin1String("enumIcons")), - m_enumNamesAttribute(QLatin1String("enumNames")), - m_flagNamesAttribute(QLatin1String("flagNames")), - m_maximumAttribute(QLatin1String("maximum")), - m_minimumAttribute(QLatin1String("minimum")), - m_regExpAttribute(QLatin1String("regExp")) -{ -} - -int QtVariantPropertyManagerPrivate::internalPropertyToType(QtProperty *property) const -{ - int type = 0; - QtAbstractPropertyManager *internPropertyManager = property->propertyManager(); - if (qobject_cast(internPropertyManager)) - type = QVariant::Int; - else if (qobject_cast(internPropertyManager)) - type = QtVariantPropertyManager::enumTypeId(); - else if (qobject_cast(internPropertyManager)) - type = QVariant::Bool; - else if (qobject_cast(internPropertyManager)) - type = QVariant::Double; - return type; -} - -QtVariantProperty *QtVariantPropertyManagerPrivate::createSubProperty(QtVariantProperty *parent, - QtVariantProperty *after, QtProperty *internal) -{ - int type = internalPropertyToType(internal); - if (!type) - return 0; - - bool wasCreatingSubProperties = m_creatingSubProperties; - m_creatingSubProperties = true; - - QtVariantProperty *varChild = q_ptr->addProperty(type, internal->propertyName()); - - m_creatingSubProperties = wasCreatingSubProperties; - - varChild->setPropertyName(internal->propertyName()); - varChild->setToolTip(internal->toolTip()); - varChild->setStatusTip(internal->statusTip()); - varChild->setWhatsThis(internal->whatsThis()); - - parent->insertSubProperty(varChild, after); - - m_internalToProperty[internal] = varChild; - propertyToWrappedProperty()->insert(varChild, internal); - return varChild; -} - -void QtVariantPropertyManagerPrivate::removeSubProperty(QtVariantProperty *property) -{ - QtProperty *internChild = wrappedProperty(property); - bool wasDestroyingSubProperties = m_destroyingSubProperties; - m_destroyingSubProperties = true; - delete property; - m_destroyingSubProperties = wasDestroyingSubProperties; - m_internalToProperty.remove(internChild); - propertyToWrappedProperty()->remove(property); -} - -void QtVariantPropertyManagerPrivate::slotPropertyInserted(QtProperty *property, - QtProperty *parent, QtProperty *after) -{ - if (m_creatingProperty) - return; - - QtVariantProperty *varParent = m_internalToProperty.value(parent, 0); - if (!varParent) - return; - - QtVariantProperty *varAfter = 0; - if (after) { - varAfter = m_internalToProperty.value(after, 0); - if (!varAfter) - return; - } - - createSubProperty(varParent, varAfter, property); -} - -void QtVariantPropertyManagerPrivate::slotPropertyRemoved(QtProperty *property, QtProperty *parent) -{ - Q_UNUSED(parent) - - QtVariantProperty *varProperty = m_internalToProperty.value(property, 0); - if (!varProperty) - return; - - removeSubProperty(varProperty); -} - -void QtVariantPropertyManagerPrivate::valueChanged(QtProperty *property, const QVariant &val) -{ - QtVariantProperty *varProp = m_internalToProperty.value(property, 0); - if (!varProp) - return; - emit q_ptr->valueChanged(varProp, val); - emit q_ptr->propertyChanged(varProp); -} - -void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, int val) -{ - valueChanged(property, QVariant(val)); -} - -void QtVariantPropertyManagerPrivate::slotRangeChanged(QtProperty *property, int min, int max) -{ - if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) { - emit q_ptr->attributeChanged(varProp, m_minimumAttribute, QVariant(min)); - emit q_ptr->attributeChanged(varProp, m_maximumAttribute, QVariant(max)); - } -} - -void QtVariantPropertyManagerPrivate::slotSingleStepChanged(QtProperty *property, int step) -{ - if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) - emit q_ptr->attributeChanged(varProp, m_singleStepAttribute, QVariant(step)); -} - -void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, double val) -{ - valueChanged(property, QVariant(val)); -} - -void QtVariantPropertyManagerPrivate::slotRangeChanged(QtProperty *property, double min, double max) -{ - if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) { - emit q_ptr->attributeChanged(varProp, m_minimumAttribute, QVariant(min)); - emit q_ptr->attributeChanged(varProp, m_maximumAttribute, QVariant(max)); - } -} - -void QtVariantPropertyManagerPrivate::slotSingleStepChanged(QtProperty *property, double step) -{ - if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) - emit q_ptr->attributeChanged(varProp, m_singleStepAttribute, QVariant(step)); -} - -void QtVariantPropertyManagerPrivate::slotDecimalsChanged(QtProperty *property, int prec) -{ - if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) - emit q_ptr->attributeChanged(varProp, m_decimalsAttribute, QVariant(prec)); -} - -void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, bool val) -{ - valueChanged(property, QVariant(val)); -} - -void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QString &val) -{ - valueChanged(property, QVariant(val)); -} - -void QtVariantPropertyManagerPrivate::slotRegExpChanged(QtProperty *property, const QRegExp ®Exp) -{ - if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) - emit q_ptr->attributeChanged(varProp, m_regExpAttribute, QVariant(regExp)); -} - -void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QDate &val) -{ - valueChanged(property, QVariant(val)); -} - -void QtVariantPropertyManagerPrivate::slotRangeChanged(QtProperty *property, const QDate &min, const QDate &max) -{ - if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) { - emit q_ptr->attributeChanged(varProp, m_minimumAttribute, QVariant(min)); - emit q_ptr->attributeChanged(varProp, m_maximumAttribute, QVariant(max)); - } -} - -void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QTime &val) -{ - valueChanged(property, QVariant(val)); -} - -void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QDateTime &val) -{ - valueChanged(property, QVariant(val)); -} - -void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QKeySequence &val) -{ - QVariant v; - qVariantSetValue(v, val); - valueChanged(property, v); -} - -void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QChar &val) -{ - valueChanged(property, QVariant(val)); -} - -void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QLocale &val) -{ - valueChanged(property, QVariant(val)); -} - -void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QPoint &val) -{ - valueChanged(property, QVariant(val)); -} - -void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QPointF &val) -{ - valueChanged(property, QVariant(val)); -} - -void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QSize &val) -{ - valueChanged(property, QVariant(val)); -} - -void QtVariantPropertyManagerPrivate::slotRangeChanged(QtProperty *property, const QSize &min, const QSize &max) -{ - if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) { - emit q_ptr->attributeChanged(varProp, m_minimumAttribute, QVariant(min)); - emit q_ptr->attributeChanged(varProp, m_maximumAttribute, QVariant(max)); - } -} - -void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QSizeF &val) -{ - valueChanged(property, QVariant(val)); -} - -void QtVariantPropertyManagerPrivate::slotRangeChanged(QtProperty *property, const QSizeF &min, const QSizeF &max) -{ - if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) { - emit q_ptr->attributeChanged(varProp, m_minimumAttribute, QVariant(min)); - emit q_ptr->attributeChanged(varProp, m_maximumAttribute, QVariant(max)); - } -} - -void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QRect &val) -{ - valueChanged(property, QVariant(val)); -} - -void QtVariantPropertyManagerPrivate::slotConstraintChanged(QtProperty *property, const QRect &constraint) -{ - if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) - emit q_ptr->attributeChanged(varProp, m_constraintAttribute, QVariant(constraint)); -} - -void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QRectF &val) -{ - valueChanged(property, QVariant(val)); -} - -void QtVariantPropertyManagerPrivate::slotConstraintChanged(QtProperty *property, const QRectF &constraint) -{ - if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) - emit q_ptr->attributeChanged(varProp, m_constraintAttribute, QVariant(constraint)); -} - -void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QColor &val) -{ - valueChanged(property, QVariant(val)); -} - -void QtVariantPropertyManagerPrivate::slotEnumNamesChanged(QtProperty *property, const QStringList &enumNames) -{ - if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) - emit q_ptr->attributeChanged(varProp, m_enumNamesAttribute, QVariant(enumNames)); -} - -void QtVariantPropertyManagerPrivate::slotEnumIconsChanged(QtProperty *property, const QMap &enumIcons) -{ - if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) { - QVariant v; - qVariantSetValue(v, enumIcons); - emit q_ptr->attributeChanged(varProp, m_enumIconsAttribute, v); - } -} - -void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QSizePolicy &val) -{ - valueChanged(property, QVariant(val)); -} - -void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QFont &val) -{ - valueChanged(property, QVariant(val)); -} - -void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QCursor &val) -{ -#ifndef QT_NO_CURSOR - valueChanged(property, QVariant(val)); -#endif -} - -void QtVariantPropertyManagerPrivate::slotFlagNamesChanged(QtProperty *property, const QStringList &flagNames) -{ - if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) - emit q_ptr->attributeChanged(varProp, m_flagNamesAttribute, QVariant(flagNames)); -} - -/*! - \class QtVariantPropertyManager - - \brief The QtVariantPropertyManager class provides and manages QVariant based properties. - - QtVariantPropertyManager provides the addProperty() function which - creates QtVariantProperty objects. The QtVariantProperty class is - a convenience class handling QVariant based properties inheriting - QtProperty. A QtProperty object created by a - QtVariantPropertyManager instance can be converted into a - QtVariantProperty object using the variantProperty() function. - - The property's value can be retrieved using the value(), and set - using the setValue() slot. In addition the property's type, and - the type of its value, can be retrieved using the propertyType() - and valueType() functions respectively. - - A property's type is a QVariant::Type enumerator value, and - usually a property's type is the same as its value type. But for - some properties the types differ, for example for enums, flags and - group types in which case QtVariantPropertyManager provides the - enumTypeId(), flagTypeId() and groupTypeId() functions, - respectively, to identify their property type (the value types are - QVariant::Int for the enum and flag types, and QVariant::Invalid - for the group type). - - Use the isPropertyTypeSupported() function to check if a particular - property type is supported. The currently supported property types - are: - - \table - \header - \o Property Type - \o Property Type Id - \row - \o int - \o QVariant::Int - \row - \o double - \o QVariant::Double - \row - \o bool - \o QVariant::Bool - \row - \o QString - \o QVariant::String - \row - \o QDate - \o QVariant::Date - \row - \o QTime - \o QVariant::Time - \row - \o QDateTime - \o QVariant::DateTime - \row - \o QKeySequence - \o QVariant::KeySequence - \row - \o QChar - \o QVariant::Char - \row - \o QLocale - \o QVariant::Locale - \row - \o QPoint - \o QVariant::Point - \row - \o QPointF - \o QVariant::PointF - \row - \o QSize - \o QVariant::Size - \row - \o QSizeF - \o QVariant::SizeF - \row - \o QRect - \o QVariant::Rect - \row - \o QRectF - \o QVariant::RectF - \row - \o QColor - \o QVariant::Color - \row - \o QSizePolicy - \o QVariant::SizePolicy - \row - \o QFont - \o QVariant::Font - \row - \o QCursor - \o QVariant::Cursor - \row - \o enum - \o enumTypeId() - \row - \o flag - \o flagTypeId() - \row - \o group - \o groupTypeId() - \endtable - - Each property type can provide additional attributes, - e.g. QVariant::Int and QVariant::Double provides minimum and - maximum values. The currently supported attributes are: - - \table - \header - \o Property Type - \o Attribute Name - \o Attribute Type - \row - \o \c int - \o minimum - \o QVariant::Int - \row - \o - \o maximum - \o QVariant::Int - \row - \o - \o singleStep - \o QVariant::Int - \row - \o \c double - \o minimum - \o QVariant::Double - \row - \o - \o maximum - \o QVariant::Double - \row - \o - \o singleStep - \o QVariant::Double - \row - \o - \o decimals - \o QVariant::Int - \row - \o QString - \o regExp - \o QVariant::RegExp - \row - \o QDate - \o minimum - \o QVariant::Date - \row - \o - \o maximum - \o QVariant::Date - \row - \o QPointF - \o decimals - \o QVariant::Int - \row - \o QSize - \o minimum - \o QVariant::Size - \row - \o - \o maximum - \o QVariant::Size - \row - \o QSizeF - \o minimum - \o QVariant::SizeF - \row - \o - \o maximum - \o QVariant::SizeF - \row - \o - \o decimals - \o QVariant::Int - \row - \o QRect - \o constraint - \o QVariant::Rect - \row - \o QRectF - \o constraint - \o QVariant::RectF - \row - \o - \o decimals - \o QVariant::Int - \row - \o \c enum - \o enumNames - \o QVariant::StringList - \row - \o - \o enumIcons - \o iconMapTypeId() - \row - \o \c flag - \o flagNames - \o QVariant::StringList - \endtable - - The attributes for a given property type can be retrieved using - the attributes() function. Each attribute has a value type which - can be retrieved using the attributeType() function, and a value - accessible through the attributeValue() function. In addition, the - value can be set using the setAttribute() slot. - - QtVariantManager also provides the valueChanged() signal which is - emitted whenever a property created by this manager change, and - the attributeChanged() signal which is emitted whenever an - attribute of such a property changes. - - \sa QtVariantProperty, QtVariantEditorFactory -*/ - -/*! - \fn void QtVariantPropertyManager::valueChanged(QtProperty *property, const QVariant &value) - - This signal is emitted whenever a property created by this manager - changes its value, passing a pointer to the \a property and the - new \a value as parameters. - - \sa setValue() -*/ - -/*! - \fn void QtVariantPropertyManager::attributeChanged(QtProperty *property, - const QString &attribute, const QVariant &value) - - This signal is emitted whenever an attribute of a property created - by this manager changes its value, passing a pointer to the \a - property, the \a attribute and the new \a value as parameters. - - \sa setAttribute() -*/ - -/*! - Creates a manager with the given \a parent. -*/ -QtVariantPropertyManager::QtVariantPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) -{ - d_ptr = new QtVariantPropertyManagerPrivate; - d_ptr->q_ptr = this; - - d_ptr->m_creatingProperty = false; - d_ptr->m_creatingSubProperties = false; - d_ptr->m_destroyingSubProperties = false; - d_ptr->m_propertyType = 0; - - // IntPropertyManager - QtIntPropertyManager *intPropertyManager = new QtIntPropertyManager(this); - d_ptr->m_typeToPropertyManager[QVariant::Int] = intPropertyManager; - d_ptr->m_typeToAttributeToAttributeType[QVariant::Int][d_ptr->m_minimumAttribute] = QVariant::Int; - d_ptr->m_typeToAttributeToAttributeType[QVariant::Int][d_ptr->m_maximumAttribute] = QVariant::Int; - d_ptr->m_typeToAttributeToAttributeType[QVariant::Int][d_ptr->m_singleStepAttribute] = QVariant::Int; - d_ptr->m_typeToValueType[QVariant::Int] = QVariant::Int; - connect(intPropertyManager, SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotValueChanged(QtProperty *, int))); - connect(intPropertyManager, SIGNAL(rangeChanged(QtProperty *, int, int)), - this, SLOT(slotRangeChanged(QtProperty *, int, int))); - connect(intPropertyManager, SIGNAL(singleStepChanged(QtProperty *, int)), - this, SLOT(slotSingleStepChanged(QtProperty *, int))); - // DoublePropertyManager - QtDoublePropertyManager *doublePropertyManager = new QtDoublePropertyManager(this); - d_ptr->m_typeToPropertyManager[QVariant::Double] = doublePropertyManager; - d_ptr->m_typeToAttributeToAttributeType[QVariant::Double][d_ptr->m_minimumAttribute] = - QVariant::Double; - d_ptr->m_typeToAttributeToAttributeType[QVariant::Double][d_ptr->m_maximumAttribute] = - QVariant::Double; - d_ptr->m_typeToAttributeToAttributeType[QVariant::Double][d_ptr->m_singleStepAttribute] = - QVariant::Double; - d_ptr->m_typeToAttributeToAttributeType[QVariant::Double][d_ptr->m_decimalsAttribute] = - QVariant::Int; - d_ptr->m_typeToValueType[QVariant::Double] = QVariant::Double; - connect(doublePropertyManager, SIGNAL(valueChanged(QtProperty *, double)), - this, SLOT(slotValueChanged(QtProperty *, double))); - connect(doublePropertyManager, SIGNAL(rangeChanged(QtProperty *, double, double)), - this, SLOT(slotRangeChanged(QtProperty *, double, double))); - connect(doublePropertyManager, SIGNAL(singleStepChanged(QtProperty *, double)), - this, SLOT(slotSingleStepChanged(QtProperty *, double))); - connect(doublePropertyManager, SIGNAL(decimalsChanged(QtProperty *, int)), - this, SLOT(slotDecimalsChanged(QtProperty *, int))); - // BoolPropertyManager - QtBoolPropertyManager *boolPropertyManager = new QtBoolPropertyManager(this); - d_ptr->m_typeToPropertyManager[QVariant::Bool] = boolPropertyManager; - d_ptr->m_typeToValueType[QVariant::Bool] = QVariant::Bool; - connect(boolPropertyManager, SIGNAL(valueChanged(QtProperty *, bool)), - this, SLOT(slotValueChanged(QtProperty *, bool))); - // StringPropertyManager - QtStringPropertyManager *stringPropertyManager = new QtStringPropertyManager(this); - d_ptr->m_typeToPropertyManager[QVariant::String] = stringPropertyManager; - d_ptr->m_typeToValueType[QVariant::String] = QVariant::String; - d_ptr->m_typeToAttributeToAttributeType[QVariant::String][d_ptr->m_regExpAttribute] = - QVariant::RegExp; - connect(stringPropertyManager, SIGNAL(valueChanged(QtProperty *, const QString &)), - this, SLOT(slotValueChanged(QtProperty *, const QString &))); - connect(stringPropertyManager, SIGNAL(regExpChanged(QtProperty *, const QRegExp &)), - this, SLOT(slotRegExpChanged(QtProperty *, const QRegExp &))); - // DatePropertyManager - QtDatePropertyManager *datePropertyManager = new QtDatePropertyManager(this); - d_ptr->m_typeToPropertyManager[QVariant::Date] = datePropertyManager; - d_ptr->m_typeToValueType[QVariant::Date] = QVariant::Date; - d_ptr->m_typeToAttributeToAttributeType[QVariant::Date][d_ptr->m_minimumAttribute] = - QVariant::Date; - d_ptr->m_typeToAttributeToAttributeType[QVariant::Date][d_ptr->m_maximumAttribute] = - QVariant::Date; - connect(datePropertyManager, SIGNAL(valueChanged(QtProperty *, const QDate &)), - this, SLOT(slotValueChanged(QtProperty *, const QDate &))); - connect(datePropertyManager, SIGNAL(rangeChanged(QtProperty *, const QDate &, const QDate &)), - this, SLOT(slotRangeChanged(QtProperty *, const QDate &, const QDate &))); - // TimePropertyManager - QtTimePropertyManager *timePropertyManager = new QtTimePropertyManager(this); - d_ptr->m_typeToPropertyManager[QVariant::Time] = timePropertyManager; - d_ptr->m_typeToValueType[QVariant::Time] = QVariant::Time; - connect(timePropertyManager, SIGNAL(valueChanged(QtProperty *, const QTime &)), - this, SLOT(slotValueChanged(QtProperty *, const QTime &))); - // DateTimePropertyManager - QtDateTimePropertyManager *dateTimePropertyManager = new QtDateTimePropertyManager(this); - d_ptr->m_typeToPropertyManager[QVariant::DateTime] = dateTimePropertyManager; - d_ptr->m_typeToValueType[QVariant::DateTime] = QVariant::DateTime; - connect(dateTimePropertyManager, SIGNAL(valueChanged(QtProperty *, const QDateTime &)), - this, SLOT(slotValueChanged(QtProperty *, const QDateTime &))); - // KeySequencePropertyManager - QtKeySequencePropertyManager *keySequencePropertyManager = new QtKeySequencePropertyManager(this); - d_ptr->m_typeToPropertyManager[QVariant::KeySequence] = keySequencePropertyManager; - d_ptr->m_typeToValueType[QVariant::KeySequence] = QVariant::KeySequence; - connect(keySequencePropertyManager, SIGNAL(valueChanged(QtProperty *, const QKeySequence &)), - this, SLOT(slotValueChanged(QtProperty *, const QKeySequence &))); - // CharPropertyManager - QtCharPropertyManager *charPropertyManager = new QtCharPropertyManager(this); - d_ptr->m_typeToPropertyManager[QVariant::Char] = charPropertyManager; - d_ptr->m_typeToValueType[QVariant::Char] = QVariant::Char; - connect(charPropertyManager, SIGNAL(valueChanged(QtProperty *, const QChar &)), - this, SLOT(slotValueChanged(QtProperty *, const QChar &))); - // LocalePropertyManager - QtLocalePropertyManager *localePropertyManager = new QtLocalePropertyManager(this); - d_ptr->m_typeToPropertyManager[QVariant::Locale] = localePropertyManager; - d_ptr->m_typeToValueType[QVariant::Locale] = QVariant::Locale; - connect(localePropertyManager, SIGNAL(valueChanged(QtProperty *, const QLocale &)), - this, SLOT(slotValueChanged(QtProperty *, const QLocale &))); - connect(localePropertyManager->subEnumPropertyManager(), SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotValueChanged(QtProperty *, int))); - connect(localePropertyManager, SIGNAL(propertyInserted(QtProperty *, QtProperty *, QtProperty *)), - this, SLOT(slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *))); - connect(localePropertyManager, SIGNAL(propertyRemoved(QtProperty *, QtProperty *)), - this, SLOT(slotPropertyRemoved(QtProperty *, QtProperty *))); - // PointPropertyManager - QtPointPropertyManager *pointPropertyManager = new QtPointPropertyManager(this); - d_ptr->m_typeToPropertyManager[QVariant::Point] = pointPropertyManager; - d_ptr->m_typeToValueType[QVariant::Point] = QVariant::Point; - connect(pointPropertyManager, SIGNAL(valueChanged(QtProperty *, const QPoint &)), - this, SLOT(slotValueChanged(QtProperty *, const QPoint &))); - connect(pointPropertyManager->subIntPropertyManager(), SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotValueChanged(QtProperty *, int))); - connect(pointPropertyManager, SIGNAL(propertyInserted(QtProperty *, QtProperty *, QtProperty *)), - this, SLOT(slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *))); - connect(pointPropertyManager, SIGNAL(propertyRemoved(QtProperty *, QtProperty *)), - this, SLOT(slotPropertyRemoved(QtProperty *, QtProperty *))); - // PointFPropertyManager - QtPointFPropertyManager *pointFPropertyManager = new QtPointFPropertyManager(this); - d_ptr->m_typeToPropertyManager[QVariant::PointF] = pointFPropertyManager; - d_ptr->m_typeToValueType[QVariant::PointF] = QVariant::PointF; - d_ptr->m_typeToAttributeToAttributeType[QVariant::PointF][d_ptr->m_decimalsAttribute] = - QVariant::Int; - connect(pointFPropertyManager, SIGNAL(valueChanged(QtProperty *, const QPointF &)), - this, SLOT(slotValueChanged(QtProperty *, const QPointF &))); - connect(pointFPropertyManager, SIGNAL(decimalsChanged(QtProperty *, int)), - this, SLOT(slotDecimalsChanged(QtProperty *, int))); - connect(pointFPropertyManager->subDoublePropertyManager(), SIGNAL(valueChanged(QtProperty *, double)), - this, SLOT(slotValueChanged(QtProperty *, double))); - connect(pointFPropertyManager, SIGNAL(propertyInserted(QtProperty *, QtProperty *, QtProperty *)), - this, SLOT(slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *))); - connect(pointFPropertyManager, SIGNAL(propertyRemoved(QtProperty *, QtProperty *)), - this, SLOT(slotPropertyRemoved(QtProperty *, QtProperty *))); - // SizePropertyManager - QtSizePropertyManager *sizePropertyManager = new QtSizePropertyManager(this); - d_ptr->m_typeToPropertyManager[QVariant::Size] = sizePropertyManager; - d_ptr->m_typeToValueType[QVariant::Size] = QVariant::Size; - d_ptr->m_typeToAttributeToAttributeType[QVariant::Size][d_ptr->m_minimumAttribute] = - QVariant::Size; - d_ptr->m_typeToAttributeToAttributeType[QVariant::Size][d_ptr->m_maximumAttribute] = - QVariant::Size; - connect(sizePropertyManager, SIGNAL(valueChanged(QtProperty *, const QSize &)), - this, SLOT(slotValueChanged(QtProperty *, const QSize &))); - connect(sizePropertyManager, SIGNAL(rangeChanged(QtProperty *, const QSize &, const QSize &)), - this, SLOT(slotRangeChanged(QtProperty *, const QSize &, const QSize &))); - connect(sizePropertyManager->subIntPropertyManager(), SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotValueChanged(QtProperty *, int))); - connect(sizePropertyManager->subIntPropertyManager(), SIGNAL(rangeChanged(QtProperty *, int, int)), - this, SLOT(slotRangeChanged(QtProperty *, int, int))); - connect(sizePropertyManager, SIGNAL(propertyInserted(QtProperty *, QtProperty *, QtProperty *)), - this, SLOT(slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *))); - connect(sizePropertyManager, SIGNAL(propertyRemoved(QtProperty *, QtProperty *)), - this, SLOT(slotPropertyRemoved(QtProperty *, QtProperty *))); - // SizeFPropertyManager - QtSizeFPropertyManager *sizeFPropertyManager = new QtSizeFPropertyManager(this); - d_ptr->m_typeToPropertyManager[QVariant::SizeF] = sizeFPropertyManager; - d_ptr->m_typeToValueType[QVariant::SizeF] = QVariant::SizeF; - d_ptr->m_typeToAttributeToAttributeType[QVariant::SizeF][d_ptr->m_minimumAttribute] = - QVariant::SizeF; - d_ptr->m_typeToAttributeToAttributeType[QVariant::SizeF][d_ptr->m_maximumAttribute] = - QVariant::SizeF; - d_ptr->m_typeToAttributeToAttributeType[QVariant::SizeF][d_ptr->m_decimalsAttribute] = - QVariant::Int; - connect(sizeFPropertyManager, SIGNAL(valueChanged(QtProperty *, const QSizeF &)), - this, SLOT(slotValueChanged(QtProperty *, const QSizeF &))); - connect(sizeFPropertyManager, SIGNAL(rangeChanged(QtProperty *, const QSizeF &, const QSizeF &)), - this, SLOT(slotRangeChanged(QtProperty *, const QSizeF &, const QSizeF &))); - connect(sizeFPropertyManager, SIGNAL(decimalsChanged(QtProperty *, int)), - this, SLOT(slotDecimalsChanged(QtProperty *, int))); - connect(sizeFPropertyManager->subDoublePropertyManager(), SIGNAL(valueChanged(QtProperty *, double)), - this, SLOT(slotValueChanged(QtProperty *, double))); - connect(sizeFPropertyManager->subDoublePropertyManager(), SIGNAL(rangeChanged(QtProperty *, double, double)), - this, SLOT(slotRangeChanged(QtProperty *, double, double))); - connect(sizeFPropertyManager, SIGNAL(propertyInserted(QtProperty *, QtProperty *, QtProperty *)), - this, SLOT(slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *))); - connect(sizeFPropertyManager, SIGNAL(propertyRemoved(QtProperty *, QtProperty *)), - this, SLOT(slotPropertyRemoved(QtProperty *, QtProperty *))); - // RectPropertyManager - QtRectPropertyManager *rectPropertyManager = new QtRectPropertyManager(this); - d_ptr->m_typeToPropertyManager[QVariant::Rect] = rectPropertyManager; - d_ptr->m_typeToValueType[QVariant::Rect] = QVariant::Rect; - d_ptr->m_typeToAttributeToAttributeType[QVariant::Rect][d_ptr->m_constraintAttribute] = - QVariant::Rect; - connect(rectPropertyManager, SIGNAL(valueChanged(QtProperty *, const QRect &)), - this, SLOT(slotValueChanged(QtProperty *, const QRect &))); - connect(rectPropertyManager, SIGNAL(constraintChanged(QtProperty *, const QRect &)), - this, SLOT(slotConstraintChanged(QtProperty *, const QRect &))); - connect(rectPropertyManager->subIntPropertyManager(), SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotValueChanged(QtProperty *, int))); - connect(rectPropertyManager->subIntPropertyManager(), SIGNAL(rangeChanged(QtProperty *, int, int)), - this, SLOT(slotRangeChanged(QtProperty *, int, int))); - connect(rectPropertyManager, SIGNAL(propertyInserted(QtProperty *, QtProperty *, QtProperty *)), - this, SLOT(slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *))); - connect(rectPropertyManager, SIGNAL(propertyRemoved(QtProperty *, QtProperty *)), - this, SLOT(slotPropertyRemoved(QtProperty *, QtProperty *))); - // RectFPropertyManager - QtRectFPropertyManager *rectFPropertyManager = new QtRectFPropertyManager(this); - d_ptr->m_typeToPropertyManager[QVariant::RectF] = rectFPropertyManager; - d_ptr->m_typeToValueType[QVariant::RectF] = QVariant::RectF; - d_ptr->m_typeToAttributeToAttributeType[QVariant::RectF][d_ptr->m_constraintAttribute] = - QVariant::RectF; - d_ptr->m_typeToAttributeToAttributeType[QVariant::RectF][d_ptr->m_decimalsAttribute] = - QVariant::Int; - connect(rectFPropertyManager, SIGNAL(valueChanged(QtProperty *, const QRectF &)), - this, SLOT(slotValueChanged(QtProperty *, const QRectF &))); - connect(rectFPropertyManager, SIGNAL(constraintChanged(QtProperty *, const QRectF &)), - this, SLOT(slotConstraintChanged(QtProperty *, const QRectF &))); - connect(rectFPropertyManager, SIGNAL(decimalsChanged(QtProperty *, int)), - this, SLOT(slotDecimalsChanged(QtProperty *, int))); - connect(rectFPropertyManager->subDoublePropertyManager(), SIGNAL(valueChanged(QtProperty *, double)), - this, SLOT(slotValueChanged(QtProperty *, double))); - connect(rectFPropertyManager->subDoublePropertyManager(), SIGNAL(rangeChanged(QtProperty *, double, double)), - this, SLOT(slotRangeChanged(QtProperty *, double, double))); - connect(rectFPropertyManager, SIGNAL(propertyInserted(QtProperty *, QtProperty *, QtProperty *)), - this, SLOT(slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *))); - connect(rectFPropertyManager, SIGNAL(propertyRemoved(QtProperty *, QtProperty *)), - this, SLOT(slotPropertyRemoved(QtProperty *, QtProperty *))); - // ColorPropertyManager - QtColorPropertyManager *colorPropertyManager = new QtColorPropertyManager(this); - d_ptr->m_typeToPropertyManager[QVariant::Color] = colorPropertyManager; - d_ptr->m_typeToValueType[QVariant::Color] = QVariant::Color; - connect(colorPropertyManager, SIGNAL(valueChanged(QtProperty *, const QColor &)), - this, SLOT(slotValueChanged(QtProperty *, const QColor &))); - connect(colorPropertyManager->subIntPropertyManager(), SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotValueChanged(QtProperty *, int))); - connect(colorPropertyManager, SIGNAL(propertyInserted(QtProperty *, QtProperty *, QtProperty *)), - this, SLOT(slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *))); - connect(colorPropertyManager, SIGNAL(propertyRemoved(QtProperty *, QtProperty *)), - this, SLOT(slotPropertyRemoved(QtProperty *, QtProperty *))); - // EnumPropertyManager - int enumId = enumTypeId(); - QtEnumPropertyManager *enumPropertyManager = new QtEnumPropertyManager(this); - d_ptr->m_typeToPropertyManager[enumId] = enumPropertyManager; - d_ptr->m_typeToValueType[enumId] = QVariant::Int; - d_ptr->m_typeToAttributeToAttributeType[enumId][d_ptr->m_enumNamesAttribute] = - QVariant::StringList; - d_ptr->m_typeToAttributeToAttributeType[enumId][d_ptr->m_enumIconsAttribute] = - iconMapTypeId(); - connect(enumPropertyManager, SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotValueChanged(QtProperty *, int))); - connect(enumPropertyManager, SIGNAL(enumNamesChanged(QtProperty *, const QStringList &)), - this, SLOT(slotEnumNamesChanged(QtProperty *, const QStringList &))); - connect(enumPropertyManager, SIGNAL(enumIconsChanged(QtProperty *, const QMap &)), - this, SLOT(slotEnumIconsChanged(QtProperty *, const QMap &))); - // SizePolicyPropertyManager - QtSizePolicyPropertyManager *sizePolicyPropertyManager = new QtSizePolicyPropertyManager(this); - d_ptr->m_typeToPropertyManager[QVariant::SizePolicy] = sizePolicyPropertyManager; - d_ptr->m_typeToValueType[QVariant::SizePolicy] = QVariant::SizePolicy; - connect(sizePolicyPropertyManager, SIGNAL(valueChanged(QtProperty *, const QSizePolicy &)), - this, SLOT(slotValueChanged(QtProperty *, const QSizePolicy &))); - connect(sizePolicyPropertyManager->subIntPropertyManager(), SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotValueChanged(QtProperty *, int))); - connect(sizePolicyPropertyManager->subIntPropertyManager(), SIGNAL(rangeChanged(QtProperty *, int, int)), - this, SLOT(slotRangeChanged(QtProperty *, int, int))); - connect(sizePolicyPropertyManager->subEnumPropertyManager(), SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotValueChanged(QtProperty *, int))); - connect(sizePolicyPropertyManager->subEnumPropertyManager(), - SIGNAL(enumNamesChanged(QtProperty *, const QStringList &)), - this, SLOT(slotEnumNamesChanged(QtProperty *, const QStringList &))); - connect(sizePolicyPropertyManager, SIGNAL(propertyInserted(QtProperty *, QtProperty *, QtProperty *)), - this, SLOT(slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *))); - connect(sizePolicyPropertyManager, SIGNAL(propertyRemoved(QtProperty *, QtProperty *)), - this, SLOT(slotPropertyRemoved(QtProperty *, QtProperty *))); - // FontPropertyManager - QtFontPropertyManager *fontPropertyManager = new QtFontPropertyManager(this); - d_ptr->m_typeToPropertyManager[QVariant::Font] = fontPropertyManager; - d_ptr->m_typeToValueType[QVariant::Font] = QVariant::Font; - connect(fontPropertyManager, SIGNAL(valueChanged(QtProperty *, const QFont &)), - this, SLOT(slotValueChanged(QtProperty *, const QFont &))); - connect(fontPropertyManager->subIntPropertyManager(), SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotValueChanged(QtProperty *, int))); - connect(fontPropertyManager->subIntPropertyManager(), SIGNAL(rangeChanged(QtProperty *, int, int)), - this, SLOT(slotRangeChanged(QtProperty *, int, int))); - connect(fontPropertyManager->subEnumPropertyManager(), SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotValueChanged(QtProperty *, int))); - connect(fontPropertyManager->subEnumPropertyManager(), - SIGNAL(enumNamesChanged(QtProperty *, const QStringList &)), - this, SLOT(slotEnumNamesChanged(QtProperty *, const QStringList &))); - connect(fontPropertyManager->subBoolPropertyManager(), SIGNAL(valueChanged(QtProperty *, bool)), - this, SLOT(slotValueChanged(QtProperty *, bool))); - connect(fontPropertyManager, SIGNAL(propertyInserted(QtProperty *, QtProperty *, QtProperty *)), - this, SLOT(slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *))); - connect(fontPropertyManager, SIGNAL(propertyRemoved(QtProperty *, QtProperty *)), - this, SLOT(slotPropertyRemoved(QtProperty *, QtProperty *))); - // CursorPropertyManager - QtCursorPropertyManager *cursorPropertyManager = new QtCursorPropertyManager(this); - d_ptr->m_typeToPropertyManager[QVariant::Cursor] = cursorPropertyManager; - d_ptr->m_typeToValueType[QVariant::Cursor] = QVariant::Cursor; - connect(cursorPropertyManager, SIGNAL(valueChanged(QtProperty *, const QCursor &)), - this, SLOT(slotValueChanged(QtProperty *, const QCursor &))); - // FlagPropertyManager - int flagId = flagTypeId(); - QtFlagPropertyManager *flagPropertyManager = new QtFlagPropertyManager(this); - d_ptr->m_typeToPropertyManager[flagId] = flagPropertyManager; - d_ptr->m_typeToValueType[flagId] = QVariant::Int; - d_ptr->m_typeToAttributeToAttributeType[flagId][d_ptr->m_flagNamesAttribute] = - QVariant::StringList; - connect(flagPropertyManager, SIGNAL(valueChanged(QtProperty *, int)), - this, SLOT(slotValueChanged(QtProperty *, int))); - connect(flagPropertyManager, SIGNAL(flagNamesChanged(QtProperty *, const QStringList &)), - this, SLOT(slotFlagNamesChanged(QtProperty *, const QStringList &))); - connect(flagPropertyManager->subBoolPropertyManager(), SIGNAL(valueChanged(QtProperty *, bool)), - this, SLOT(slotValueChanged(QtProperty *, bool))); - connect(flagPropertyManager, SIGNAL(propertyInserted(QtProperty *, QtProperty *, QtProperty *)), - this, SLOT(slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *))); - connect(flagPropertyManager, SIGNAL(propertyRemoved(QtProperty *, QtProperty *)), - this, SLOT(slotPropertyRemoved(QtProperty *, QtProperty *))); - // FlagPropertyManager - int groupId = groupTypeId(); - QtGroupPropertyManager *groupPropertyManager = new QtGroupPropertyManager(this); - d_ptr->m_typeToPropertyManager[groupId] = groupPropertyManager; - d_ptr->m_typeToValueType[groupId] = QVariant::Invalid; -} - -/*! - Destroys this manager, and all the properties it has created. -*/ -QtVariantPropertyManager::~QtVariantPropertyManager() -{ - clear(); - delete d_ptr; -} - -/*! - Returns the given \a property converted into a QtVariantProperty. - - If the \a property was not created by this variant manager, the - function returns 0. - - \sa createProperty() -*/ -QtVariantProperty *QtVariantPropertyManager::variantProperty(const QtProperty *property) const -{ - const QMap >::const_iterator it = d_ptr->m_propertyToType.constFind(property); - if (it == d_ptr->m_propertyToType.constEnd()) - return 0; - return it.value().first; -} - -/*! - Returns true if the given \a propertyType is supported by this - variant manager; otherwise false. - - \sa propertyType() -*/ -bool QtVariantPropertyManager::isPropertyTypeSupported(int propertyType) const -{ - if (d_ptr->m_typeToValueType.contains(propertyType)) - return true; - return false; -} - -/*! - Creates and returns a variant property of the given \a propertyType - with the given \a name. - - If the specified \a propertyType is not supported by this variant - manager, this function returns 0. - - Do not use the inherited - QtAbstractPropertyManager::addProperty() function to create a - variant property (that function will always return 0 since it will - not be clear what type the property should have). - - \sa isPropertyTypeSupported() -*/ -QtVariantProperty *QtVariantPropertyManager::addProperty(int propertyType, const QString &name) -{ - if (!isPropertyTypeSupported(propertyType)) - return 0; - - bool wasCreating = d_ptr->m_creatingProperty; - d_ptr->m_creatingProperty = true; - d_ptr->m_propertyType = propertyType; - QtProperty *property = QtAbstractPropertyManager::addProperty(name); - d_ptr->m_creatingProperty = wasCreating; - d_ptr->m_propertyType = 0; - - if (!property) - return 0; - - return variantProperty(property); -} - -/*! - Returns the given \a property's value. - - If the given \a property is not managed by this manager, this - function returns an invalid variant. - - \sa setValue() -*/ -QVariant QtVariantPropertyManager::value(const QtProperty *property) const -{ - QtProperty *internProp = propertyToWrappedProperty()->value(property, 0); - if (internProp == 0) - return QVariant(); - - QtAbstractPropertyManager *manager = internProp->propertyManager(); - if (QtIntPropertyManager *intManager = qobject_cast(manager)) { - return intManager->value(internProp); - } else if (QtDoublePropertyManager *doubleManager = qobject_cast(manager)) { - return doubleManager->value(internProp); - } else if (QtBoolPropertyManager *boolManager = qobject_cast(manager)) { - return boolManager->value(internProp); - } else if (QtStringPropertyManager *stringManager = qobject_cast(manager)) { - return stringManager->value(internProp); - } else if (QtDatePropertyManager *dateManager = qobject_cast(manager)) { - return dateManager->value(internProp); - } else if (QtTimePropertyManager *timeManager = qobject_cast(manager)) { - return timeManager->value(internProp); - } else if (QtDateTimePropertyManager *dateTimeManager = qobject_cast(manager)) { - return dateTimeManager->value(internProp); - } else if (QtKeySequencePropertyManager *keySequenceManager = qobject_cast(manager)) { - return keySequenceManager->value(internProp); - } else if (QtCharPropertyManager *charManager = qobject_cast(manager)) { - return charManager->value(internProp); - } else if (QtLocalePropertyManager *localeManager = qobject_cast(manager)) { - return localeManager->value(internProp); - } else if (QtPointPropertyManager *pointManager = qobject_cast(manager)) { - return pointManager->value(internProp); - } else if (QtPointFPropertyManager *pointFManager = qobject_cast(manager)) { - return pointFManager->value(internProp); - } else if (QtSizePropertyManager *sizeManager = qobject_cast(manager)) { - return sizeManager->value(internProp); - } else if (QtSizeFPropertyManager *sizeFManager = qobject_cast(manager)) { - return sizeFManager->value(internProp); - } else if (QtRectPropertyManager *rectManager = qobject_cast(manager)) { - return rectManager->value(internProp); - } else if (QtRectFPropertyManager *rectFManager = qobject_cast(manager)) { - return rectFManager->value(internProp); - } else if (QtColorPropertyManager *colorManager = qobject_cast(manager)) { - return colorManager->value(internProp); - } else if (QtEnumPropertyManager *enumManager = qobject_cast(manager)) { - return enumManager->value(internProp); - } else if (QtSizePolicyPropertyManager *sizePolicyManager = - qobject_cast(manager)) { - return sizePolicyManager->value(internProp); - } else if (QtFontPropertyManager *fontManager = qobject_cast(manager)) { - return fontManager->value(internProp); -#ifndef QT_NO_CURSOR - } else if (QtCursorPropertyManager *cursorManager = qobject_cast(manager)) { - return cursorManager->value(internProp); -#endif - } else if (QtFlagPropertyManager *flagManager = qobject_cast(manager)) { - return flagManager->value(internProp); - } - return QVariant(); -} - -/*! - Returns the given \a property's value type. - - \sa propertyType() -*/ -int QtVariantPropertyManager::valueType(const QtProperty *property) const -{ - int propType = propertyType(property); - return valueType(propType); -} - -/*! - \overload - - Returns the value type associated with the given \a propertyType. -*/ -int QtVariantPropertyManager::valueType(int propertyType) const -{ - if (d_ptr->m_typeToValueType.contains(propertyType)) - return d_ptr->m_typeToValueType[propertyType]; - return 0; -} - -/*! - Returns the given \a property's type. - - \sa valueType() -*/ -int QtVariantPropertyManager::propertyType(const QtProperty *property) const -{ - const QMap >::const_iterator it = d_ptr->m_propertyToType.constFind(property); - if (it == d_ptr->m_propertyToType.constEnd()) - return 0; - return it.value().second; -} - -/*! - Returns the given \a property's value for the specified \a - attribute - - If the given \a property was not created by \e this manager, or if - the specified \a attribute does not exist, this function returns - an invalid variant. - - \sa attributes(), attributeType(), setAttribute() -*/ -QVariant QtVariantPropertyManager::attributeValue(const QtProperty *property, const QString &attribute) const -{ - int propType = propertyType(property); - if (!propType) - return QVariant(); - - QMap >::ConstIterator it = - d_ptr->m_typeToAttributeToAttributeType.find(propType); - if (it == d_ptr->m_typeToAttributeToAttributeType.constEnd()) - return QVariant(); - - QMap attributes = it.value(); - QMap::ConstIterator itAttr = attributes.find(attribute); - if (itAttr == attributes.constEnd()) - return QVariant(); - - QtProperty *internProp = propertyToWrappedProperty()->value(property, 0); - if (internProp == 0) - return QVariant(); - - QtAbstractPropertyManager *manager = internProp->propertyManager(); - if (QtIntPropertyManager *intManager = qobject_cast(manager)) { - if (attribute == d_ptr->m_maximumAttribute) - return intManager->maximum(internProp); - if (attribute == d_ptr->m_minimumAttribute) - return intManager->minimum(internProp); - if (attribute == d_ptr->m_singleStepAttribute) - return intManager->singleStep(internProp); - return QVariant(); - } else if (QtDoublePropertyManager *doubleManager = qobject_cast(manager)) { - if (attribute == d_ptr->m_maximumAttribute) - return doubleManager->maximum(internProp); - if (attribute == d_ptr->m_minimumAttribute) - return doubleManager->minimum(internProp); - if (attribute == d_ptr->m_singleStepAttribute) - return doubleManager->singleStep(internProp); - if (attribute == d_ptr->m_decimalsAttribute) - return doubleManager->decimals(internProp); - return QVariant(); - } else if (QtStringPropertyManager *stringManager = qobject_cast(manager)) { - if (attribute == d_ptr->m_regExpAttribute) - return stringManager->regExp(internProp); - return QVariant(); - } else if (QtDatePropertyManager *dateManager = qobject_cast(manager)) { - if (attribute == d_ptr->m_maximumAttribute) - return dateManager->maximum(internProp); - if (attribute == d_ptr->m_minimumAttribute) - return dateManager->minimum(internProp); - return QVariant(); - } else if (QtPointFPropertyManager *pointFManager = qobject_cast(manager)) { - if (attribute == d_ptr->m_decimalsAttribute) - return pointFManager->decimals(internProp); - return QVariant(); - } else if (QtSizePropertyManager *sizeManager = qobject_cast(manager)) { - if (attribute == d_ptr->m_maximumAttribute) - return sizeManager->maximum(internProp); - if (attribute == d_ptr->m_minimumAttribute) - return sizeManager->minimum(internProp); - return QVariant(); - } else if (QtSizeFPropertyManager *sizeFManager = qobject_cast(manager)) { - if (attribute == d_ptr->m_maximumAttribute) - return sizeFManager->maximum(internProp); - if (attribute == d_ptr->m_minimumAttribute) - return sizeFManager->minimum(internProp); - if (attribute == d_ptr->m_decimalsAttribute) - return sizeFManager->decimals(internProp); - return QVariant(); - } else if (QtRectPropertyManager *rectManager = qobject_cast(manager)) { - if (attribute == d_ptr->m_constraintAttribute) - return rectManager->constraint(internProp); - return QVariant(); - } else if (QtRectFPropertyManager *rectFManager = qobject_cast(manager)) { - if (attribute == d_ptr->m_constraintAttribute) - return rectFManager->constraint(internProp); - if (attribute == d_ptr->m_decimalsAttribute) - return rectFManager->decimals(internProp); - return QVariant(); - } else if (QtEnumPropertyManager *enumManager = qobject_cast(manager)) { - if (attribute == d_ptr->m_enumNamesAttribute) - return enumManager->enumNames(internProp); - if (attribute == d_ptr->m_enumIconsAttribute) { - QVariant v; - qVariantSetValue(v, enumManager->enumIcons(internProp)); - return v; - } - return QVariant(); - } else if (QtFlagPropertyManager *flagManager = qobject_cast(manager)) { - if (attribute == d_ptr->m_flagNamesAttribute) - return flagManager->flagNames(internProp); - return QVariant(); - } - return QVariant(); -} - -/*! - Returns a list of the given \a propertyType 's attributes. - - \sa attributeValue(), attributeType() -*/ -QStringList QtVariantPropertyManager::attributes(int propertyType) const -{ - QMap >::ConstIterator it = - d_ptr->m_typeToAttributeToAttributeType.find(propertyType); - if (it == d_ptr->m_typeToAttributeToAttributeType.constEnd()) - return QStringList(); - return it.value().keys(); -} - -/*! - Returns the type of the specified \a attribute of the given \a - propertyType. - - If the given \a propertyType is not supported by \e this manager, - or if the given \a propertyType does not possess the specified \a - attribute, this function returns QVariant::Invalid. - - \sa attributes(), valueType() -*/ -int QtVariantPropertyManager::attributeType(int propertyType, const QString &attribute) const -{ - QMap >::ConstIterator it = - d_ptr->m_typeToAttributeToAttributeType.find(propertyType); - if (it == d_ptr->m_typeToAttributeToAttributeType.constEnd()) - return 0; - - QMap attributes = it.value(); - QMap::ConstIterator itAttr = attributes.find(attribute); - if (itAttr == attributes.constEnd()) - return 0; - return itAttr.value(); -} - -/*! - \fn void QtVariantPropertyManager::setValue(QtProperty *property, const QVariant &value) - - Sets the value of the given \a property to \a value. - - The specified \a value must be of a type returned by valueType(), - or of type that can be converted to valueType() using the - QVariant::canConvert() function, otherwise this function does - nothing. - - \sa value(), QtVariantProperty::setValue(), valueChanged() -*/ -void QtVariantPropertyManager::setValue(QtProperty *property, const QVariant &val) -{ - int propType = val.userType(); - if (!propType) - return; - - int valType = valueType(property); - - if (propType != valType && !val.canConvert(static_cast(valType))) - return; - - QtProperty *internProp = propertyToWrappedProperty()->value(property, 0); - if (internProp == 0) - return; - - - QtAbstractPropertyManager *manager = internProp->propertyManager(); - if (QtIntPropertyManager *intManager = qobject_cast(manager)) { - intManager->setValue(internProp, qVariantValue(val)); - return; - } else if (QtDoublePropertyManager *doubleManager = qobject_cast(manager)) { - doubleManager->setValue(internProp, qVariantValue(val)); - return; - } else if (QtBoolPropertyManager *boolManager = qobject_cast(manager)) { - boolManager->setValue(internProp, qVariantValue(val)); - return; - } else if (QtStringPropertyManager *stringManager = qobject_cast(manager)) { - stringManager->setValue(internProp, qVariantValue(val)); - return; - } else if (QtDatePropertyManager *dateManager = qobject_cast(manager)) { - dateManager->setValue(internProp, qVariantValue(val)); - return; - } else if (QtTimePropertyManager *timeManager = qobject_cast(manager)) { - timeManager->setValue(internProp, qVariantValue(val)); - return; - } else if (QtDateTimePropertyManager *dateTimeManager = qobject_cast(manager)) { - dateTimeManager->setValue(internProp, qVariantValue(val)); - return; - } else if (QtKeySequencePropertyManager *keySequenceManager = qobject_cast(manager)) { - keySequenceManager->setValue(internProp, qVariantValue(val)); - return; - } else if (QtCharPropertyManager *charManager = qobject_cast(manager)) { - charManager->setValue(internProp, qVariantValue(val)); - return; - } else if (QtLocalePropertyManager *localeManager = qobject_cast(manager)) { - localeManager->setValue(internProp, qVariantValue(val)); - return; - } else if (QtPointPropertyManager *pointManager = qobject_cast(manager)) { - pointManager->setValue(internProp, qVariantValue(val)); - return; - } else if (QtPointFPropertyManager *pointFManager = qobject_cast(manager)) { - pointFManager->setValue(internProp, qVariantValue(val)); - return; - } else if (QtSizePropertyManager *sizeManager = qobject_cast(manager)) { - sizeManager->setValue(internProp, qVariantValue(val)); - return; - } else if (QtSizeFPropertyManager *sizeFManager = qobject_cast(manager)) { - sizeFManager->setValue(internProp, qVariantValue(val)); - return; - } else if (QtRectPropertyManager *rectManager = qobject_cast(manager)) { - rectManager->setValue(internProp, qVariantValue(val)); - return; - } else if (QtRectFPropertyManager *rectFManager = qobject_cast(manager)) { - rectFManager->setValue(internProp, qVariantValue(val)); - return; - } else if (QtColorPropertyManager *colorManager = qobject_cast(manager)) { - colorManager->setValue(internProp, qVariantValue(val)); - return; - } else if (QtEnumPropertyManager *enumManager = qobject_cast(manager)) { - enumManager->setValue(internProp, qVariantValue(val)); - return; - } else if (QtSizePolicyPropertyManager *sizePolicyManager = - qobject_cast(manager)) { - sizePolicyManager->setValue(internProp, qVariantValue(val)); - return; - } else if (QtFontPropertyManager *fontManager = qobject_cast(manager)) { - fontManager->setValue(internProp, qVariantValue(val)); - return; -#ifndef QT_NO_CURSOR - } else if (QtCursorPropertyManager *cursorManager = qobject_cast(manager)) { - cursorManager->setValue(internProp, qVariantValue(val)); - return; -#endif - } else if (QtFlagPropertyManager *flagManager = qobject_cast(manager)) { - flagManager->setValue(internProp, qVariantValue(val)); - return; - } -} - -/*! - Sets the value of the specified \a attribute of the given \a - property, to \a value. - - The new \a value's type must be of the type returned by - attributeType(), or of a type that can be converted to - attributeType() using the QVariant::canConvert() function, - otherwise this function does nothing. - - \sa attributeValue(), QtVariantProperty::setAttribute(), attributeChanged() -*/ -void QtVariantPropertyManager::setAttribute(QtProperty *property, - const QString &attribute, const QVariant &value) -{ - QVariant oldAttr = attributeValue(property, attribute); - if (!oldAttr.isValid()) - return; - - int attrType = value.userType(); - if (!attrType) - return; - - if (attrType != attributeType(propertyType(property), attribute) && - !value.canConvert((QVariant::Type)attrType)) - return; - - QtProperty *internProp = propertyToWrappedProperty()->value(property, 0); - if (internProp == 0) - return; - - QtAbstractPropertyManager *manager = internProp->propertyManager(); - if (QtIntPropertyManager *intManager = qobject_cast(manager)) { - if (attribute == d_ptr->m_maximumAttribute) - intManager->setMaximum(internProp, qVariantValue(value)); - else if (attribute == d_ptr->m_minimumAttribute) - intManager->setMinimum(internProp, qVariantValue(value)); - else if (attribute == d_ptr->m_singleStepAttribute) - intManager->setSingleStep(internProp, qVariantValue(value)); - return; - } else if (QtDoublePropertyManager *doubleManager = qobject_cast(manager)) { - if (attribute == d_ptr->m_maximumAttribute) - doubleManager->setMaximum(internProp, qVariantValue(value)); - if (attribute == d_ptr->m_minimumAttribute) - doubleManager->setMinimum(internProp, qVariantValue(value)); - if (attribute == d_ptr->m_singleStepAttribute) - doubleManager->setSingleStep(internProp, qVariantValue(value)); - if (attribute == d_ptr->m_decimalsAttribute) - doubleManager->setDecimals(internProp, qVariantValue(value)); - return; - } else if (QtStringPropertyManager *stringManager = qobject_cast(manager)) { - if (attribute == d_ptr->m_regExpAttribute) - stringManager->setRegExp(internProp, qVariantValue(value)); - return; - } else if (QtDatePropertyManager *dateManager = qobject_cast(manager)) { - if (attribute == d_ptr->m_maximumAttribute) - dateManager->setMaximum(internProp, qVariantValue(value)); - if (attribute == d_ptr->m_minimumAttribute) - dateManager->setMinimum(internProp, qVariantValue(value)); - return; - } else if (QtPointFPropertyManager *pointFManager = qobject_cast(manager)) { - if (attribute == d_ptr->m_decimalsAttribute) - pointFManager->setDecimals(internProp, qVariantValue(value)); - return; - } else if (QtSizePropertyManager *sizeManager = qobject_cast(manager)) { - if (attribute == d_ptr->m_maximumAttribute) - sizeManager->setMaximum(internProp, qVariantValue(value)); - if (attribute == d_ptr->m_minimumAttribute) - sizeManager->setMinimum(internProp, qVariantValue(value)); - return; - } else if (QtSizeFPropertyManager *sizeFManager = qobject_cast(manager)) { - if (attribute == d_ptr->m_maximumAttribute) - sizeFManager->setMaximum(internProp, qVariantValue(value)); - if (attribute == d_ptr->m_minimumAttribute) - sizeFManager->setMinimum(internProp, qVariantValue(value)); - if (attribute == d_ptr->m_decimalsAttribute) - sizeFManager->setDecimals(internProp, qVariantValue(value)); - return; - } else if (QtRectPropertyManager *rectManager = qobject_cast(manager)) { - if (attribute == d_ptr->m_constraintAttribute) - rectManager->setConstraint(internProp, qVariantValue(value)); - return; - } else if (QtRectFPropertyManager *rectFManager = qobject_cast(manager)) { - if (attribute == d_ptr->m_constraintAttribute) - rectFManager->setConstraint(internProp, qVariantValue(value)); - if (attribute == d_ptr->m_decimalsAttribute) - rectFManager->setDecimals(internProp, qVariantValue(value)); - return; - } else if (QtEnumPropertyManager *enumManager = qobject_cast(manager)) { - if (attribute == d_ptr->m_enumNamesAttribute) - enumManager->setEnumNames(internProp, qVariantValue(value)); - if (attribute == d_ptr->m_enumIconsAttribute) - enumManager->setEnumIcons(internProp, qVariantValue(value)); - return; - } else if (QtFlagPropertyManager *flagManager = qobject_cast(manager)) { - if (attribute == d_ptr->m_flagNamesAttribute) - flagManager->setFlagNames(internProp, qVariantValue(value)); - return; - } -} - -/*! - \reimp -*/ -bool QtVariantPropertyManager::hasValue(const QtProperty *property) const -{ - if (propertyType(property) == groupTypeId()) - return false; - return true; -} - -/*! - \reimp -*/ -QString QtVariantPropertyManager::valueText(const QtProperty *property) const -{ - const QtProperty *internProp = propertyToWrappedProperty()->value(property, 0); - return internProp ? internProp->valueText() : QString(); -} - -/*! - \reimp -*/ -QIcon QtVariantPropertyManager::valueIcon(const QtProperty *property) const -{ - const QtProperty *internProp = propertyToWrappedProperty()->value(property, 0); - return internProp ? internProp->valueIcon() : QIcon(); -} - -/*! - \reimp -*/ -void QtVariantPropertyManager::initializeProperty(QtProperty *property) -{ - QtVariantProperty *varProp = variantProperty(property); - if (!varProp) - return; - - QMap::ConstIterator it = - d_ptr->m_typeToPropertyManager.find(d_ptr->m_propertyType); - if (it != d_ptr->m_typeToPropertyManager.constEnd()) { - QtProperty *internProp = 0; - if (!d_ptr->m_creatingSubProperties) { - QtAbstractPropertyManager *manager = it.value(); - internProp = manager->addProperty(); - d_ptr->m_internalToProperty[internProp] = varProp; - } - propertyToWrappedProperty()->insert(varProp, internProp); - if (internProp) { - QList children = internProp->subProperties(); - QListIterator itChild(children); - QtVariantProperty *lastProperty = 0; - while (itChild.hasNext()) { - QtVariantProperty *prop = d_ptr->createSubProperty(varProp, lastProperty, itChild.next()); - lastProperty = prop ? prop : lastProperty; - } - } - } -} - -/*! - \reimp -*/ -void QtVariantPropertyManager::uninitializeProperty(QtProperty *property) -{ - const QMap >::iterator type_it = d_ptr->m_propertyToType.find(property); - if (type_it == d_ptr->m_propertyToType.end()) - return; - - PropertyMap::iterator it = propertyToWrappedProperty()->find(property); - if (it != propertyToWrappedProperty()->end()) { - QtProperty *internProp = it.value(); - if (internProp) { - d_ptr->m_internalToProperty.remove(internProp); - if (!d_ptr->m_destroyingSubProperties) { - delete internProp; - } - } - propertyToWrappedProperty()->erase(it); - } - d_ptr->m_propertyToType.erase(type_it); -} - -/*! - \reimp -*/ -QtProperty *QtVariantPropertyManager::createProperty() -{ - if (!d_ptr->m_creatingProperty) - return 0; - - QtVariantProperty *property = new QtVariantProperty(this); - d_ptr->m_propertyToType.insert(property, qMakePair(property, d_ptr->m_propertyType)); - - return property; -} - -///////////////////////////// - -class QtVariantEditorFactoryPrivate -{ - QtVariantEditorFactory *q_ptr; - Q_DECLARE_PUBLIC(QtVariantEditorFactory) -public: - - QtSpinBoxFactory *m_spinBoxFactory; - QtDoubleSpinBoxFactory *m_doubleSpinBoxFactory; - QtCheckBoxFactory *m_checkBoxFactory; - QtLineEditFactory *m_lineEditFactory; - QtDateEditFactory *m_dateEditFactory; - QtTimeEditFactory *m_timeEditFactory; - QtDateTimeEditFactory *m_dateTimeEditFactory; - QtKeySequenceEditorFactory *m_keySequenceEditorFactory; - QtCharEditorFactory *m_charEditorFactory; - QtEnumEditorFactory *m_comboBoxFactory; - QtCursorEditorFactory *m_cursorEditorFactory; - QtColorEditorFactory *m_colorEditorFactory; - QtFontEditorFactory *m_fontEditorFactory; - - QMap m_factoryToType; - QMap m_typeToFactory; -}; - -/*! - \class QtVariantEditorFactory - - \brief The QtVariantEditorFactory class provides widgets for properties - created by QtVariantPropertyManager objects. - - The variant factory provides the following widgets for the - specified property types: - - \table - \header - \o Property Type - \o Widget - \row - \o \c int - \o QSpinBox - \row - \o \c double - \o QDoubleSpinBox - \row - \o \c bool - \o QCheckBox - \row - \o QString - \o QLineEdit - \row - \o QDate - \o QDateEdit - \row - \o QTime - \o QTimeEdit - \row - \o QDateTime - \o QDateTimeEdit - \row - \o QKeySequence - \o customized editor - \row - \o QChar - \o customized editor - \row - \o \c enum - \o QComboBox - \row - \o QCursor - \o QComboBox - \endtable - - Note that QtVariantPropertyManager supports several additional property - types for which the QtVariantEditorFactory class does not provide - editing widgets, e.g. QPoint and QSize. To provide widgets for other - types using the variant approach, derive from the QtVariantEditorFactory - class. - - \sa QtAbstractEditorFactory, QtVariantPropertyManager -*/ - -/*! - Creates a factory with the given \a parent. -*/ -QtVariantEditorFactory::QtVariantEditorFactory(QObject *parent) - : QtAbstractEditorFactory(parent) -{ - d_ptr = new QtVariantEditorFactoryPrivate(); - d_ptr->q_ptr = this; - - d_ptr->m_spinBoxFactory = new QtSpinBoxFactory(this); - d_ptr->m_factoryToType[d_ptr->m_spinBoxFactory] = QVariant::Int; - d_ptr->m_typeToFactory[QVariant::Int] = d_ptr->m_spinBoxFactory; - - d_ptr->m_doubleSpinBoxFactory = new QtDoubleSpinBoxFactory(this); - d_ptr->m_factoryToType[d_ptr->m_doubleSpinBoxFactory] = QVariant::Double; - d_ptr->m_typeToFactory[QVariant::Double] = d_ptr->m_doubleSpinBoxFactory; - - d_ptr->m_checkBoxFactory = new QtCheckBoxFactory(this); - d_ptr->m_factoryToType[d_ptr->m_checkBoxFactory] = QVariant::Bool; - d_ptr->m_typeToFactory[QVariant::Bool] = d_ptr->m_checkBoxFactory; - - d_ptr->m_lineEditFactory = new QtLineEditFactory(this); - d_ptr->m_factoryToType[d_ptr->m_lineEditFactory] = QVariant::String; - d_ptr->m_typeToFactory[QVariant::String] = d_ptr->m_lineEditFactory; - - d_ptr->m_dateEditFactory = new QtDateEditFactory(this); - d_ptr->m_factoryToType[d_ptr->m_dateEditFactory] = QVariant::Date; - d_ptr->m_typeToFactory[QVariant::Date] = d_ptr->m_dateEditFactory; - - d_ptr->m_timeEditFactory = new QtTimeEditFactory(this); - d_ptr->m_factoryToType[d_ptr->m_timeEditFactory] = QVariant::Time; - d_ptr->m_typeToFactory[QVariant::Time] = d_ptr->m_timeEditFactory; - - d_ptr->m_dateTimeEditFactory = new QtDateTimeEditFactory(this); - d_ptr->m_factoryToType[d_ptr->m_dateTimeEditFactory] = QVariant::DateTime; - d_ptr->m_typeToFactory[QVariant::DateTime] = d_ptr->m_dateTimeEditFactory; - - d_ptr->m_keySequenceEditorFactory = new QtKeySequenceEditorFactory(this); - d_ptr->m_factoryToType[d_ptr->m_keySequenceEditorFactory] = QVariant::KeySequence; - d_ptr->m_typeToFactory[QVariant::KeySequence] = d_ptr->m_keySequenceEditorFactory; - - d_ptr->m_charEditorFactory = new QtCharEditorFactory(this); - d_ptr->m_factoryToType[d_ptr->m_charEditorFactory] = QVariant::Char; - d_ptr->m_typeToFactory[QVariant::Char] = d_ptr->m_charEditorFactory; - - d_ptr->m_cursorEditorFactory = new QtCursorEditorFactory(this); - d_ptr->m_factoryToType[d_ptr->m_cursorEditorFactory] = QVariant::Cursor; - d_ptr->m_typeToFactory[QVariant::Cursor] = d_ptr->m_cursorEditorFactory; - - d_ptr->m_colorEditorFactory = new QtColorEditorFactory(this); - d_ptr->m_factoryToType[d_ptr->m_colorEditorFactory] = QVariant::Color; - d_ptr->m_typeToFactory[QVariant::Color] = d_ptr->m_colorEditorFactory; - - d_ptr->m_fontEditorFactory = new QtFontEditorFactory(this); - d_ptr->m_factoryToType[d_ptr->m_fontEditorFactory] = QVariant::Font; - d_ptr->m_typeToFactory[QVariant::Font] = d_ptr->m_fontEditorFactory; - - d_ptr->m_comboBoxFactory = new QtEnumEditorFactory(this); - const int enumId = QtVariantPropertyManager::enumTypeId(); - d_ptr->m_factoryToType[d_ptr->m_comboBoxFactory] = enumId; - d_ptr->m_typeToFactory[enumId] = d_ptr->m_comboBoxFactory; -} - -/*! - Destroys this factory, and all the widgets it has created. -*/ -QtVariantEditorFactory::~QtVariantEditorFactory() -{ - delete d_ptr; -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtVariantEditorFactory::connectPropertyManager(QtVariantPropertyManager *manager) -{ - QList intPropertyManagers = qFindChildren(manager); - QListIterator itInt(intPropertyManagers); - while (itInt.hasNext()) - d_ptr->m_spinBoxFactory->addPropertyManager(itInt.next()); - - QList doublePropertyManagers = qFindChildren(manager); - QListIterator itDouble(doublePropertyManagers); - while (itDouble.hasNext()) - d_ptr->m_doubleSpinBoxFactory->addPropertyManager(itDouble.next()); - - QList boolPropertyManagers = qFindChildren(manager); - QListIterator itBool(boolPropertyManagers); - while (itBool.hasNext()) - d_ptr->m_checkBoxFactory->addPropertyManager(itBool.next()); - - QList stringPropertyManagers = qFindChildren(manager); - QListIterator itString(stringPropertyManagers); - while (itString.hasNext()) - d_ptr->m_lineEditFactory->addPropertyManager(itString.next()); - - QList datePropertyManagers = qFindChildren(manager); - QListIterator itDate(datePropertyManagers); - while (itDate.hasNext()) - d_ptr->m_dateEditFactory->addPropertyManager(itDate.next()); - - QList timePropertyManagers = qFindChildren(manager); - QListIterator itTime(timePropertyManagers); - while (itTime.hasNext()) - d_ptr->m_timeEditFactory->addPropertyManager(itTime.next()); - - QList dateTimePropertyManagers = qFindChildren(manager); - QListIterator itDateTime(dateTimePropertyManagers); - while (itDateTime.hasNext()) - d_ptr->m_dateTimeEditFactory->addPropertyManager(itDateTime.next()); - - QList keySequencePropertyManagers = qFindChildren(manager); - QListIterator itKeySequence(keySequencePropertyManagers); - while (itKeySequence.hasNext()) - d_ptr->m_keySequenceEditorFactory->addPropertyManager(itKeySequence.next()); - - QList charPropertyManagers = qFindChildren(manager); - QListIterator itChar(charPropertyManagers); - while (itChar.hasNext()) - d_ptr->m_charEditorFactory->addPropertyManager(itChar.next()); - - QList localePropertyManagers = qFindChildren(manager); - QListIterator itLocale(localePropertyManagers); - while (itLocale.hasNext()) - d_ptr->m_comboBoxFactory->addPropertyManager(itLocale.next()->subEnumPropertyManager()); - - QList pointPropertyManagers = qFindChildren(manager); - QListIterator itPoint(pointPropertyManagers); - while (itPoint.hasNext()) - d_ptr->m_spinBoxFactory->addPropertyManager(itPoint.next()->subIntPropertyManager()); - - QList pointFPropertyManagers = qFindChildren(manager); - QListIterator itPointF(pointFPropertyManagers); - while (itPointF.hasNext()) - d_ptr->m_doubleSpinBoxFactory->addPropertyManager(itPointF.next()->subDoublePropertyManager()); - - QList sizePropertyManagers = qFindChildren(manager); - QListIterator itSize(sizePropertyManagers); - while (itSize.hasNext()) - d_ptr->m_spinBoxFactory->addPropertyManager(itSize.next()->subIntPropertyManager()); - - QList sizeFPropertyManagers = qFindChildren(manager); - QListIterator itSizeF(sizeFPropertyManagers); - while (itSizeF.hasNext()) - d_ptr->m_doubleSpinBoxFactory->addPropertyManager(itSizeF.next()->subDoublePropertyManager()); - - QList rectPropertyManagers = qFindChildren(manager); - QListIterator itRect(rectPropertyManagers); - while (itRect.hasNext()) - d_ptr->m_spinBoxFactory->addPropertyManager(itRect.next()->subIntPropertyManager()); - - QList rectFPropertyManagers = qFindChildren(manager); - QListIterator itRectF(rectFPropertyManagers); - while (itRectF.hasNext()) - d_ptr->m_doubleSpinBoxFactory->addPropertyManager(itRectF.next()->subDoublePropertyManager()); - - QList colorPropertyManagers = qFindChildren(manager); - QListIterator itColor(colorPropertyManagers); - while (itColor.hasNext()) { - QtColorPropertyManager *manager = itColor.next(); - d_ptr->m_colorEditorFactory->addPropertyManager(manager); - d_ptr->m_spinBoxFactory->addPropertyManager(manager->subIntPropertyManager()); - } - - QList enumPropertyManagers = qFindChildren(manager); - QListIterator itEnum(enumPropertyManagers); - while (itEnum.hasNext()) - d_ptr->m_comboBoxFactory->addPropertyManager(itEnum.next()); - - QList sizePolicyPropertyManagers = qFindChildren(manager); - QListIterator itSizePolicy(sizePolicyPropertyManagers); - while (itSizePolicy.hasNext()) { - QtSizePolicyPropertyManager *manager = itSizePolicy.next(); - d_ptr->m_spinBoxFactory->addPropertyManager(manager->subIntPropertyManager()); - d_ptr->m_comboBoxFactory->addPropertyManager(manager->subEnumPropertyManager()); - } - - QList fontPropertyManagers = qFindChildren(manager); - QListIterator itFont(fontPropertyManagers); - while (itFont.hasNext()) { - QtFontPropertyManager *manager = itFont.next(); - d_ptr->m_fontEditorFactory->addPropertyManager(manager); - d_ptr->m_spinBoxFactory->addPropertyManager(manager->subIntPropertyManager()); - d_ptr->m_comboBoxFactory->addPropertyManager(manager->subEnumPropertyManager()); - d_ptr->m_checkBoxFactory->addPropertyManager(manager->subBoolPropertyManager()); - } - - QList cursorPropertyManagers = qFindChildren(manager); - QListIterator itCursor(cursorPropertyManagers); - while (itCursor.hasNext()) - d_ptr->m_cursorEditorFactory->addPropertyManager(itCursor.next()); - - QList flagPropertyManagers = qFindChildren(manager); - QListIterator itFlag(flagPropertyManagers); - while (itFlag.hasNext()) - d_ptr->m_checkBoxFactory->addPropertyManager(itFlag.next()->subBoolPropertyManager()); -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -QWidget *QtVariantEditorFactory::createEditor(QtVariantPropertyManager *manager, QtProperty *property, - QWidget *parent) -{ - const int propType = manager->propertyType(property); - QtAbstractEditorFactoryBase *factory = d_ptr->m_typeToFactory.value(propType, 0); - if (!factory) - return 0; - return factory->createEditor(wrappedProperty(property), parent); -} - -/*! - \internal - - Reimplemented from the QtAbstractEditorFactory class. -*/ -void QtVariantEditorFactory::disconnectPropertyManager(QtVariantPropertyManager *manager) -{ - QList intPropertyManagers = qFindChildren(manager); - QListIterator itInt(intPropertyManagers); - while (itInt.hasNext()) - d_ptr->m_spinBoxFactory->removePropertyManager(itInt.next()); - - QList doublePropertyManagers = qFindChildren(manager); - QListIterator itDouble(doublePropertyManagers); - while (itDouble.hasNext()) - d_ptr->m_doubleSpinBoxFactory->removePropertyManager(itDouble.next()); - - QList boolPropertyManagers = qFindChildren(manager); - QListIterator itBool(boolPropertyManagers); - while (itBool.hasNext()) - d_ptr->m_checkBoxFactory->removePropertyManager(itBool.next()); - - QList stringPropertyManagers = qFindChildren(manager); - QListIterator itString(stringPropertyManagers); - while (itString.hasNext()) - d_ptr->m_lineEditFactory->removePropertyManager(itString.next()); - - QList datePropertyManagers = qFindChildren(manager); - QListIterator itDate(datePropertyManagers); - while (itDate.hasNext()) - d_ptr->m_dateEditFactory->removePropertyManager(itDate.next()); - - QList timePropertyManagers = qFindChildren(manager); - QListIterator itTime(timePropertyManagers); - while (itTime.hasNext()) - d_ptr->m_timeEditFactory->removePropertyManager(itTime.next()); - - QList dateTimePropertyManagers = qFindChildren(manager); - QListIterator itDateTime(dateTimePropertyManagers); - while (itDateTime.hasNext()) - d_ptr->m_dateTimeEditFactory->removePropertyManager(itDateTime.next()); - - QList keySequencePropertyManagers = qFindChildren(manager); - QListIterator itKeySequence(keySequencePropertyManagers); - while (itKeySequence.hasNext()) - d_ptr->m_keySequenceEditorFactory->removePropertyManager(itKeySequence.next()); - - QList charPropertyManagers = qFindChildren(manager); - QListIterator itChar(charPropertyManagers); - while (itChar.hasNext()) - d_ptr->m_charEditorFactory->removePropertyManager(itChar.next()); - - QList localePropertyManagers = qFindChildren(manager); - QListIterator itLocale(localePropertyManagers); - while (itLocale.hasNext()) - d_ptr->m_comboBoxFactory->removePropertyManager(itLocale.next()->subEnumPropertyManager()); - - QList pointPropertyManagers = qFindChildren(manager); - QListIterator itPoint(pointPropertyManagers); - while (itPoint.hasNext()) - d_ptr->m_spinBoxFactory->removePropertyManager(itPoint.next()->subIntPropertyManager()); - - QList pointFPropertyManagers = qFindChildren(manager); - QListIterator itPointF(pointFPropertyManagers); - while (itPointF.hasNext()) - d_ptr->m_doubleSpinBoxFactory->removePropertyManager(itPointF.next()->subDoublePropertyManager()); - - QList sizePropertyManagers = qFindChildren(manager); - QListIterator itSize(sizePropertyManagers); - while (itSize.hasNext()) - d_ptr->m_spinBoxFactory->removePropertyManager(itSize.next()->subIntPropertyManager()); - - QList sizeFPropertyManagers = qFindChildren(manager); - QListIterator itSizeF(sizeFPropertyManagers); - while (itSizeF.hasNext()) - d_ptr->m_doubleSpinBoxFactory->removePropertyManager(itSizeF.next()->subDoublePropertyManager()); - - QList rectPropertyManagers = qFindChildren(manager); - QListIterator itRect(rectPropertyManagers); - while (itRect.hasNext()) - d_ptr->m_spinBoxFactory->removePropertyManager(itRect.next()->subIntPropertyManager()); - - QList rectFPropertyManagers = qFindChildren(manager); - QListIterator itRectF(rectFPropertyManagers); - while (itRectF.hasNext()) - d_ptr->m_doubleSpinBoxFactory->removePropertyManager(itRectF.next()->subDoublePropertyManager()); - - QList colorPropertyManagers = qFindChildren(manager); - QListIterator itColor(colorPropertyManagers); - while (itColor.hasNext()) { - QtColorPropertyManager *manager = itColor.next(); - d_ptr->m_colorEditorFactory->removePropertyManager(manager); - d_ptr->m_spinBoxFactory->removePropertyManager(manager->subIntPropertyManager()); - } - - QList enumPropertyManagers = qFindChildren(manager); - QListIterator itEnum(enumPropertyManagers); - while (itEnum.hasNext()) - d_ptr->m_comboBoxFactory->removePropertyManager(itEnum.next()); - - QList sizePolicyPropertyManagers = qFindChildren(manager); - QListIterator itSizePolicy(sizePolicyPropertyManagers); - while (itSizePolicy.hasNext()) { - QtSizePolicyPropertyManager *manager = itSizePolicy.next(); - d_ptr->m_spinBoxFactory->removePropertyManager(manager->subIntPropertyManager()); - d_ptr->m_comboBoxFactory->removePropertyManager(manager->subEnumPropertyManager()); - } - - QList fontPropertyManagers = qFindChildren(manager); - QListIterator itFont(fontPropertyManagers); - while (itFont.hasNext()) { - QtFontPropertyManager *manager = itFont.next(); - d_ptr->m_fontEditorFactory->removePropertyManager(manager); - d_ptr->m_spinBoxFactory->removePropertyManager(manager->subIntPropertyManager()); - d_ptr->m_comboBoxFactory->removePropertyManager(manager->subEnumPropertyManager()); - d_ptr->m_checkBoxFactory->removePropertyManager(manager->subBoolPropertyManager()); - } - - QList cursorPropertyManagers = qFindChildren(manager); - QListIterator itCursor(cursorPropertyManagers); - while (itCursor.hasNext()) - d_ptr->m_cursorEditorFactory->removePropertyManager(itCursor.next()); - - QList flagPropertyManagers = qFindChildren(manager); - QListIterator itFlag(flagPropertyManagers); - while (itFlag.hasNext()) - d_ptr->m_checkBoxFactory->removePropertyManager(itFlag.next()->subBoolPropertyManager()); -} - -#if QT_VERSION >= 0x040400 -QT_END_NAMESPACE -#endif - -#include "moc_qtvariantproperty.cxx" diff --git a/QtPropertyBrowser/qtvariantproperty.h b/QtPropertyBrowser/qtvariantproperty.h deleted file mode 100644 index 9f20d3dd41..0000000000 --- a/QtPropertyBrowser/qtvariantproperty.h +++ /dev/null @@ -1,232 +0,0 @@ -/**************************************************************************** -** -** This file is part of a Qt Solutions component. -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Solutions Commercial License Agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** Please note Third Party Software included with Qt Solutions may impose -** additional restrictions and it is the user's responsibility to ensure -** that they have met the licensing requirements of the GPL, LGPL, or Qt -** Solutions Commercial license and the relevant license of the Third -** Party Software they are using. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTVARIANTPROPERTY_H -#define QTVARIANTPROPERTY_H - -#include "qtpropertybrowser.h" -#include -#include - -#if QT_VERSION >= 0x040400 -QT_BEGIN_NAMESPACE -#endif - -typedef QMap QtIconMap; - -class QtVariantPropertyManager; -class QtVariantPropertyPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtVariantProperty : public QtProperty -{ -public: - ~QtVariantProperty(); - QVariant value() const; - QVariant attributeValue(const QString &attribute) const; - int valueType() const; - int propertyType() const; - - void setValue(const QVariant &value); - void setAttribute(const QString &attribute, const QVariant &value); -protected: - QtVariantProperty(QtVariantPropertyManager *manager); -private: - friend class QtVariantPropertyManager; - QtVariantPropertyPrivate *d_ptr; -}; - -class QtVariantPropertyManagerPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtVariantPropertyManager : public QtAbstractPropertyManager -{ - Q_OBJECT -public: - QtVariantPropertyManager(QObject *parent = 0); - ~QtVariantPropertyManager(); - - virtual QtVariantProperty *addProperty(int propertyType, const QString &name = QString()); - - int propertyType(const QtProperty *property) const; - int valueType(const QtProperty *property) const; - QtVariantProperty *variantProperty(const QtProperty *property) const; - - virtual bool isPropertyTypeSupported(int propertyType) const; - virtual int valueType(int propertyType) const; - virtual QStringList attributes(int propertyType) const; - virtual int attributeType(int propertyType, const QString &attribute) const; - - virtual QVariant value(const QtProperty *property) const; - virtual QVariant attributeValue(const QtProperty *property, const QString &attribute) const; - - static int enumTypeId(); - static int flagTypeId(); - static int groupTypeId(); - static int iconMapTypeId(); -public Q_SLOTS: - virtual void setValue(QtProperty *property, const QVariant &val); - virtual void setAttribute(QtProperty *property, - const QString &attribute, const QVariant &value); -Q_SIGNALS: - void valueChanged(QtProperty *property, const QVariant &val); - void attributeChanged(QtProperty *property, - const QString &attribute, const QVariant &val); -protected: - virtual bool hasValue(const QtProperty *property) const; - QString valueText(const QtProperty *property) const; - QIcon valueIcon(const QtProperty *property) const; - virtual void initializeProperty(QtProperty *property); - virtual void uninitializeProperty(QtProperty *property); - virtual QtProperty *createProperty(); -private: - QtVariantPropertyManagerPrivate *d_ptr; - Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, int)) - Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, int, int)) - Q_PRIVATE_SLOT(d_func(), void slotSingleStepChanged(QtProperty *, int)) - Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, double)) - Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, double, double)) - Q_PRIVATE_SLOT(d_func(), void slotSingleStepChanged(QtProperty *, double)) - Q_PRIVATE_SLOT(d_func(), void slotDecimalsChanged(QtProperty *, int)) - Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, bool)) - Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QString &)) - Q_PRIVATE_SLOT(d_func(), void slotRegExpChanged(QtProperty *, const QRegExp &)) - Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QDate &)) - Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, const QDate &, const QDate &)) - Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QTime &)) - Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QDateTime &)) - Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QKeySequence &)) - Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QChar &)) - Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QLocale &)) - Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QPoint &)) - Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QPointF &)) - Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QSize &)) - Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, const QSize &, const QSize &)) - Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QSizeF &)) - Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, const QSizeF &, const QSizeF &)) - Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QRect &)) - Q_PRIVATE_SLOT(d_func(), void slotConstraintChanged(QtProperty *, const QRect &)) - Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QRectF &)) - Q_PRIVATE_SLOT(d_func(), void slotConstraintChanged(QtProperty *, const QRectF &)) - Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QColor &)) - Q_PRIVATE_SLOT(d_func(), void slotEnumNamesChanged(QtProperty *, const QStringList &)) - Q_PRIVATE_SLOT(d_func(), void slotEnumIconsChanged(QtProperty *, const QMap &)) - Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QSizePolicy &)) - Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QFont &)) - Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QCursor &)) - Q_PRIVATE_SLOT(d_func(), void slotFlagNamesChanged(QtProperty *, const QStringList &)) - - Q_PRIVATE_SLOT(d_func(), void slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *)) - Q_PRIVATE_SLOT(d_func(), void slotPropertyRemoved(QtProperty *, QtProperty *)) - Q_DECLARE_PRIVATE(QtVariantPropertyManager) - Q_DISABLE_COPY(QtVariantPropertyManager) -}; - -class QtVariantEditorFactoryPrivate; - -class QT_QTPROPERTYBROWSER_EXPORT QtVariantEditorFactory : public QtAbstractEditorFactory -{ - Q_OBJECT -public: - QtVariantEditorFactory(QObject *parent = 0); - ~QtVariantEditorFactory(); -protected: - void connectPropertyManager(QtVariantPropertyManager *manager); - QWidget *createEditor(QtVariantPropertyManager *manager, QtProperty *property, - QWidget *parent); - void disconnectPropertyManager(QtVariantPropertyManager *manager); -private: - QtVariantEditorFactoryPrivate *d_ptr; - Q_DECLARE_PRIVATE(QtVariantEditorFactory) - Q_DISABLE_COPY(QtVariantEditorFactory) -}; - -#if QT_VERSION >= 0x040400 -QT_END_NAMESPACE -#endif - -Q_DECLARE_METATYPE(QIcon) -Q_DECLARE_METATYPE(QtIconMap) -#endif diff --git a/ThirdParty/Ert-windows/Building_ERT_libs_for_ResInsight.txt b/ThirdParty/Ert-windows/Building_ERT_libs_for_ResInsight.txt new file mode 100644 index 0000000000..7603b6b546 --- /dev/null +++ b/ThirdParty/Ert-windows/Building_ERT_libs_for_ResInsight.txt @@ -0,0 +1,59 @@ + +# System requirements + +MINGW +Install MINGW, and make sure c++, fortran and MSYS are installed +http://www.mingw.org/wiki/Getting_Started + +LAPACK/BLAS +http://icl.cs.utk.edu/lapack-for-windows/lapack/ +Download relevant DLLs + +# Create a folder for ERT source code + +# For an initial checkout of code, see here +# http://ert.nr.no/wiki/index.php/Download +# svn co http://ert.nr.no/repos/ert + + +cd /ert/devel/ + +# First you might want to check what has happened since last update: +svn log -r BASE:HEAD + +# Then update and build the code: +svn up + +# using cmake +cmake-gui +Select MSYS toolchain + + +# Enter the following in the gui: +# Source code: /devel/ +# Binaries: c:/cmakebuild/ErtCmakeBuild + +# Then press configure, and edit the following variables: +# BLAS_LIBRARY: libblas.dll +# CMAKE_BUILD_TYPE: Release +# CMAKE_GNUtoMS : True +# CMAKE_INSTALL_PREFIX : /Projects/ResInsight/dev/ThirdParty/Ert-windows/ +# LAPACK_LIBRARY: liblapack.dll +# USE_ZLIB: False + +# then press Configure and then Generate + +# If you want to, you can start a start MINGW shell, if you want the common Windows way, start a command line window +cd /c/cmakebuild/ErtCmakeBuild + +make clean +make + +# make your copy of the library editable by checking it out +#p4 edit -c default /home/builder/Projects/ResInsight/ThirdParty/Ert-windows/... + +make install + +# Then check in if appropriate +# Finished. + diff --git a/ThirdParty/Ert-windows/bin/libblas.dll b/ThirdParty/Ert-windows/bin/libblas.dll new file mode 100644 index 0000000000..9b535fe239 Binary files /dev/null and b/ThirdParty/Ert-windows/bin/libblas.dll differ diff --git a/ThirdParty/Ert-windows/bin/libgfortran-3.dll b/ThirdParty/Ert-windows/bin/libgfortran-3.dll new file mode 100644 index 0000000000..0a924412f1 Binary files /dev/null and b/ThirdParty/Ert-windows/bin/libgfortran-3.dll differ diff --git a/ThirdParty/Ert-windows/bin/libgomp-1.dll b/ThirdParty/Ert-windows/bin/libgomp-1.dll new file mode 100644 index 0000000000..35ff14c51d Binary files /dev/null and b/ThirdParty/Ert-windows/bin/libgomp-1.dll differ diff --git a/ThirdParty/Ert-windows/bin/liblapack.dll b/ThirdParty/Ert-windows/bin/liblapack.dll new file mode 100644 index 0000000000..43dd2d4d26 Binary files /dev/null and b/ThirdParty/Ert-windows/bin/liblapack.dll differ diff --git a/ThirdParty/Ert-windows/bin/libquadmath-0.dll b/ThirdParty/Ert-windows/bin/libquadmath-0.dll new file mode 100644 index 0000000000..bdf0964a44 Binary files /dev/null and b/ThirdParty/Ert-windows/bin/libquadmath-0.dll differ diff --git a/ThirdParty/Ert-windows/bin/pthreadGC2.dll b/ThirdParty/Ert-windows/bin/pthreadGC2.dll new file mode 100644 index 0000000000..dbd7563782 Binary files /dev/null and b/ThirdParty/Ert-windows/bin/pthreadGC2.dll differ diff --git a/ThirdParty/Ert-windows/ecl/bin/convert.x.exe b/ThirdParty/Ert-windows/ecl/bin/convert.x.exe new file mode 100644 index 0000000000..56fd0cd8cf Binary files /dev/null and b/ThirdParty/Ert-windows/ecl/bin/convert.x.exe differ diff --git a/ThirdParty/Ert-windows/ecl/bin/grdecl_test.x.exe b/ThirdParty/Ert-windows/ecl/bin/grdecl_test.x.exe new file mode 100644 index 0000000000..de4bc49eec Binary files /dev/null and b/ThirdParty/Ert-windows/ecl/bin/grdecl_test.x.exe differ diff --git a/ThirdParty/Ert-windows/ecl/bin/grid_dump.x.exe b/ThirdParty/Ert-windows/ecl/bin/grid_dump.x.exe new file mode 100644 index 0000000000..3ad4e6c812 Binary files /dev/null and b/ThirdParty/Ert-windows/ecl/bin/grid_dump.x.exe differ diff --git a/ThirdParty/Ert-windows/ecl/bin/grid_dump_ascii.x.exe b/ThirdParty/Ert-windows/ecl/bin/grid_dump_ascii.x.exe new file mode 100644 index 0000000000..4e2af9afaf Binary files /dev/null and b/ThirdParty/Ert-windows/ecl/bin/grid_dump_ascii.x.exe differ diff --git a/ThirdParty/Ert-windows/ecl/bin/grid_info.x.exe b/ThirdParty/Ert-windows/ecl/bin/grid_info.x.exe new file mode 100644 index 0000000000..d502cc4eb4 Binary files /dev/null and b/ThirdParty/Ert-windows/ecl/bin/grid_info.x.exe differ diff --git a/ThirdParty/Ert-windows/ecl/bin/kw_list.x.exe b/ThirdParty/Ert-windows/ecl/bin/kw_list.x.exe new file mode 100644 index 0000000000..c62f2b8d58 Binary files /dev/null and b/ThirdParty/Ert-windows/ecl/bin/kw_list.x.exe differ diff --git a/ThirdParty/Ert-windows/ecl/bin/select_test.x.exe b/ThirdParty/Ert-windows/ecl/bin/select_test.x.exe new file mode 100644 index 0000000000..5a6b0e95cf Binary files /dev/null and b/ThirdParty/Ert-windows/ecl/bin/select_test.x.exe differ diff --git a/ThirdParty/Ert-windows/ecl/bin/summary.x.exe b/ThirdParty/Ert-windows/ecl/bin/summary.x.exe new file mode 100644 index 0000000000..c7541042b3 Binary files /dev/null and b/ThirdParty/Ert-windows/ecl/bin/summary.x.exe differ diff --git a/ThirdParty/Ert-windows/ecl/include/ecl_box.h b/ThirdParty/Ert-windows/ecl/include/ecl_box.h new file mode 100644 index 0000000000..457d71eeb1 --- /dev/null +++ b/ThirdParty/Ert-windows/ecl/include/ecl_box.h @@ -0,0 +1,48 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_box.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __ECL_BOX_H__ +#define __ECL_BOX_H__ +#ifdef __cplusplus +extern "C" { +#endif + +#include + + +typedef struct ecl_box_struct ecl_box_type; + + +void ecl_box_set_size (ecl_box_type * , int , int , int , int , int , int ); +ecl_box_type * ecl_box_alloc(const ecl_grid_type * ecl_grid , int i1,int i2 , int j1 , int j2 , int k1, int k2); +void ecl_box_free (ecl_box_type * ); +void ecl_box_set_values(const ecl_box_type * , char * , const char * , int ); +int ecl_box_get_total_size(const ecl_box_type * ); +int ecl_box_get_active_size( const ecl_box_type * ecl_box ); +const int * ecl_box_get_active_list( const ecl_box_type * ecl_box ); +int ecl_box_get_global_size( const ecl_box_type * ecl_box ); +const int * ecl_box_get_global_list( const ecl_box_type * ecl_box ); +bool ecl_box_contains(const ecl_box_type * box , int i , int j , int k); + +UTIL_IS_INSTANCE_HEADER( ecl_box ); +UTIL_SAFE_CAST_HEADER( ecl_box ); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/ecl/include/ecl_endian_flip.h b/ThirdParty/Ert-windows/ecl/include/ecl_endian_flip.h new file mode 100644 index 0000000000..e2c27159ee --- /dev/null +++ b/ThirdParty/Ert-windows/ecl/include/ecl_endian_flip.h @@ -0,0 +1,60 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_endian_flip.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __ECL_ENDIAN_FLIP_H__ +#define __ECL_ENDIAN_FLIP_H__ +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/** + This header file checks if the ECLIPSE endianness and the hardware + endianness are equal, and defines the macro ECL_ENDIAN_FLIP + accordingly. + + All the ecl_xxx functions will use the ECL_ENDIAN_FLIP macro to + determine whether the endian flip should be performed. When opening + a fortio instance explicitly you can use the ECL_ENDIAN_FLIP macro + to get the endianness correct (for ECLIPSE usage that is). +*/ + +#define ECLIPSE_BYTE_ORDER __BIG_ENDIAN // Alternatively: __LITTLE_ENDIAN + +#ifdef BYTE_ORDER + #if BYTE_ORDER == ECLIPSE_BYTE_ORDER + #define ECL_ENDIAN_FLIP false + #else + #define ECL_ENDIAN_FLIP true + #endif +#else + #ifdef WIN32 + #define ECL_ENDIAN_FLIP true // Unconditional byte flip on Windows. + #else + #error: The macro BYTE_ORDER is not defined? + #endif +#endif + +#undef ECLIPSE_BYTE_ORDER + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/ecl/include/ecl_file.h b/ThirdParty/Ert-windows/ecl/include/ecl_file.h new file mode 100644 index 0000000000..8c57f0cd85 --- /dev/null +++ b/ThirdParty/Ert-windows/ecl/include/ecl_file.h @@ -0,0 +1,114 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_file.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __ECL_FILE_H__ +#define __ECL_FILE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + + +#include +#include +#include +#include + + + typedef struct ecl_file_struct ecl_file_type; + void ecl_file_load_all( ecl_file_type * ecl_file ); + void ecl_file_push_block( ecl_file_type * ecl_file ); + void ecl_file_pop_block( ecl_file_type * ecl_file ); + ecl_file_type * ecl_file_open( const char * filename ); + ecl_file_type * ecl_file_open_writable( const char * filename ); + void ecl_file_close( ecl_file_type * ecl_file ); + void ecl_file_fortio_detach( ecl_file_type * ecl_file ); + void ecl_file_free__(void * arg); + ecl_kw_type * ecl_file_icopy_named_kw( const ecl_file_type * ecl_file , const char * kw, int ith); + ecl_kw_type * ecl_file_icopy_kw( const ecl_file_type * ecl_file , int index); + bool ecl_file_has_kw( const ecl_file_type * ecl_file , const char * kw); + int ecl_file_get_num_named_kw(const ecl_file_type * ecl_file , const char * kw); + int ecl_file_get_size( const ecl_file_type * ecl_file ); + int ecl_file_get_num_distinct_kw(const ecl_file_type * ecl_file); + const char * ecl_file_iget_distinct_kw(const ecl_file_type * ecl_file , int index); + const char * ecl_file_get_src_file( const ecl_file_type * ecl_file ); + int ecl_file_iget_occurence( const ecl_file_type * ecl_file , int index); + ecl_version_enum ecl_file_get_ecl_version( const ecl_file_type * file ); + void ecl_file_fwrite_fortio(const ecl_file_type * ec_file , fortio_type * fortio , int offset); + void ecl_file_fwrite(const ecl_file_type * ecl_file , const char * , bool fmt_file ); + + void ecl_file_replace_kw( ecl_file_type * ecl_file , ecl_kw_type * old_kw , ecl_kw_type * new_kw , bool insert_copy); + int ecl_file_get_phases( const ecl_file_type * init_file ); + void ecl_file_fprintf_kw_list( const ecl_file_type * ecl_file , FILE * stream ); + + + ecl_file_kw_type * ecl_file_iget_file_kw( const ecl_file_type * file , int global_index); + ecl_file_kw_type * ecl_file_iget_named_file_kw( const ecl_file_type * file , const char * kw, int ith); + ecl_kw_type * ecl_file_iget_kw( const ecl_file_type * file , int global_index); + ecl_type_enum ecl_file_iget_type( const ecl_file_type * file , int global_index); + int ecl_file_iget_size( const ecl_file_type * file , int global_index); + const char * ecl_file_iget_header( const ecl_file_type * file , int global_index); + ecl_kw_type * ecl_file_iget_named_kw( const ecl_file_type * file , const char * kw, int ith); + ecl_type_enum ecl_file_iget_named_type( const ecl_file_type * file , const char * kw , int ith); + int ecl_file_iget_named_size( const ecl_file_type * file , const char * kw , int ith); + + + bool ecl_file_subselect_block( ecl_file_type * ecl_file , const char * kw , int occurence); + bool ecl_file_select_block( ecl_file_type * ecl_file , const char * kw , int occurence); + void ecl_file_select_global( ecl_file_type * ecl_file ); + bool ecl_file_writable( const ecl_file_type * ecl_file ); + void ecl_file_save_kw( const ecl_file_type * ecl_file , const ecl_kw_type * ecl_kw); + bool ecl_file_has_kw_ptr( const ecl_file_type * ecl_file , const ecl_kw_type * ecl_kw); + +/*****************************************************************/ +/* R E S T A R T F I L E S */ + + time_t ecl_file_iget_restart_sim_date( const ecl_file_type * restart_file , int occurence ); + int ecl_file_get_restart_index( const ecl_file_type * restart_file , time_t sim_time); + bool ecl_file_has_report_step( const ecl_file_type * ecl_file , int report_step); + bool ecl_file_has_sim_time( const ecl_file_type * ecl_file , time_t sim_time); + + + bool ecl_file_select_rstblock_sim_time( ecl_file_type * ecl_file , time_t sim_time); + bool ecl_file_select_rstblock_report_step( ecl_file_type * ecl_file , int report_step); + bool ecl_file_iselect_rstblock( ecl_file_type * ecl_file , int seqnum_index ); + + ecl_file_type * ecl_file_open_rstblock_report_step( const char * filename , int report_step ); + ecl_file_type * ecl_file_open_rstblock_sim_time( const char * filename , time_t sim_time); + ecl_file_type * ecl_file_iopen_rstblock( const char * filename , int seqnum_index); + + ecl_file_type * ecl_file_open_rstblock_report_step_writable( const char * filename , int report_step ); + ecl_file_type * ecl_file_open_rstblock_sim_time_writable( const char * filename , time_t sim_time); + ecl_file_type * ecl_file_iopen_rstblock_writable( const char * filename , int seqnum_index); + +/*****************************************************************/ +/* SUMMARY FILES */ + + bool ecl_file_select_smryblock( ecl_file_type * ecl_file , int ministep_nr ); + ecl_file_type * ecl_file_open_smryblock( const char * filename , int ministep_nr ); + + + UTIL_IS_INSTANCE_HEADER( ecl_file ); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/ecl/include/ecl_file_kw.h b/ThirdParty/Ert-windows/ecl/include/ecl_file_kw.h new file mode 100644 index 0000000000..58a62741d1 --- /dev/null +++ b/ThirdParty/Ert-windows/ecl/include/ecl_file_kw.h @@ -0,0 +1,55 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_file_kw.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __ECL_FILE_KW_H__ +#define __ECL_FILE_KW_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include +#include + +typedef struct ecl_file_kw_struct ecl_file_kw_type; +typedef struct inv_map_struct inv_map_type; + + inv_map_type * inv_map_alloc(); + ecl_file_kw_type * inv_map_get_file_kw( inv_map_type * inv_map , const ecl_kw_type * ecl_kw ); + void inv_map_free( inv_map_type * map ); + + ecl_file_kw_type * ecl_file_kw_alloc( const ecl_kw_type * ecl_kw , long offset); + void ecl_file_kw_free( ecl_file_kw_type * file_kw ); + void ecl_file_kw_free__( void * arg ); + ecl_kw_type * ecl_file_kw_get_kw( ecl_file_kw_type * file_kw , fortio_type * fortio, inv_map_type * inv_map); + ecl_file_kw_type * ecl_file_kw_alloc_copy( const ecl_file_kw_type * src ); + const char * ecl_file_kw_get_header( const ecl_file_kw_type * file_kw ); + int ecl_file_kw_get_size( const ecl_file_kw_type * file_kw ); + ecl_type_enum ecl_file_kw_get_type( const ecl_file_kw_type * file_kw); + bool ecl_file_kw_ptr_eq( const ecl_file_kw_type * file_kw , const ecl_kw_type * ecl_kw); + void ecl_file_kw_replace_kw( ecl_file_kw_type * file_kw , fortio_type * target , ecl_kw_type * new_kw ); + void ecl_file_kw_fskip_data( const ecl_file_kw_type * file_kw , fortio_type * fortio); + void ecl_file_kw_inplace_fwrite( ecl_file_kw_type * file_kw , fortio_type * fortio); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/ThirdParty/Ert-windows/ecl/include/ecl_grav.h b/ThirdParty/Ert-windows/ecl/include/ecl_grav.h new file mode 100644 index 0000000000..95c342e9dc --- /dev/null +++ b/ThirdParty/Ert-windows/ecl/include/ecl_grav.h @@ -0,0 +1,46 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_grav.h' is part of ERT - Ensemble based + Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __ECL_GRAV_H__ +#define __ECL_GRAV_H__ +#ifdef __plusplus +extern "C" { +#endif + +#include +#include +#include + +typedef struct ecl_grav_struct ecl_grav_type; +typedef struct ecl_grav_survey_struct ecl_grav_survey_type; + + +void ecl_grav_free( ecl_grav_type * ecl_grav_config ); +ecl_grav_type * ecl_grav_alloc( const ecl_grid_type * ecl_grid, const ecl_file_type * init_file ); +ecl_grav_survey_type * ecl_grav_add_survey_FIP( ecl_grav_type * grav , const char * name , const ecl_file_type * restart_file ); +ecl_grav_survey_type * ecl_grav_add_survey_PORMOD( ecl_grav_type * grav , const char * name , const ecl_file_type * restart_file ); +ecl_grav_survey_type * ecl_grav_add_survey_RPORV( ecl_grav_type * grav , const char * name , const ecl_file_type * restart_file ); +double ecl_grav_eval( const ecl_grav_type * grav , const char * base, const char * monitor , ecl_region_type * region , double utm_x, double utm_y , double depth, int phase_mask); +void ecl_grav_new_std_density( ecl_grav_type * grav , ecl_phase_enum phase , double default_density); +void ecl_grav_add_std_density( ecl_grav_type * grav , ecl_phase_enum phase , int pvtnum , double density); + +#ifdef __plusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/ecl/include/ecl_grav_calc.h b/ThirdParty/Ert-windows/ecl/include/ecl_grav_calc.h new file mode 100644 index 0000000000..bf32d0d49e --- /dev/null +++ b/ThirdParty/Ert-windows/ecl/include/ecl_grav_calc.h @@ -0,0 +1,47 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_grav.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __ECL_GRAV_CALC_H__ +#define __ECL_GRAV_CALC_H__ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +double ecl_grav_phase_deltag( double utm_x , + double utm_y , + double tvd, + const ecl_grid_type * grid, + const ecl_file_type * init_file , + const ecl_kw_type * sat_kw1, + const ecl_kw_type * rho_kw1, + const ecl_kw_type * porv_kw1, + const ecl_kw_type * sat_kw2, + const ecl_kw_type * rho_kw2, + const ecl_kw_type * porv_kw2); + + + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/ThirdParty/Ert-windows/ecl/include/ecl_grav_common.h b/ThirdParty/Ert-windows/ecl/include/ecl_grav_common.h new file mode 100644 index 0000000000..d95ac487c7 --- /dev/null +++ b/ThirdParty/Ert-windows/ecl/include/ecl_grav_common.h @@ -0,0 +1,38 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_grav_common.h' is part of ERT - Ensemble based + Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __ECL_GRAV_COMMON_H__ +#define __ECL_GRAV_COMMON_H__ + +#ifdef __cplusplus +extern "C" { +#endif +#include + +#include +#include + + bool * ecl_grav_common_alloc_aquifer_cell( const ecl_grid_cache_type * grid_cache , const ecl_file_type * init_file); + double ecl_grav_common_eval_biot_savart( const ecl_grid_cache_type * grid_cache , ecl_region_type * region , const bool * aquifer , const double * weight , double utm_x , double utm_y , double depth); + +#ifdef __cplusplus +} + +#endif +#endif diff --git a/ThirdParty/Ert-windows/ecl/include/ecl_grid.h b/ThirdParty/Ert-windows/ecl/include/ecl_grid.h new file mode 100644 index 0000000000..a1865e0fc8 --- /dev/null +++ b/ThirdParty/Ert-windows/ecl/include/ecl_grid.h @@ -0,0 +1,152 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_grid.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __ECL_GRID_H__ +#define __ECL_GRID_H__ +#ifdef __cplusplus +extern "C" { +#endif +#include + +#include +#include +#include + +#include + + + typedef double (block_function_ftype) ( const double_vector_type *); + typedef struct ecl_grid_struct ecl_grid_type; + + void ecl_grid_get_column_property(const ecl_grid_type * ecl_grid , const ecl_kw_type * ecl_kw , int i , int j, double_vector_type * column); + int ecl_grid_get_global_index_from_xy_top( const ecl_grid_type * ecl_grid , double x , double y); + int ecl_grid_get_global_index_from_xy_bottom( const ecl_grid_type * ecl_grid , double x , double y); + + void ecl_grid_get_corner_xyz3(const ecl_grid_type * grid , int i , int j , int k, int corner_nr , double * xpos , double * ypos , double * zpos ); + void ecl_grid_get_corner_xyz1(const ecl_grid_type * grid , int global_index , int corner_nr , double * xpos , double * ypos , double * zpos ); + + double ecl_grid_get_cell_thickness3( const ecl_grid_type * grid , int i , int j , int k); + double ecl_grid_get_cell_thickness1( const ecl_grid_type * grid , int global_index ); + double ecl_grid_get_cdepth1(const ecl_grid_type * grid , int global_index); + double ecl_grid_get_cdepth3(const ecl_grid_type * grid , int i, int j , int k); + double ecl_grid_get_depth3(const ecl_grid_type * grid , int i, int j , int k); + int ecl_grid_get_global_index_from_xy( const ecl_grid_type * ecl_grid , int k , bool lower_layer , double x , double y); + bool ecl_grid_cell_contains_xyz1( const ecl_grid_type * ecl_grid , int global_index , double x , double y , double z); + bool ecl_grid_cell_contains_xyz3( const ecl_grid_type * ecl_grid , int i , int j , int k, double x , double y , double z ); + double ecl_grid_get_cell_volume1( const ecl_grid_type * ecl_grid, int global_index ); + double ecl_grid_get_cell_volume3( const ecl_grid_type * ecl_grid, int i , int j , int k); + bool ecl_grid_cell_contains1(const ecl_grid_type * grid , int global_index , double x , double y , double z); + bool ecl_grid_cell_contains3(const ecl_grid_type * grid , int i , int j ,int k , double x , double y , double z); + int ecl_grid_get_global_index_from_xyz(ecl_grid_type * grid , double x , double y , double z , int start_index); + const char * ecl_grid_get_name( const ecl_grid_type * ); + int ecl_grid_get_active_index3(const ecl_grid_type * ecl_grid , int i , int j , int k); + int ecl_grid_get_active_index1(const ecl_grid_type * ecl_grid , int global_index); + bool ecl_grid_cell_active3(const ecl_grid_type * , int , int , int ); + bool ecl_grid_cell_active1(const ecl_grid_type * , int); + bool ecl_grid_ijk_valid(const ecl_grid_type * , int , int , int ); + int ecl_grid_get_global_index3(const ecl_grid_type * , int , int , int ); + int ecl_grid_get_global_index1A(const ecl_grid_type * ecl_grid , int active_index); + ecl_grid_type * ecl_grid_alloc_GRDECL_kw( int nx, int ny , int nz , const ecl_kw_type * zcorn_kw , const ecl_kw_type * coord_kw , const ecl_kw_type * actnum_kw , const ecl_kw_type * mapaxes_kw ); + ecl_grid_type * ecl_grid_alloc_GRDECL_data(int , int , int , const float * , const float * , const int * , const float * mapaxes); + ecl_grid_type * ecl_grid_alloc_GRID_data(int num_coords , int nx, int ny , int nz , int coords_size , int ** coords , float ** corners , const float * mapaxes); + ecl_grid_type * ecl_grid_alloc(const char * ); + ecl_grid_type * ecl_grid_load_case( const char * case_input ); + bool ecl_grid_exists( const char * case_input ); + char * ecl_grid_alloc_case_filename( const char * case_input ); + + void ecl_grid_free(ecl_grid_type * ); + void ecl_grid_free__( void * arg ); + void ecl_grid_get_dims(const ecl_grid_type * , int *, int * , int * , int *); + int ecl_grid_get_nz( const ecl_grid_type * grid ); + int ecl_grid_get_nx( const ecl_grid_type * grid ); + int ecl_grid_get_ny( const ecl_grid_type * grid ); + int ecl_grid_get_active_index(const ecl_grid_type * , int , int , int ); + void ecl_grid_summarize(const ecl_grid_type * ); + void ecl_grid_get_ijk1(const ecl_grid_type * , int global_index , int *, int * , int *); + void ecl_grid_get_ijk1A(const ecl_grid_type * , int active_index, int *, int * , int *); + void ecl_grid_get_ijk_from_active_index(const ecl_grid_type *, int , int *, int * , int * ); + void ecl_grid_get_xyz3(const ecl_grid_type * , int , int , int , double * , double * , double *); + void ecl_grid_get_xyz1(const ecl_grid_type * grid , int global_index , double *xpos , double *ypos , double *zpos); + void ecl_grid_get_xyz1A(const ecl_grid_type * grid , int active_index , double *xpos , double *ypos , double *zpos); + int ecl_grid_get_global_size( const ecl_grid_type * ecl_grid ); + bool ecl_grid_compare(const ecl_grid_type * g1 , const ecl_grid_type * g2 , bool include_lgr); + int ecl_grid_get_active_size( const ecl_grid_type * ecl_grid ); + + double ecl_grid_get_bottom1(const ecl_grid_type * grid , int global_index); + double ecl_grid_get_bottom3(const ecl_grid_type * grid , int i, int j , int k); + double ecl_grid_get_bottom1A(const ecl_grid_type * grid , int active_index); + double ecl_grid_get_top1(const ecl_grid_type * grid , int global_index); + double ecl_grid_get_top3(const ecl_grid_type * grid , int i, int j , int k); + double ecl_grid_get_top1A(const ecl_grid_type * grid , int active_index); + double ecl_grid_get_top2(const ecl_grid_type * grid , int i, int j); + double ecl_grid_get_bottom2(const ecl_grid_type * grid , int i, int j); + int ecl_grid_locate_depth( const ecl_grid_type * grid , double depth , int i , int j ); + + void ecl_grid_alloc_blocking_variables(ecl_grid_type * , int ); + void ecl_grid_init_blocking(ecl_grid_type * ); + double ecl_grid_block_eval3d(ecl_grid_type * grid , int i, int j , int k ,block_function_ftype * blockf ); + int ecl_grid_get_block_count3d(const ecl_grid_type * ecl_grid , int i , int j, int k); + bool ecl_grid_block_value_3d(ecl_grid_type * , double , double ,double , double); + + bool ecl_grid_cell_invalid1(const ecl_grid_type * ecl_grid , int global_index); + bool ecl_grid_cell_invalid3(const ecl_grid_type * ecl_grid , int i , int j , int k); + double ecl_grid_cell_invalid1A(const ecl_grid_type * grid , int active_index); + + void ecl_grid_dump(const ecl_grid_type * grid , FILE * stream); + void ecl_grid_dump_ascii(const ecl_grid_type * grid , bool active_only , FILE * stream); + + /* lgr related functions */ + const ecl_grid_type * ecl_grid_get_cell_lgr3(const ecl_grid_type * grid , int i, int j , int k); + const ecl_grid_type * ecl_grid_get_cell_lgr1A(const ecl_grid_type * grid , int active_index); + const ecl_grid_type * ecl_grid_get_cell_lgr1(const ecl_grid_type * grid , int global_index ); + int ecl_grid_get_num_lgr(const ecl_grid_type * main_grid ); + int ecl_grid_get_grid_nr( const ecl_grid_type * ecl_grid ); + ecl_grid_type * ecl_grid_iget_lgr(const ecl_grid_type * main_grid , int lgr_nr); + ecl_grid_type * ecl_grid_get_lgr(const ecl_grid_type * main_grid, const char * __lgr_name); + bool ecl_grid_has_lgr(const ecl_grid_type * main_grid, const char * __lgr_name); + stringlist_type * ecl_grid_alloc_lgr_name_list(const ecl_grid_type * ecl_grid); + int ecl_grid_get_parent_cell1( const ecl_grid_type * grid , int global_index); + int ecl_grid_get_parent_cell3( const ecl_grid_type * grid , int i , int j , int k); + const ecl_grid_type * ecl_grid_get_global_grid( const ecl_grid_type * grid ); + bool ecl_grid_is_lgr( const ecl_grid_type * ecl_grid ); + + double ecl_grid_get_property(const ecl_grid_type * ecl_grid , const ecl_kw_type * ecl_kw , int i , int j , int k); + float ecl_grid_get_float_property(const ecl_grid_type * ecl_grid , const ecl_kw_type * ecl_kw , int i , int j , int k); + double ecl_grid_get_double_property(const ecl_grid_type * ecl_grid , const ecl_kw_type * ecl_kw , int i , int j , int k); + int ecl_grid_get_int_property(const ecl_grid_type * ecl_grid , const ecl_kw_type * ecl_kw , int i , int j , int k); + + void ecl_grid_grdecl_fprintf_kw( const ecl_grid_type * ecl_grid , const ecl_kw_type * ecl_kw , FILE * stream , double double_default); + bool ecl_grid_test_lgr_consistency( const ecl_grid_type * ecl_grid ); + + void ecl_grid_fwrite_EGRID( const ecl_grid_type * grid , const char * filename); + void ecl_grid_fwrite_GRID( const ecl_grid_type * grid , const char * filename); + void ecl_grid_fprintf_grdecl( const ecl_grid_type * grid , FILE * stream ); + + float * ecl_grid_alloc_coord_data( const ecl_grid_type * grid ); + ecl_kw_type * ecl_grid_alloc_coord_kw( const ecl_grid_type * grid ); + float * ecl_grid_alloc_zcorn_data( const ecl_grid_type * grid ); + ecl_kw_type * ecl_grid_alloc_zcorn_kw( const ecl_grid_type * grid ); + int * ecl_grid_alloc_actnum_data( const ecl_grid_type * grid ); + ecl_kw_type * ecl_grid_alloc_actnum_kw( const ecl_grid_type * grid ); + ecl_kw_type * ecl_grid_alloc_hostnum_kw( const ecl_grid_type * grid ); + ecl_kw_type * ecl_grid_alloc_gridhead_kw( int nx, int ny , int nz , int grid_nr); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/ecl/include/ecl_grid_cache.h b/ThirdParty/Ert-windows/ecl/include/ecl_grid_cache.h new file mode 100644 index 0000000000..407d50a27e --- /dev/null +++ b/ThirdParty/Ert-windows/ecl/include/ecl_grid_cache.h @@ -0,0 +1,46 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_grid_cache.h' is part of ERT - Ensemble based + Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __ECL_GRID_CACHE_H__ +#define __ECL_GRID_CACHE_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + typedef struct ecl_grid_cache_struct ecl_grid_cache_type; + + + ecl_grid_cache_type * ecl_grid_cache_alloc( const ecl_grid_type * grid ); + int ecl_grid_cache_get_size( const ecl_grid_cache_type * grid_cache ); + int ecl_grid_cache_iget_global_index( const ecl_grid_cache_type * grid_cache , int active_index); + const int * ecl_grid_cache_get_global_index( const ecl_grid_cache_type * grid_cache ); + const double * ecl_grid_cache_get_xpos( const ecl_grid_cache_type * grid_cache ); + const double * ecl_grid_cache_get_ypos( const ecl_grid_cache_type * grid_cache ); + const double * ecl_grid_cache_get_zpos( const ecl_grid_cache_type * grid_cache ); + void ecl_grid_cache_free( ecl_grid_cache_type * grid_cache ); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/ThirdParty/Ert-windows/ecl/include/ecl_intehead.h b/ThirdParty/Ert-windows/ecl/include/ecl_intehead.h new file mode 100644 index 0000000000..704b83150e --- /dev/null +++ b/ThirdParty/Ert-windows/ecl/include/ecl_intehead.h @@ -0,0 +1,102 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_INTEHEAD.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __ECL_INTEHEAD_H__ +#define __ECL_INTEHEAD_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define INTEHEAD_KW "INTEHEAD" /* Long array with lots of data. */ + + typedef struct { + int day; + int year; + int month; + time_t sim_time; + int version; // 100, 300, 500 (Eclipse300-Thermal) + int phase_sum; // Oil = 1 Gas = 2 Water = 4 + + int nx; + int ny; + int nz; + int nactive; + /*-----------------------------------------------------------------*/ + /* All fields below the line are taken literally (apart from + lowercasing) from the section about restart files in the + ECLIPSE File Formats Reference Manual. The elements typically + serve as dimensions in the ?WEL, ?SEG and ?CON arrays. + */ + + // Pure well properties + int nwells; // Number of wells + int niwelz; // Number of elements pr well in IWEL array + int nzwelz; // Number of 8 character words pr well in ZWEL array + + // Connection properties + int niconz; // Number of elements per completion in ICON array + int ncwmax; // Maximum number of completions per well + + // Segment properties + int nisegz; // Number of entries pr segment in the ISEG array + int nsegmx; // The maximum number of segments pr well + int nswlmx; // The maximum number of segmented wells + int nlbrmx; // The maximum number of lateral branches pr well + int nilbrz; // The number of entries pr segment in ILBR array + } ecl_intehead_type; + + +/* Some magic indices used to look up in the INTEHEAD keyword. */ +#define INTEHEAD_DAY_INDEX 64 +#define INTEHEAD_MONTH_INDEX 65 +#define INTEHEAD_YEAR_INDEX 66 + +#define INTEHEAD_NX_INDEX 8 +#define INTEHEAD_NY_INDEX 9 +#define INTEHEAD_NZ_INDEX 10 +#define INTEHEAD_NACTIVE_INDEX 11 + +#define INTEHEAD_PHASE_INDEX 14 +#define INTEHEAD_VERSION_INDEX 94 /* This is ECLIPSE100 || ECLIPSE300 - not temporal version. */ + +#define INTEHEAD_NWELLS_INDEX 16 +#define INTEHEAD_NIWELZ_INDEX 24 +#define INTEHEAD_NZWELZ_INDEX 27 + +#define INTEHEAD_NCWMAX_INDEX 17 +#define INTEHEAD_NICONZ_INDEX 32 + +#define INTEHEAD_NSWLMX_INDEX 175 +#define INTEHEAD_NSEGMX_INDEX 176 +#define INTEHEAD_NLBRMX_INDEX 177 +#define INTEHEAD_NISEGZ_INDEX 178 +#define INTEHEAD_NILBRZ_INDEX 180 + + void ecl_intehead_free( ecl_intehead_type * intehead ); + ecl_intehead_type * ecl_intehead_alloc( const ecl_kw_type * intehead_kw ); + time_t ecl_intehead_date( const ecl_kw_type * intehead_kw ); + void ecl_intehead_fprintf( const ecl_intehead_type * header , FILE * stream); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/ecl/include/ecl_io_config.h b/ThirdParty/Ert-windows/ecl/include/ecl_io_config.h new file mode 100644 index 0000000000..f7393a4535 --- /dev/null +++ b/ThirdParty/Ert-windows/ecl/include/ecl_io_config.h @@ -0,0 +1,41 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_io_config.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __ECL_IO_CONFIG_H__ +#define __ECL_IO_CONFIG_H__ + + +typedef struct ecl_io_config_struct ecl_io_config_type; + +/* Modifiers */ +void ecl_io_config_set_formatted(ecl_io_config_type *, bool ); +void ecl_io_config_set_unified_restart(ecl_io_config_type *, bool ); +void ecl_io_config_set_unified_summary(ecl_io_config_type *, bool ); + + +/* Accesors */ +bool ecl_io_config_get_formatted(ecl_io_config_type *); +bool ecl_io_config_get_unified_restart(ecl_io_config_type *); +bool ecl_io_config_get_unified_summary(ecl_io_config_type *); + + +/* Allocater & destructor */ +ecl_io_config_type * ecl_io_config_alloc(bool ,bool ,bool); +void ecl_io_config_free(ecl_io_config_type * ); + +#endif diff --git a/ThirdParty/Ert-windows/ecl/include/ecl_kw.h b/ThirdParty/Ert-windows/ecl/include/ecl_kw.h new file mode 100644 index 0000000000..89caeb3e46 --- /dev/null +++ b/ThirdParty/Ert-windows/ecl/include/ecl_kw.h @@ -0,0 +1,219 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_kw.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __ECL_KW_H__ +#define __ECL_KW_H__ +#ifdef __cplusplus +extern "C" { +#endif +#include +#include +#include + +#include + +#include +#include + + UTIL_IS_INSTANCE_HEADER(ecl_kw); + + + typedef struct ecl_kw_struct ecl_kw_type; + + void ecl_kw_set_data_ptr(ecl_kw_type * ecl_kw , void * data); + void ecl_kw_fwrite_data(const ecl_kw_type *_ecl_kw , fortio_type *fortio); + void ecl_kw_fread_realloc_data(ecl_kw_type *ecl_kw, fortio_type *fortio); + ecl_type_enum ecl_kw_get_type(const ecl_kw_type *); + const char * ecl_kw_get_header8(const ecl_kw_type *); + const char * ecl_kw_get_header(const ecl_kw_type * ecl_kw ); + ecl_kw_type * ecl_kw_alloc_empty(); + bool ecl_kw_fread_header(ecl_kw_type *, fortio_type *); + void ecl_kw_set_header_name(ecl_kw_type * , const char * ); + void ecl_kw_set_header(ecl_kw_type * , const char * , int , const char *); + void ecl_kw_set_header_alloc(ecl_kw_type * , const char * , int , const char *); + bool ecl_kw_fseek_kw(const char * , bool , bool , fortio_type *); + bool ecl_kw_fseek_last_kw(const char * , bool , fortio_type *); + void ecl_kw_inplace_update_file(const ecl_kw_type * , const char * , int ) ; + void ecl_kw_fskip(fortio_type *); + void ecl_kw_alloc_data(ecl_kw_type *); + void ecl_kw_alloc_double_data(ecl_kw_type * ecl_kw , double * values); + void ecl_kw_alloc_float_data(ecl_kw_type * ecl_kw , float * values); + bool ecl_kw_fread_realloc(ecl_kw_type *, fortio_type *); + void ecl_kw_fread(ecl_kw_type * , fortio_type * ); + ecl_kw_type * ecl_kw_fread_alloc(fortio_type *); + void ecl_kw_free_data(ecl_kw_type *); + void ecl_kw_free(ecl_kw_type *); + void ecl_kw_free__(void *); + ecl_kw_type * ecl_kw_alloc_copy (const ecl_kw_type *); + const void * ecl_kw_copyc__(const void *); + ecl_kw_type * ecl_kw_alloc_slice_copy( const ecl_kw_type * src, int index1, int index2, int stride); + //void * ecl_kw_get_data_ref(const ecl_kw_type *); + void * ecl_kw_alloc_data_copy(const ecl_kw_type * ); + void ecl_kw_memcpy(ecl_kw_type *, const ecl_kw_type *); + void ecl_kw_get_memcpy_data(const ecl_kw_type *, void *); + void ecl_kw_get_memcpy_float_data(const ecl_kw_type *ecl_kw , float *target); + void ecl_kw_get_memcpy_double_data(const ecl_kw_type *ecl_kw , double *target); + void ecl_kw_get_memcpy_int_data(const ecl_kw_type *ecl_kw , int *target); + void ecl_kw_set_memcpy_data(ecl_kw_type * , const void *); + void ecl_kw_fwrite(const ecl_kw_type *, fortio_type *); + void ecl_kw_iget(const ecl_kw_type *, int , void *); + void ecl_kw_iset(ecl_kw_type *ecl_kw , int i , const void *iptr); + void ecl_kw_iset_char_ptr( ecl_kw_type * ecl_kw , int index, const char * s); + void ecl_kw_iset_string8(ecl_kw_type * ecl_kw , int index , const char *s8); + const char * ecl_kw_iget_char_ptr( const ecl_kw_type * ecl_kw , int i); + void * ecl_kw_iget_ptr(const ecl_kw_type *, int); + int ecl_kw_get_size(const ecl_kw_type *); + bool ecl_kw_header_eq(const ecl_kw_type *, const char *); + bool ecl_kw_ichar_eq(const ecl_kw_type *, int , const char *); + ecl_kw_type * ecl_kw_alloc( const char * header , int size , ecl_type_enum ecl_type ); + ecl_kw_type * ecl_kw_alloc_new(const char * , int , ecl_type_enum , const void * ); + ecl_kw_type * ecl_kw_alloc_new_shared(const char * , int , ecl_type_enum , void * ); + void ecl_kw_fwrite_param(const char * , bool , const char * , ecl_type_enum , int , void * ); + void ecl_kw_fwrite_param_fortio(fortio_type *, const char * , ecl_type_enum , int , void * ); + void ecl_kw_summarize(const ecl_kw_type * ecl_kw); + void ecl_kw_fread_double_param(const char * , bool , double *); + float ecl_kw_iget_as_float(const ecl_kw_type * ecl_kw , int i); + double ecl_kw_iget_as_double(const ecl_kw_type * ecl_kw , int i); + void ecl_kw_get_data_as_double(const ecl_kw_type *, double *); + void ecl_kw_get_data_as_float(const ecl_kw_type * ecl_kw , float * float_data); + bool ecl_kw_equal(const ecl_kw_type *ecl_kw1, const ecl_kw_type *ecl_kw2); + bool ecl_kw_data_equal( const ecl_kw_type * ecl_kw , const void * data); + void ecl_kw_fskip_data__( ecl_type_enum ecl_type , int size , fortio_type * fortio); + void ecl_kw_fskip_data(ecl_kw_type *ecl_kw, fortio_type *fortio); + void ecl_kw_fread_data(ecl_kw_type *ecl_kw, fortio_type *fortio); + void ecl_kw_fskip_header( fortio_type * fortio); + + + bool ecl_kw_is_grdecl_file(FILE * ); + bool ecl_kw_is_kw_file(FILE * , bool ); + void ecl_kw_inplace_sub(ecl_kw_type * , const ecl_kw_type * ); + void ecl_kw_inplace_mul(ecl_kw_type * , const ecl_kw_type * ); + void ecl_kw_inplace_div(ecl_kw_type * , const ecl_kw_type * ); + + double ecl_kw_element_sum_float( const ecl_kw_type * ecl_kw ); + void ecl_kw_inplace_inv(ecl_kw_type * my_kw); + void ecl_kw_element_sum(const ecl_kw_type * , void * ); + void ecl_kw_max_min(const ecl_kw_type * , void * , void *); + void * ecl_kw_get_void_ptr(const ecl_kw_type * ecl_kw); + + double ecl_kw_iget_as_double(const ecl_kw_type * , int ); + + ecl_kw_type * ecl_kw_buffer_alloc(buffer_type * buffer); + void ecl_kw_buffer_store(const ecl_kw_type * ecl_kw , buffer_type * buffer); + + + void ecl_kw_memcpy_data( ecl_kw_type * target , const ecl_kw_type * src); + + bool ecl_kw_assert_numeric( const ecl_kw_type * kw ); + bool ecl_kw_assert_binary( const ecl_kw_type * kw1, const ecl_kw_type * kw2); + + void ecl_kw_scalar_set__(ecl_kw_type * ecl_kw , const void * value); + void ecl_kw_scalar_set_float_or_double( ecl_kw_type * ecl_kw , double value ); +#define ECL_KW_SCALAR_SET_TYPED_HEADER( ctype ) void ecl_kw_scalar_set_ ## ctype( ecl_kw_type * ecl_kw , ctype value); + ECL_KW_SCALAR_SET_TYPED_HEADER( int ) + ECL_KW_SCALAR_SET_TYPED_HEADER( float ) + ECL_KW_SCALAR_SET_TYPED_HEADER( double ) +#undef ECL_KW_SCALAR_SET_TYPED_HEADER + + ecl_kw_type * ecl_kw_alloc_scatter_copy( const ecl_kw_type * src_kw , int target_size , const int * mapping, void * def_value); + + void ecl_kw_inplace_add( ecl_kw_type * target_kw , const ecl_kw_type * add_kw); + void ecl_kw_inplace_add_indexed( ecl_kw_type * target_kw , const int_vector_type * index_set , const ecl_kw_type * add_kw); + void ecl_kw_inplace_sub_indexed( ecl_kw_type * target_kw , const int_vector_type * index_set , const ecl_kw_type * sub_kw); + void ecl_kw_copy_indexed( ecl_kw_type * target_kw , const int_vector_type * index_set , const ecl_kw_type * src_kw); + + bool ecl_kw_assert_binary_numeric( const ecl_kw_type * kw1, const ecl_kw_type * kw2); +#define ECL_KW_ASSERT_TYPED_BINARY_OP_HEADER( ctype ) bool ecl_kw_assert_binary_ ## ctype( const ecl_kw_type * kw1 , const ecl_kw_type * kw2); + ECL_KW_ASSERT_TYPED_BINARY_OP_HEADER( int ) + ECL_KW_ASSERT_TYPED_BINARY_OP_HEADER( float ) + ECL_KW_ASSERT_TYPED_BINARY_OP_HEADER( double ) +#undef ECL_KW_ASSERT_TYPED_BINARY_OP_HEADER + +#define ECL_KW_SCALE_TYPED_HEADER( ctype ) void ecl_kw_scale_ ## ctype (ecl_kw_type * ecl_kw , ctype scale_factor); + ECL_KW_SCALE_TYPED_HEADER( int ) + ECL_KW_SCALE_TYPED_HEADER( float ) + ECL_KW_SCALE_TYPED_HEADER( double ) +#undef ECL_KW_SCALE_TYPED_HEADER + void ecl_kw_scale_float_or_double( ecl_kw_type * ecl_kw , double scale_factor ); + + +#define ECL_KW_SHIFT_TYPED_HEADER( ctype ) void ecl_kw_shift_ ## ctype (ecl_kw_type * ecl_kw , ctype shift_factor); + ECL_KW_SHIFT_TYPED_HEADER( int ) + ECL_KW_SHIFT_TYPED_HEADER( float ) + ECL_KW_SHIFT_TYPED_HEADER( double ) +#undef ECL_KW_SHIFT_TYPED_HEADER + void ecl_kw_shift_float_or_double( ecl_kw_type * ecl_kw , double shift_value ); + + +#define ECL_KW_IGET_TYPED_HEADER(type) type ecl_kw_iget_ ## type(const ecl_kw_type * , int); + ECL_KW_IGET_TYPED_HEADER(double); + ECL_KW_IGET_TYPED_HEADER(float); + ECL_KW_IGET_TYPED_HEADER(int); +#undef ECL_KW_IGET_TYPED_HEADER + bool ecl_kw_iget_bool( const ecl_kw_type * ecl_kw , int i ); + + +#define ECL_KW_ISET_TYPED_HEADER(type) void ecl_kw_iset_ ## type(ecl_kw_type * , int , type ); + ECL_KW_ISET_TYPED_HEADER(double); + ECL_KW_ISET_TYPED_HEADER(float); + ECL_KW_ISET_TYPED_HEADER(int); +#undef ECL_KW_ISET_TYPED_HEADER + void ecl_kw_iset_bool( ecl_kw_type * ecl_kw , int i , bool bool_value); + + +#define ECL_KW_GET_TYPED_PTR_HEADER(type) type * ecl_kw_get_ ## type ## _ptr(const ecl_kw_type *); + ECL_KW_GET_TYPED_PTR_HEADER(double); + ECL_KW_GET_TYPED_PTR_HEADER(float); + ECL_KW_GET_TYPED_PTR_HEADER(int); + ECL_KW_GET_TYPED_PTR_HEADER(bool); +#undef ECL_KW_GET_TYPED_PTR_HEADER + + +#define ECL_KW_SET_INDEXED_HEADER(ctype ) void ecl_kw_set_indexed_ ## ctype( ecl_kw_type * ecl_kw, const int_vector_type * index_list , ctype value); + ECL_KW_SET_INDEXED_HEADER( double ); + ECL_KW_SET_INDEXED_HEADER( float ); + ECL_KW_SET_INDEXED_HEADER( int ); +#undef ECL_KW_SET_INDEXED_HEADER + + +#define ECL_KW_SHIFT_INDEXED_HEADER(ctype) void ecl_kw_shift_indexed_ ## ctype( ecl_kw_type * ecl_kw, const int_vector_type * index_list , ctype shift); + ECL_KW_SHIFT_INDEXED_HEADER( int ) + ECL_KW_SHIFT_INDEXED_HEADER( float ) + ECL_KW_SHIFT_INDEXED_HEADER( double ) +#undef ECL_KW_SHIFT_INDEXED_HEADER + + +#define ECL_KW_SCALE_INDEXED_HEADER(ctype) void ecl_kw_scale_indexed_ ## ctype( ecl_kw_type * ecl_kw, const int_vector_type * index_list , ctype scale); + ECL_KW_SCALE_INDEXED_HEADER( int ) + ECL_KW_SCALE_INDEXED_HEADER( float ) + ECL_KW_SCALE_INDEXED_HEADER( double ) +#undef ECL_KW_SCALE_INDEXED_HEADER + + +#define ECL_KW_MAX_MIN_HEADER( ctype ) void ecl_kw_max_min_ ## ctype( const ecl_kw_type * ecl_kw , ctype * _max , ctype * _min); + ECL_KW_MAX_MIN_HEADER( int ) + ECL_KW_MAX_MIN_HEADER( float ) + ECL_KW_MAX_MIN_HEADER( double ) +#undef ECL_KW_MAX_MIN_HEADER + +#include + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/ecl/include/ecl_kw_grdecl.h b/ThirdParty/Ert-windows/ecl/include/ecl_kw_grdecl.h new file mode 100644 index 0000000000..bd824dc599 --- /dev/null +++ b/ThirdParty/Ert-windows/ecl/include/ecl_kw_grdecl.h @@ -0,0 +1,56 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_kw_grdecl.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +/* + This header does not define datatypes; just a couple of functions. It should + be included from the ecl_kw.h header, so applications do not need to include this + header explicitly. +*/ + +#ifndef __ECL_KW_GRDECL_H__ +#define __ECL_KW_GRDECL_H__ +#ifdef __cplusplus +extern "C" { +#endif + + + + bool ecl_kw_grdecl_fseek_kw(const char * , bool , FILE * ); + + ecl_kw_type * ecl_kw_fscanf_alloc_grdecl_dynamic__( FILE * stream , const char * kw , bool strict , ecl_type_enum ecl_type); + ecl_kw_type * ecl_kw_fscanf_alloc_grdecl_dynamic( FILE * stream , const char * kw , ecl_type_enum ecl_type); + + ecl_kw_type * ecl_kw_fscanf_alloc_grdecl_data__(FILE * stream , bool strict , int size, ecl_type_enum ecl_type ); + ecl_kw_type * ecl_kw_fscanf_alloc_grdecl_data( FILE * stream , int size , ecl_type_enum ecl_type); + + ecl_kw_type * ecl_kw_fscanf_alloc_grdecl__(FILE * stream, const char * kw , bool strict , int size, ecl_type_enum ecl_type); + ecl_kw_type * ecl_kw_fscanf_alloc_grdecl(FILE * stream , const char * kw, int size, ecl_type_enum ecl_type); + + ecl_kw_type * ecl_kw_fscanf_alloc_current_grdecl__( FILE * stream , bool strict , ecl_type_enum ecl_type); + ecl_kw_type * ecl_kw_fscanf_alloc_current_grdecl( FILE * stream , ecl_type_enum ecl_type); + + bool ecl_kw_grdecl_fseek_next_kw( FILE * stream ); + char * ecl_kw_grdecl_alloc_next_header( FILE * stream ); + + void ecl_kw_fprintf_grdecl(const ecl_kw_type * ecl_kw , FILE * stream); + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/ThirdParty/Ert-windows/ecl/include/ecl_kw_magic.h b/ThirdParty/Ert-windows/ecl/include/ecl_kw_magic.h new file mode 100644 index 0000000000..40b9c2cdf3 --- /dev/null +++ b/ThirdParty/Ert-windows/ecl/include/ecl_kw_magic.h @@ -0,0 +1,195 @@ +#ifndef __ECL_KW_MAGIC_H__ +#define __ECL_KW_MAGIC_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + This header file contains names and indices of ECLIPSE keywords + which have special significance in various files; everything + related to the INTEHEAD keyword is in the ecl_intehead.h header + file. +*/ + + +/*****************************************************************/ +/* INIT and RESTART files: */ +/*****************************************************************/ + +#define SEQNUM_KW "SEQNUM" /* Contains the report step as the only data; + not present in non-unified files, where the + report step can be inferred from the filename. */ + + +#define IWEL_KW "IWEL" +#define ZWEL_KW "ZWEL" +#define ICON_KW "ICON" +#define ISEG_KW "ISEG" + +#define PORV_KW "PORV" +#define AQUIFER_KW "AQUIFERN" + +/*****************************************************************/ +/* Summary files */ +/*****************************************************************/ + +/* Summary header file */ +#define STARTDAT_KW "STARTDAT" /* Intgere keyword containing day,month,year. */ +#define WGNAMES_KW "WGNAMES" /* The names of wells/groups for the summary vectors. */ +#define KEYWORDS_KW "KEYWORDS" /* The variable type for the various summary vectors. */ +#define UNITS_KW "UNITS" /* The units, i.e SM^3/DAY the summary vectors. */ +#define DIMENS_KW "DIMENS" /* The dimensions of the grid - also used in the GRID files. */ +#define NUMS_KW "NUMS" /* Extra numeric qualifiers for the summary variables, like cell number. */ +#define LGRS_KW "LGRS" /* The lgr name for a vector originating from an lgr. */ +#define NUMLX_KW "NUMLX" /* For block variables defined in a an lgr this is i coordinate in the lgr. */ +#define NUMLY_KW "NUMLY" /* ... j coordinate in the lgr. */ +#define NUMLZ_KW "NUMLZ" /* ... k coordinate in the lgr. */ + + +/* Magic indices used to locate day,month,year from the STARTDAT keyword. */ +#define STARTDAT_DAY_INDEX 0 +#define STARTDAT_MONTH_INDEX 1 +#define STARTDAT_YEAR_INDEX 2 + + +/* Magic indices uset to locate the grid dimensions from the DIMENS + keyword in the SMSPEC files. Observe that these magic indices + differ from the magic indices used to look up grid dimensions from + the DIMENS keyword in GRID files. */ +#define DIMENS_SMSPEC_NX_INDEX 1 +#define DIMENS_SMSPEC_NY_INDEX 2 +#define DIMENS_SMSPEC_NZ_INDEX 3 + + +/* Summary data files: */ +#define SEQHDR_KW "SEQHDR" // Contains a single 'magic' integer - not used in libecl. +#define PARAMS_KW "PARAMS" // Contains the actual summary data for one timestep. +#define MINISTEP_KW "MINISTEP" // Scalar integer - contains the timestep number. + +/* + There are no magic indices in the summary data files, for all + interesting data the table created from the ecl_smspec file must be + consulted. +*/ + + +/*****************************************************************/ +/* RFT Files */ +/*****************************************************************/ +/* The files with extension .RFT can contain three quite different + types of information: RFT / PLT / SEGMENT, this is indicated by an + element of the WELLETC keyword. The keywords below are organized in + common keywords, keywords for RFTs and keywords for PLTs. The + special information for SEGMENT data is not internalized at all, + and there are also several additional keywords for the PLTs which + are not internalized. */ + + +/* Common keywords */ +#define TIME_KW "TIME" /* The days since simulation start when + an RFT is performed, also used as + block header when splitting an RFT + file into different wells and timesteps. */ +#define DATE_KW "DATE" /* The date of an RFT as integers: (day,month,year). */ +#define WELLETC_KW "WELLETC" /* The type of date RFT|PLT|SEGMENT and well name are + extracted from this keyword. */ +#define CONIPOS_KW "CONIPOS" /* The i-index of the connections in the well. */ +#define CONJPOS_KW "CONJPOS" /* The j-index ... */ +#define CONKPOS_KW "CONKPOS" /* The k-index ... */ + +/* RFT keywords */ +#define SWAT_KW "SWAT" /* The kewyord containing SWAT. */ +#define SGAS_KW "SGAS" /* The kewyord containing SGAS. */ +#define PRESSURE_KW "PRESSURE" /* The kewyord containing PRESSURE. */ +#define DEPTH_KW "DEPTH" /* The depth of the connection. */ + +/* PLT keywords */ +#define CONDEPTH_KW "CONDEPTH" /* The depth of the connection. */ +#define CONWRAT_KW "CONWRAT" /* Water rate in a connection. */ +#define CONGRAT_KW "CONGRAT" /* Gas ... */ +#define CONORAT_KW "CONORAT" /* Oil ... */ +#define CONPRES_KW "CONPRES" /* Pressure ... */ + + + +#define WELLETC_TYPE_INDEX 5 /* At this keyword the WELLETC keyword contains a string + containing 'R', 'P' , or 'S' for RFT, PLT or SEGMENT data + respectively.*/ +#define WELLETC_NAME_INDEX 1 /* The name of well being investigated is on this index of + the WELLETC keyword. */ + +/* Magic indices used to get day,month,year from the DATE + keyword. */ +#define DATE_DAY_INDEX 0 +#define DATE_MONTH_INDEX 1 +#define DATE_YEAR_INDEX 2 + + +/*****************************************************************/ +/* GRID and EGRID files. */ +/*****************************************************************/ +/* GRID and EGRID files have very different structure, and only a few + keywords are shared. */ + + +/* Common keywords */ +#define SPECGRID_KW "SPECGRID" +#define MAPAXES_KW "MAPAXES" /* Keyword used to transform from grid coordinates to + world coordinates. */ +#define LGR_KW "LGR" /* Name of LGR; for GRID files it can contain two elements, + the second element will be the name of the parent. */ +#define MAPUNITS_KW "MAPUNITS" +#define GRIDUNIT_KW "GRIDUNIT" + + +/* EGRID keywords */ +#define LGR_PARENT_KW "LGRPARNT" /* The name of the parent for an LGR. */ +#define COORDS_KW "COORDS" /* The (x,y) coordinates of the top and bottom of the pillars constituting the grid. */ +#define ZCORN_KW "ZCORN" /* Z coordinate where pillars cross planes. */ +#define ACTNUM_KW "ACTNUM" /* Integer flag of with active=0,1. */ +#define HOSTNUM_KW "HOSTNUM" /* For cells in LGR - pointing back to cell nr in + parent grid. */ +#define FILEHEAD_KW "FILEHEAD" +#define ENDGRID_KW "ENDGRID" +#define ENDLGR_KW "ENDLGR" + +/* GRID keywords */ +#define GRIDHEAD_KW "GRIDHEAD" /* Header information for GRID files. */ +#define COORD_KW "COORD" /* Header information for one cell in GRID file. */ +#define CORNERS_KW "CORNERS" /* Vector containing (x,y,z) x 8 elements - all corners in a cell. */ +#define DIMENS_KW "DIMENS" /* The dimensions of the grid. */ +#define RADIAL_KW "RADIAL" + +#define GLOBAL_STRING "GLOBAL" + +#define GRIDHEAD_TYPE_INDEX 0 +#define GRIDHEAD_NX_INDEX 1 +#define GRIDHEAD_NY_INDEX 2 +#define GRIDHEAD_NZ_INDEX 3 +#define GRIDHEAD_LGR_INDEX 4 +#define GRIDHEAD_SIZE 100 + +/* Observe that these indices are one value lower than the values used + in the ecl_smspec file. */ +#define DIMENS_NX_INDEX 0 +#define DIMENS_NY_INDEX 1 +#define DIMENS_NZ_INDEX 2 + +#define FILEHEAD_VERSION_INDEX 0 +#define FILEHEAD_YEAR_INDEX 1 +#define FILEHEAD_COMPAT_INDEX 3 +#define FILEHEAD_TYPE_INDEX 4 +#define FILEHEAD_DUALP_INDEX 5 +#define FILEHEAD_ORGFORMAT_INDEX 6 + +#define GRIDHEAD_GRIDTYPE_CORNERPOINT 1 /* <----\ */ + /* | Fucking hysterical! */ +#define FILEHEAD_GRIDTYPE_CORNERPOINT 0 /* <----/ */ +#define FILEHEAD_SINGLE_POROSITY 0 +#define FILEHEAD_ORGTYPE_CORNERPOINT 1 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/ecl/include/ecl_region.h b/ThirdParty/Ert-windows/ecl/include/ecl_region.h new file mode 100644 index 0000000000..f7b1b5467c --- /dev/null +++ b/ThirdParty/Ert-windows/ecl/include/ecl_region.h @@ -0,0 +1,185 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_region.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __ECL_REGION_H__ +#define __ECL_REGION_H__ +#ifdef __cplusplus +extern "C" { +#endif +#include + +#include + +#include + +#include +#include + + +typedef enum { + SELECT_ALL = 0, + DESELECT_ALL = 1, + SELECT_FROM_IJK = 2, + DESELECT_FROM_IJK = 3, + SELECT_FROM_I = 4, + DSELECT_FROM_I = 5, + SELECT_FROM_J = 6, + DSELECT_FROM_J = 7, + SELECT_FROM_K = 8, + DSELECT_FROM_K = 9, + SELECT_EQUAL = 10, + DESELECT_EQUAL = 11, + SELECT_IN_INTERVAL = 12, + DESELECT_IN_INTERVAL = 13, + INVERT_SELECTION = 14 +} ecl_region_select_cmd; + + + +typedef struct ecl_region_struct ecl_region_type; + +void ecl_region_unlock( ecl_region_type * region ); +void ecl_region_lock( ecl_region_type * region ); +void ecl_region_reset( ecl_region_type * ecl_region ); +ecl_region_type * ecl_region_alloc_copy( const ecl_region_type * ecl_region ); +ecl_region_type * ecl_region_alloc( const ecl_grid_type * ecl_grid , bool preselect); +void ecl_region_free( ecl_region_type * region ); +void ecl_region_free__( void * __region ); + +const int_vector_type * ecl_region_get_active_list( ecl_region_type * region ); +const int_vector_type * ecl_region_get_global_list( ecl_region_type * region ); +const int_vector_type * ecl_region_get_global_active_list( ecl_region_type * region ); + + bool ecl_region_contains_ijk( const ecl_region_type * ecl_region , int i , int j , int k); + bool ecl_region_contains_global( const ecl_region_type * ecl_region , int global_index); + bool ecl_region_contains_active( const ecl_region_type * ecl_region , int active_index); + + +void ecl_region_invert_selection( ecl_region_type * region ); +void ecl_region_select_all( ecl_region_type * region); +void ecl_region_deselect_all( ecl_region_type * region ); + +void ecl_region_select_in_interval( ecl_region_type * region , const ecl_kw_type * ecl_kw, float min_value , float max_value); +void ecl_region_deselect_in_interval( ecl_region_type * region , const ecl_kw_type * ecl_kw, float min_value , float max_value); + +void ecl_region_select_equal( ecl_region_type * region , const ecl_kw_type * ecl_kw, int value); +void ecl_region_deselect_equal( ecl_region_type * region , const ecl_kw_type * ecl_kw, int value); + +void ecl_region_select_inactive_cells( ecl_region_type * region ); +void ecl_region_deselect_inactive_cells( ecl_region_type * region ); +void ecl_region_select_active_cells( ecl_region_type * region ); +void ecl_region_deselect_active_cells( ecl_region_type * region ); + +void ecl_region_select_from_box( ecl_region_type * region , const ecl_box_type * ecl_box ); +void ecl_region_deselect_from_box( ecl_region_type * region , const ecl_box_type * ecl_box ); + +void ecl_region_select_from_ijkbox( ecl_region_type * region , int i1 , int i2 , int j1 , int j2 , int k1 , int k2); +void ecl_region_deselect_from_ijkbox( ecl_region_type * region , int i1 , int i2 , int j1 , int j2 , int k1 , int k2); + +void ecl_region_select_i1i2( ecl_region_type * region , int i1 , int i2); +void ecl_region_deselect_i1i2( ecl_region_type * region , int i1 , int i2); +void ecl_region_select_j1j2( ecl_region_type * region , int j1 , int j2); +void ecl_region_deselect_j1j2( ecl_region_type * region , int j1 , int i2); +void ecl_region_select_k1k2( ecl_region_type * region , int k1 , int k2); +void ecl_region_deselect_k1k2( ecl_region_type * region , int k1 , int i2); + +void ecl_region_select_shallow_cells( ecl_region_type * region , double depth_limit ); +void ecl_region_deselect_shallow_cells( ecl_region_type * region , double depth_limit ); +void ecl_region_select_deep_cells( ecl_region_type * region , double depth_limit ); +void ecl_region_deselect_deep_cells( ecl_region_type * region , double depth_limit ); + +void ecl_region_select_thin_cells( ecl_region_type * ecl_region , double dz_limit ); +void ecl_region_deselect_thin_cells( ecl_region_type * ecl_region , double dz_limit ); +void ecl_region_select_thick_cells( ecl_region_type * ecl_region , double dz_limit ); +void ecl_region_deselect_thick_cells( ecl_region_type * ecl_region , double dz_limit ); + +void ecl_region_select_small_cells( ecl_region_type * ecl_region , double volum_limit ); +void ecl_region_deselect_small_cells( ecl_region_type * ecl_region , double volum_limit ); +void ecl_region_select_large_cells( ecl_region_type * ecl_region , double volum_limit ); +void ecl_region_deselect_large_cells( ecl_region_type * ecl_region , double volum_limit ); + +void ecl_region_select_global_index( ecl_region_type * ecl_region , int global_index); +void ecl_region_deselect_global_index( ecl_region_type * ecl_region , int global_index); + +void ecl_region_select_active_index( ecl_region_type * ecl_region , int active_index); +void ecl_region_deselect_active_index( ecl_region_type * ecl_region , int active_index); + +void ecl_region_intersection( ecl_region_type * region , const ecl_region_type * new_region ); +void ecl_region_union( ecl_region_type * region , const ecl_region_type * new_region ); +void ecl_region_subtract( ecl_region_type * region , const ecl_region_type * new_region); +void ecl_region_xor( ecl_region_type * region , const ecl_region_type * new_region); + +void ecl_region_select_smaller( ecl_region_type * ecl_region , const ecl_kw_type * ecl_kw , float limit); +void ecl_region_deselect_smaller( ecl_region_type * ecl_region , const ecl_kw_type * ecl_kw , float limit); +void ecl_region_select_larger( ecl_region_type * ecl_region , const ecl_kw_type * ecl_kw , float limit); +void ecl_region_deselect_larger( ecl_region_type * ecl_region , const ecl_kw_type * ecl_kw , float limit); + +void ecl_region_cmp_select_less( ecl_region_type * ecl_region , const ecl_kw_type * kw1 , const ecl_kw_type * kw2); +void ecl_region_cmp_deselect_less( ecl_region_type * ecl_region , const ecl_kw_type * kw1 , const ecl_kw_type * kw2); +void ecl_region_cmp_select_more( ecl_region_type * ecl_region , const ecl_kw_type * kw1 , const ecl_kw_type * kw2); +void ecl_region_cmp_deselect_more( ecl_region_type * ecl_region , const ecl_kw_type * kw1 , const ecl_kw_type * kw2); + +void ecl_region_select_in_cylinder( ecl_region_type * region , double x0 , double y0, double R); +void ecl_region_deselect_in_cylinder( ecl_region_type * region , double x0 , double y0, double R); +void ecl_region_select_in_zcylinder( ecl_region_type * region , double x0 , double y0, double R , double z1 , double z2); +void ecl_region_deselect_in_zcylinder( ecl_region_type * region , double x0 , double y0, double R, double z1 , double z2); + +void ecl_region_select_above_plane( ecl_region_type * region, const double n[3] , const double p[3]); +void ecl_region_select_below_plane( ecl_region_type * region, const double n[3] , const double p[3]); +void ecl_region_deselect_above_plane( ecl_region_type * region, const double n[3] , const double p[3]); +void ecl_region_deselect_below_plane( ecl_region_type * region, const double n[3] , const double p[3]); + + void ecl_region_select_inside_polygon( ecl_region_type * region , const geo_polygon_type * polygon); + void ecl_region_deselect_inside_polygon( ecl_region_type * region , const geo_polygon_type * polygon); + void ecl_region_select_outside_polygon( ecl_region_type * region , const geo_polygon_type * polygon); + void ecl_region_deselect_outside_polygon( ecl_region_type * region , const geo_polygon_type * polygon); + +/*****************************************************************/ +/* Functions to manipulate ecl_kw instances . */ + +void ecl_region_set_kw_int( ecl_region_type * ecl_region , ecl_kw_type * ecl_kw , int value, bool force_active); +void ecl_region_set_kw_float( ecl_region_type * ecl_region , ecl_kw_type * ecl_kw , float value , bool force_active); +void ecl_region_set_kw_double( ecl_region_type * ecl_region , ecl_kw_type * ecl_kw , double value , bool force_active); +void ecl_region_kw_copy( ecl_region_type * ecl_region , ecl_kw_type * ecl_kw , const ecl_kw_type * src_kw , bool force_active); +int ecl_region_get_kw_size( ecl_region_type * ecl_region , const ecl_kw_type * ecl_kw , bool force_active); + +/*****************************************************************/ +/* set/get the name */ +void ecl_region_set_name( ecl_region_type * region , const char * name ); +const char * ecl_region_get_name( const ecl_region_type * region ); + +/*****************************************************************/ +/* Stupid cpp compat/legacy/cruft functions. */ + int ecl_region_get_active_size_cpp( ecl_region_type * region ); + int ecl_region_get_global_size_cpp( ecl_region_type * region ); + const int * ecl_region_get_active_list_cpp( ecl_region_type * region ); + const int * ecl_region_get_global_list_cpp( ecl_region_type * region ); + + +/*****************************************************************/ + + + + +UTIL_IS_INSTANCE_HEADER( ecl_region ); +UTIL_SAFE_CAST_HEADER( ecl_region ); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/ecl/include/ecl_rft_file.h b/ThirdParty/Ert-windows/ecl/include/ecl_rft_file.h new file mode 100644 index 0000000000..24bc7a1696 --- /dev/null +++ b/ThirdParty/Ert-windows/ecl/include/ecl_rft_file.h @@ -0,0 +1,60 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_rft_file.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __ECL_RFT_FILE_H__ +#define __ECL_RFT_FILE_H__ +#ifdef __cplusplus +extern "C" { +#endif +#include + +#include + +#include + +typedef struct ecl_rft_file_struct ecl_rft_file_type; + +char * ecl_rft_file_alloc_case_filename(const char * case_input ); +const char * ecl_rft_file_get_filename( const ecl_rft_file_type * rft_file ); +ecl_rft_file_type * ecl_rft_file_alloc_case(const char * case_input ); +bool ecl_rft_file_case_has_rft(const char * case_input ); +bool ecl_rft_file_case_has_rft( const char * case_input ); +ecl_rft_file_type * ecl_rft_file_alloc(const char * ); +void ecl_rft_file_free(ecl_rft_file_type * ); +void ecl_rft_file_block(const ecl_rft_file_type * , double , const char * , int , const double * , int * , int * , int *); +void ecl_rft_file_fprintf_rft_obs(const ecl_rft_file_type * , double , const char * , const char *, const char * , double); +ecl_rft_node_type * ecl_rft_file_get_node(const ecl_rft_file_type * , const char * ); +void ecl_rft_file_summarize(const ecl_rft_file_type * , bool ); +void ecl_rft_file_xml_summary( const ecl_rft_file_type * rft_file ); + +const ecl_rft_node_type * ecl_rft_file_get_well_time_rft( const ecl_rft_file_type * rft_file , const char * well , time_t recording_time); + +int ecl_rft_file_get_size__( const ecl_rft_file_type * rft_file, const char * well_pattern , time_t recording_time); +int ecl_rft_file_get_size( const ecl_rft_file_type * rft_file); +const ecl_rft_node_type * ecl_rft_file_iget_node( const ecl_rft_file_type * rft_file , int index); +const ecl_rft_node_type * ecl_rft_file_iget_well_rft( const ecl_rft_file_type * rft_file , const char * well, int index); +bool ecl_rft_file_has_well( const ecl_rft_file_type * rft_file , const char * well); +int ecl_rft_file_get_well_occurences( const ecl_rft_file_type * rft_file , const char * well); +stringlist_type * ecl_rft_file_alloc_well_list(const ecl_rft_file_type * rft_file ); +int ecl_rft_file_get_num_wells( const ecl_rft_file_type * rft_file ); +void ecl_rft_file_free__( void * arg); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/ecl/include/ecl_rft_node.h b/ThirdParty/Ert-windows/ecl/include/ecl_rft_node.h new file mode 100644 index 0000000000..3c830eac0d --- /dev/null +++ b/ThirdParty/Ert-windows/ecl/include/ecl_rft_node.h @@ -0,0 +1,61 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_rft_node.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __ECL_RFT_NODE_H__ +#define __ECL_RFT_NODE_H__ +#ifdef __cplusplus +extern "C" { +#endif +#include + +#include + +typedef enum { RFT = 1 , + PLT = 2 , + SEGMENT = 3 /* Not really implemented */ } ecl_rft_enum; + +typedef struct ecl_rft_node_struct ecl_rft_node_type; + +int ecl_rft_node_lookup_ijk( const ecl_rft_node_type * rft_node , int i, int j , int k); +void ecl_rft_node_fprintf_rft_obs(const ecl_rft_node_type * , double , const char * , const char * , double ); +ecl_rft_node_type * ecl_rft_node_alloc(const ecl_file_type * file_map ); +const char * ecl_rft_node_get_well_name(const ecl_rft_node_type * ); +void ecl_rft_node_free(ecl_rft_node_type * ); +void ecl_rft_node_free__(void * ); +void ecl_rft_node_block2(const ecl_rft_node_type * , int , const double * , const double * , int * , int * , int *); +void ecl_rft_node_block(const ecl_rft_node_type * , double , int , const double * , int * , int * , int *); +time_t ecl_rft_node_get_date(const ecl_rft_node_type * ); +int ecl_rft_node_get_size(const ecl_rft_node_type * ); +void ecl_rft_node_summarize(const ecl_rft_node_type * , bool ); +const char * ecl_rft_node_get_well_name( const ecl_rft_node_type * rft_node ); +void ecl_rft_node_iget_ijk( const ecl_rft_node_type * rft_node , int index , int *i , int *j , int *k); + +void ecl_rft_node_export_DEPTH(const ecl_rft_node_type * , const char * ); +double ecl_rft_node_iget_pressure( const ecl_rft_node_type * rft_node , int index); +double ecl_rft_node_iget_depth( const ecl_rft_node_type * rft_node , int index); +double ecl_rft_node_iget_wrat( const ecl_rft_node_type * rft_node , int index); +double ecl_rft_node_iget_grat( const ecl_rft_node_type * rft_node , int index); +double ecl_rft_node_iget_orat( const ecl_rft_node_type * rft_node , int index); +double ecl_rft_node_iget_swat( const ecl_rft_node_type * rft_node , int index); +double ecl_rft_node_iget_sgas( const ecl_rft_node_type * rft_node , int index); + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/ThirdParty/Ert-windows/ecl/include/ecl_smspec.h b/ThirdParty/Ert-windows/ecl/include/ecl_smspec.h new file mode 100644 index 0000000000..ea2062f0da --- /dev/null +++ b/ThirdParty/Ert-windows/ecl/include/ecl_smspec.h @@ -0,0 +1,133 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_smspec.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __ECL_SMSPEC__ +#define __ECL_SMSPEC__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +typedef struct ecl_smspec_struct ecl_smspec_type; + + +/** + These are the different variable types, see table 3.4 in the + ECLIPFE file format docuemntation for naming conventions. + + Only the variable types marked with "X" below are supported in the + remaining implementation. To add support for a new variable type + the functions smspec_node_alloc(), ecl_smsepec_fread_header() and + ecl_smspec_install_gen_key() must be updated. +*/ + +typedef enum {ECL_SMSPEC_INVALID_VAR = 0 , + ECL_SMSPEC_AQUIFER_VAR = 1 , + ECL_SMSPEC_WELL_VAR = 2 , /* X */ + ECL_SMSPEC_REGION_VAR = 3 , /* X */ + ECL_SMSPEC_FIELD_VAR = 4 , /* X */ + ECL_SMSPEC_GROUP_VAR = 5 , /* X */ + ECL_SMSPEC_BLOCK_VAR = 6 , /* X */ + ECL_SMSPEC_COMPLETION_VAR = 7 , /* X */ + ECL_SMSPEC_LOCAL_BLOCK_VAR = 8 , /* X */ + ECL_SMSPEC_LOCAL_COMPLETION_VAR = 9 , /* X */ + ECL_SMSPEC_LOCAL_WELL_VAR = 10 , /* X */ + ECL_SMSPEC_NETWORK_VAR = 11 , + ECL_SMSPEC_REGION_2_REGION_VAR = 12 , + ECL_SMSPEC_SEGMENT_VAR = 13 , /* X */ + ECL_SMSPEC_MISC_VAR = 14 /* X */} ecl_smspec_var_type; + +ecl_smspec_var_type ecl_smspec_iget_var_type( const ecl_smspec_type * smspec , int index ); +bool ecl_smspec_needs_num( ecl_smspec_var_type var_type ); +bool ecl_smspec_needs_wgname( ecl_smspec_var_type var_type ); +const char * ecl_smspec_get_var_type_name( ecl_smspec_var_type var_type ); +ecl_smspec_var_type ecl_smspec_identify_var_type(const char * var); + +bool ecl_smspec_general_is_total(const ecl_smspec_type * ecl_smspec , const char * gen_key); +bool ecl_smspec_is_rate(const ecl_smspec_type * smspec , int kw_index); + +ecl_smspec_type * ecl_smspec_fread_alloc(const char * , const char *, bool include_restart); +void ecl_smspec_free( ecl_smspec_type *); +void ecl_smspec_set_time_info( const ecl_smspec_type * , const float * , double * , time_t * ); + +int ecl_smspec_get_well_var_index(const ecl_smspec_type * ecl_smspec , const char * well , const char *var); +bool ecl_smspec_has_well_var(const ecl_smspec_type * ecl_smspec , const char * well , const char *var); + +int ecl_smspec_get_group_var_index(const ecl_smspec_type * ecl_smspec , const char * group , const char *var); +bool ecl_smspec_has_group_var(const ecl_smspec_type * ecl_smspec , const char * group , const char *var); + +int ecl_smspec_get_field_var_index(const ecl_smspec_type * ecl_smspec , const char *var); +bool ecl_smspec_has_field_var(const ecl_smspec_type * ecl_smspec , const char *var); + +int ecl_smspec_get_block_var_index(const ecl_smspec_type * ecl_smspec , const char * block_var , int block_nr); +bool ecl_smspec_has_block_var(const ecl_smspec_type * ecl_smspec , const char * block_var , int block_nr); +int ecl_smspec_get_block_var_index_ijk(const ecl_smspec_type * ecl_smspec , const char * block_var , int i , int j , int k); +bool ecl_smspec_has_block_var_ijk(const ecl_smspec_type * ecl_smspec , const char * block_var , int i , int j , int k); + +int ecl_smspec_get_region_var_index(const ecl_smspec_type * ecl_smspec , int region_nr , const char *var); +bool ecl_smspec_has_region_var(const ecl_smspec_type * ecl_smspec , int region_nr , const char *var); + +int ecl_smspec_get_misc_var_index(const ecl_smspec_type * ecl_smspec , const char *var); +bool ecl_smspec_has_misc_var(const ecl_smspec_type * ecl_smspec , const char *var); + +int ecl_smspec_get_well_completion_var_index(const ecl_smspec_type * ecl_smspec , const char * well , const char *var, int cell_nr); +bool ecl_smspec_has_well_completion_var(const ecl_smspec_type * ecl_smspec , const char * well , const char *var, int cell_nr); + +int ecl_smspec_get_general_var_index(const ecl_smspec_type * ecl_smspec , const char * lookup_kw); +bool ecl_smspec_has_general_var(const ecl_smspec_type * ecl_smspec , const char * lookup_kw); +const char * ecl_smspec_get_general_var_unit( const ecl_smspec_type * ecl_smspec , const char * lookup_kw); + + +ecl_smspec_var_type ecl_smspec_iget_var_type( const ecl_smspec_type * smspec , int index ); +const char * ecl_smspec_iget_unit( const ecl_smspec_type * smspec , int index ); +int ecl_smspec_iget_num( const ecl_smspec_type * smspec , int index ); +const char * ecl_smspec_iget_wgname( const ecl_smspec_type * smspec , int index ); +const char * ecl_smspec_iget_keyword( const ecl_smspec_type * smspec , int index ); + + + + + +void ecl_smspec_select_matching_general_var_list( const ecl_smspec_type * smspec , const char * pattern , stringlist_type * keys); +stringlist_type * ecl_smspec_alloc_matching_general_var_list(const ecl_smspec_type * smspec , const char * pattern); + +time_t ecl_smspec_get_start_time(const ecl_smspec_type * ); +/*****************************************************************/ +bool ecl_smspec_get_formatted( const ecl_smspec_type * ecl_smspec); +const char * ecl_smspec_get_header_file( const ecl_smspec_type * ecl_smspec ); +const char * ecl_smspec_get_simulation_case(const ecl_smspec_type * ); + stringlist_type * ecl_smspec_alloc_well_list( const ecl_smspec_type * smspec , const char * pattern); + stringlist_type * ecl_smspec_alloc_group_list( const ecl_smspec_type * smspec , const char * pattern); +stringlist_type * ecl_smspec_alloc_well_var_list( const ecl_smspec_type * smspec ); +const char * ecl_smspec_get_simulation_path(const ecl_smspec_type * ecl_smspec); +const char * ecl_smspec_get_base_name( const ecl_smspec_type * ecl_smspec); +const stringlist_type * ecl_smspec_get_restart_list( const ecl_smspec_type * ecl_smspec); +const char * ecl_smspec_get_join_string( const ecl_smspec_type * smspec); + + int ecl_smspec_get_param_size( const ecl_smspec_type * smspec ); + const char * ecl_smspec_iget_general_key( const ecl_smspec_type * smspec , int index); + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/ecl/include/ecl_subsidence.h b/ThirdParty/Ert-windows/ecl/include/ecl_subsidence.h new file mode 100644 index 0000000000..1c9250c9f7 --- /dev/null +++ b/ThirdParty/Ert-windows/ecl/include/ecl_subsidence.h @@ -0,0 +1,47 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_subsidence.h' is part of ERT - Ensemble based + Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __ECL_SUBSIDENCE_H__ +#define __ECL_SUBSICENCE_H__ +#ifdef __plusplus +extern "C" { +#endif + +#include +#include +#include + + typedef struct ecl_subsidence_struct ecl_subsidence_type; + typedef struct ecl_subsidence_survey_struct ecl_subsidence_survey_type; + + + void ecl_subsidence_free( ecl_subsidence_type * ecl_subsidence_config ); + ecl_subsidence_type * ecl_subsidence_alloc( const ecl_grid_type * ecl_grid, const ecl_file_type * init_file ); + ecl_subsidence_survey_type * ecl_subsidence_add_survey_PRESSURE( ecl_subsidence_type * subsidence , + const char * name , const ecl_file_type * restart_file ); + double ecl_subsidence_eval( const ecl_subsidence_type * subsidence , + const char * base, const char * monitor , + ecl_region_type * region , + double utm_x, double utm_y , double depth, double compressibility, double poisson_ratio); + + +#ifdef __plusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/ecl/include/ecl_sum.h b/ThirdParty/Ert-windows/ecl/include/ecl_sum.h new file mode 100644 index 0000000000..bd80ef7cc1 --- /dev/null +++ b/ThirdParty/Ert-windows/ecl/include/ecl_sum.h @@ -0,0 +1,170 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_sum.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __ECL_SUM_H__ +#define __ECL_SUM_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +#include + +#include +#include +#include + +typedef struct ecl_sum_struct ecl_sum_type; + + + +bool ecl_sum_check_sim_time( const ecl_sum_type * sum , time_t sim_time); +bool ecl_sum_check_sim_days( const ecl_sum_type * sum , double sim_days); +const char * ecl_sum_get_keyword( const ecl_sum_type * sum , const char * gen_key ); +const char * ecl_sum_get_wgname( const ecl_sum_type * sum , const char * gen_key ); +const char * ecl_sum_get_unit( const ecl_sum_type * sum , const char * gen_key ); +int ecl_sum_get_num( const ecl_sum_type * sum , const char * gen_key ); + +double ecl_sum_iiget( const ecl_sum_type * ecl_sum , int internal_index , int param_index); +const char * ecl_sum_iget_unit( const ecl_sum_type * ecl_sum , int param_index); +int ecl_sum_iget_num( const ecl_sum_type * sum , int param_index ); +const char * ecl_sum_iget_wgname( const ecl_sum_type * sum , int param_index ); +const char * ecl_sum_iget_keyword( const ecl_sum_type * sum , int param_index ); +int ecl_sum_get_data_length( const ecl_sum_type * ecl_sum ); +double ecl_sum_iget_from_sim_time( const ecl_sum_type * ecl_sum , time_t sim_time , int param_index); +double ecl_sum_iget_from_sim_days( const ecl_sum_type * ecl_sum , double sim_days , int param_index ); + + + +void ecl_sum_summarize( const ecl_sum_type * ecl_sum , FILE * stream ); +bool ecl_sum_general_is_total(const ecl_sum_type * ecl_sum , const char * gen_key); +bool ecl_sum_var_is_total(const ecl_sum_type * ecl_sum , const char * gen_key); +void ecl_sum_free_data(ecl_sum_type * ); +void ecl_sum_free__(void * ); +void ecl_sum_free(ecl_sum_type * ); +ecl_sum_type * ecl_sum_fread_alloc(const char * , const stringlist_type * data_files, const char * key_join_string); +ecl_sum_type * ecl_sum_fread_alloc_case(const char * , const char * key_join_string); +ecl_sum_type * ecl_sum_fread_alloc_case__(const char * , const char * key_join_string , bool include_restart); + +/* Accessor functions : */ +double ecl_sum_get_well_var(const ecl_sum_type * ecl_sum , int time_index , const char * well , const char *var); +int ecl_sum_get_well_var_index(const ecl_sum_type * ecl_sum , const char * well , const char *var); +bool ecl_sum_has_well_var(const ecl_sum_type * ecl_sum , const char * well , const char *var); +double ecl_sum_get_well_var_from_sim_days( const ecl_sum_type * ecl_sum , double sim_days , const char * well , const char * var); +double ecl_sum_get_well_var_from_sim_time( const ecl_sum_type * ecl_sum , time_t sim_time , const char * well , const char * var); + +double ecl_sum_get_group_var(const ecl_sum_type * ecl_sum , int time_index , const char * group , const char *var); +int ecl_sum_get_group_var_index(const ecl_sum_type * ecl_sum , const char * group , const char *var); +bool ecl_sum_has_group_var(const ecl_sum_type * ecl_sum , const char * group , const char *var); + +double ecl_sum_get_field_var(const ecl_sum_type * ecl_sum , int time_index , const char *var); +int ecl_sum_get_field_var_index(const ecl_sum_type * ecl_sum , const char *var); +bool ecl_sum_has_field_var(const ecl_sum_type * ecl_sum , const char *var); +double ecl_sum_get_field_var_from_sim_days( const ecl_sum_type * ecl_sum , double sim_days , const char * var); +double ecl_sum_get_field_var_from_sim_time( const ecl_sum_type * ecl_sum , time_t sim_time , const char * var); + +double ecl_sum_get_block_var(const ecl_sum_type * ecl_sum , int time_index , const char * block_var , int block_nr); +int ecl_sum_get_block_var_index(const ecl_sum_type * ecl_sum , const char * block_var , int block_nr); +bool ecl_sum_has_block_var(const ecl_sum_type * ecl_sum , const char * block_var , int block_nr); +double ecl_sum_get_block_var_ijk(const ecl_sum_type * ecl_sum , int time_index , const char * block_var , int i , int j , int k); +int ecl_sum_get_block_var_index_ijk(const ecl_sum_type * ecl_sum , const char * block_var , int i , int j , int k); +bool ecl_sum_has_block_var_ijk(const ecl_sum_type * ecl_sum , const char * block_var , int i , int j , int k); + +double ecl_sum_get_region_var(const ecl_sum_type * ecl_sum , int time_index , int region_nr , const char *var); +int ecl_sum_get_region_var_index(const ecl_sum_type * ecl_sum , int region_nr , const char *var); +bool ecl_sum_has_region_var(const ecl_sum_type * ecl_sum , int region_nr , const char *var); + +double ecl_sum_get_misc_var(const ecl_sum_type * ecl_sum , int time_index , const char *var); +int ecl_sum_get_misc_var_index(const ecl_sum_type * ecl_sum , const char *var); +bool ecl_sum_has_misc_var(const ecl_sum_type * ecl_sum , const char *var); + +double ecl_sum_get_well_completion_var(const ecl_sum_type * ecl_sum , int time_index , const char * well , const char *var, int cell_nr); +int ecl_sum_get_well_completion_var_index(const ecl_sum_type * ecl_sum , const char * well , const char *var, int cell_nr); +bool ecl_sum_has_well_completion_var(const ecl_sum_type * ecl_sum , const char * well , const char *var, int cell_nr); + +double ecl_sum_get_general_var(const ecl_sum_type * ecl_sum , int time_index , const char * lookup_kw); +int ecl_sum_get_general_var_index(const ecl_sum_type * ecl_sum , const char * lookup_kw); +bool ecl_sum_has_general_var(const ecl_sum_type * ecl_sum , const char * lookup_kw); +bool ecl_sum_has_key(const ecl_sum_type * ecl_sum , const char * lookup_kw); +double ecl_sum_get_general_var_from_sim_days( const ecl_sum_type * ecl_sum , double sim_days , const char * var); +double ecl_sum_get_general_var_from_sim_time( const ecl_sum_type * ecl_sum , time_t sim_time , const char * var); +const char * ecl_sum_get_general_var_unit( const ecl_sum_type * ecl_sum , const char * var); +/***************/ +void ecl_sum_fprintf(const ecl_sum_type * , FILE * , const stringlist_type * , bool report_only , bool print_header); + + + + +/* Time related functions */ +int ecl_sum_get_first_gt( const ecl_sum_type * ecl_sum , int param_index , double limit); +int ecl_sum_get_first_lt( const ecl_sum_type * ecl_sum , int param_index , double limit); +int ecl_sum_get_last_report_step( const ecl_sum_type * ecl_sum ); +int ecl_sum_get_first_report_step( const ecl_sum_type * ecl_sum ); +bool ecl_sum_has_report_step(const ecl_sum_type * ecl_sum , int report_step ); +time_t ecl_sum_get_report_time( const ecl_sum_type * ecl_sum , int report_step ); +time_t ecl_sum_iget_sim_time( const ecl_sum_type * ecl_sum , int index ); +double ecl_sum_iget_sim_days( const ecl_sum_type * ecl_sum , int time_index); +int ecl_sum_iget_report_step( const ecl_sum_type * ecl_sum , int internal_index ); +int ecl_sum_iget_mini_step( const ecl_sum_type * ecl_sum , int internal_index ); +double ecl_sum_iget_general_var(const ecl_sum_type * ecl_sum , int internal_index , const char * lookup_kw); + + +void ecl_sum_init_data_vector( const ecl_sum_type * ecl_sum , double_vector_type * data_vector , int data_index , bool report_only ); +double_vector_type * ecl_sum_alloc_data_vector( const ecl_sum_type * ecl_sum , int data_index , bool report_only); +time_t_vector_type * ecl_sum_alloc_time_vector( const ecl_sum_type * ecl_sum , bool report_only); + time_t ecl_sum_get_data_start( const ecl_sum_type * ecl_sum ); + time_t ecl_sum_get_end_time( const ecl_sum_type * ecl_sum); + time_t ecl_sum_get_start_time(const ecl_sum_type * ); + + const char * ecl_sum_get_case(const ecl_sum_type * ); +bool ecl_sum_same_case( const ecl_sum_type * ecl_sum , const char * input_file ); + +void ecl_sum_resample_from_sim_days( const ecl_sum_type * ecl_sum , const double_vector_type * sim_days , double_vector_type * value , const char * gen_key); +void ecl_sum_resample_from_sim_time( const ecl_sum_type * ecl_sum , const time_t_vector_type * sim_time , double_vector_type * value , const char * gen_key); +time_t ecl_sum_time_from_days( const ecl_sum_type * ecl_sum , double sim_days ); +double ecl_sum_days_from_time( const ecl_sum_type * ecl_sum , time_t sim_time ); +double ecl_sum_get_sim_length( const ecl_sum_type * ecl_sum ) ; + double ecl_sum_get_first_day( const ecl_sum_type * ecl_sum ); + +/*****************************************************************/ + stringlist_type * ecl_sum_alloc_well_list( const ecl_sum_type * ecl_sum , const char * pattern); + stringlist_type * ecl_sum_alloc_group_list( const ecl_sum_type * ecl_sum , const char * pattern); +stringlist_type * ecl_sum_alloc_well_var_list( const ecl_sum_type * ecl_sum ); +stringlist_type * ecl_sum_alloc_matching_general_var_list(const ecl_sum_type * ecl_sum , const char * pattern); +void ecl_sum_select_matching_general_var_list( const ecl_sum_type * ecl_sum , const char * pattern , stringlist_type * keys); +const ecl_smspec_type * ecl_sum_get_smspec( const ecl_sum_type * ecl_sum ); +ecl_smspec_var_type ecl_sum_identify_var_type(const char * var); +ecl_smspec_var_type ecl_sum_get_var_type( const ecl_sum_type * ecl_sum , const char * gen_key); +bool ecl_sum_var_is_rate( const ecl_sum_type * ecl_sum , const char * gen_key); +bool ecl_sum_var_is_total( const ecl_sum_type * ecl_sum , const char * gen_key); + + + +int ecl_sum_iget_report_end( const ecl_sum_type * ecl_sum , int report_step ); +int ecl_sum_iget_report_start( const ecl_sum_type * ecl_sum , int report_step ); + +UTIL_IS_INSTANCE_HEADER( ecl_sum ); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/ecl/include/ecl_sum_data.h b/ThirdParty/Ert-windows/ecl/include/ecl_sum_data.h new file mode 100644 index 0000000000..a35b866b9c --- /dev/null +++ b/ThirdParty/Ert-windows/ecl/include/ecl_sum_data.h @@ -0,0 +1,76 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_sum_data.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __ECL_SUM_DATA_H__ +#define __ECL_SUM_DATA_H__ + + +#ifdef __cplusplus +extern "C" { +#endif +#include +#include + +#include +#include +#include + +typedef struct ecl_sum_data_struct ecl_sum_data_type ; + + bool ecl_sum_data_check_sim_time( const ecl_sum_data_type * data , time_t sim_time); + bool ecl_sum_data_check_sim_days( const ecl_sum_data_type * data , double sim_days); + int ecl_sum_data_get_num_ministep( const ecl_sum_data_type * data ); + double_vector_type * ecl_sum_data_alloc_data_vector( const ecl_sum_data_type * data , int data_index , bool report_only); + void ecl_sum_data_init_data_vector( const ecl_sum_data_type * data , double_vector_type * data_vector , int data_index , bool report_only); + void ecl_sum_data_init_time_vector( const ecl_sum_data_type * data , time_t_vector_type * time_vector , bool report_only); + time_t_vector_type * ecl_sum_data_alloc_time_vector( const ecl_sum_data_type * data , bool report_only); + time_t ecl_sum_data_get_data_start( const ecl_sum_data_type * data ); + double ecl_sum_data_get_first_day( const ecl_sum_data_type * data); + time_t ecl_sum_data_get_sim_start ( const ecl_sum_data_type * data ); + time_t ecl_sum_data_get_sim_end ( const ecl_sum_data_type * data ); + double ecl_sum_data_get_sim_length( const ecl_sum_data_type * data ); + void ecl_sum_data_summarize(const ecl_sum_data_type * data , FILE * stream); + double ecl_sum_data_iget( const ecl_sum_data_type * data , int internal_index , int params_index ); + + double ecl_sum_data_iget_sim_days( const ecl_sum_data_type * , int ); + time_t ecl_sum_data_iget_sim_time( const ecl_sum_data_type * , int ); + + + bool ecl_sum_data_has_report_step(const ecl_sum_data_type * , int ); + + ecl_sum_data_type * ecl_sum_data_fread_alloc(const ecl_smspec_type * , const stringlist_type * filelist , bool include_restart); + void ecl_sum_data_free( ecl_sum_data_type * ); + int ecl_sum_data_get_last_report_step( const ecl_sum_data_type * data ); + int ecl_sum_data_get_first_report_step( const ecl_sum_data_type * data ); + int ecl_sum_data_get_first_ministep( const ecl_sum_data_type * data ); + int ecl_sum_data_get_last_ministep( const ecl_sum_data_type * data ); + + double ecl_sum_data_get_from_sim_time( const ecl_sum_data_type * data , time_t sim_time , int params_index); + double ecl_sum_data_get_from_sim_days( const ecl_sum_data_type * data , double sim_days , int params_index); + + int ecl_sum_data_get_length( const ecl_sum_data_type * data ); + int ecl_sum_data_iget_report_step(const ecl_sum_data_type * data , int internal_index); + int ecl_sum_data_iget_mini_step(const ecl_sum_data_type * data , int internal_index); + int ecl_sum_data_iget_report_end( const ecl_sum_data_type * data , int report_step ); + int ecl_sum_data_iget_report_start( const ecl_sum_data_type * data , int report_step ); + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/ecl/include/ecl_util.h b/ThirdParty/Ert-windows/ecl/include/ecl_util.h new file mode 100644 index 0000000000..36a480b5d0 --- /dev/null +++ b/ThirdParty/Ert-windows/ecl/include/ecl_util.h @@ -0,0 +1,185 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_util.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __ECL_UTIL_H__ +#define __ECL_UTIL_H__ +#ifdef __cplusplus +extern "C" { +#endif +#include +#include +#include + +typedef enum { ECL_OTHER_FILE = 0 , + ECL_RESTART_FILE = 1 , + ECL_UNIFIED_RESTART_FILE = 2 , + ECL_SUMMARY_FILE = 4 , + ECL_UNIFIED_SUMMARY_FILE = 8 , + ECL_SUMMARY_HEADER_FILE = 16 , + ECL_GRID_FILE = 32 , + ECL_EGRID_FILE = 64 , + ECL_INIT_FILE = 128 , + ECL_RFT_FILE = 256 , + ECL_DATA_FILE = 512 } ecl_file_enum; + + +#define ECL_FILE_ENUM_DEFS {.value = 0 , .name="ECL_OTHER_FILE"}, \ +{.value = 1 , .name="ECL_RESTART_FILE"}, \ +{.value = 2 , .name="ECL_UNIFIED_RESTART_FILE"}, \ +{.value = 4 , .name="ECL_SUMMARY_FILE"}, \ +{.value = 8 , .name="ECL_UNIFIED_SUMMARY_FILE"}, \ +{.value = 16 , .name="ECL_SUMMARY_HEADER_FILE"}, \ +{.value = 32 , .name="ECL_GRID_FILE"}, \ +{.value = 64 , .name="ECL_EGRID_FILE"}, \ +{.value = 128 , .name="ECL_INIT_FILE"}, \ +{.value = 256 , .name="ECL_RFT_FILE"}, \ +{.value = 512 , .name="ECL_DATA_FILE"} +#define ECL_FILE_ENUM_SIZE 11 + + + + /* + This enum enumerates the four different ways summary and restart information + can be stored. + */ + + + typedef enum { ECL_INVALID_STORAGE = 0, + ECL_BINARY_UNIFIED = 1, + ECL_FORMATTED_UNIFIED = 2, + ECL_BINARY_NON_UNIFIED = 4, + ECL_FORMATTED_NON_UNIFIED = 8} ecl_storage_enum; + +/* + Character data in ECLIPSE files comes as an array of fixed-length + string. Each of these strings is 8 characters long. The type name, + i.e. 'REAL', 'INTE', ... , come as 4 character strings. +*/ + + +#define ECL_STRING_LENGTH 8 +#define ECL_TYPE_LENGTH 4 + + + +/*****************************************************************/ +/* + Observe that these type identidiers are (ab)used in both the rms and + ert/enkf libraries in situations where ECLIPSE is not at all involved. +*/ + +typedef enum { + ECL_CHAR_TYPE = 0, + ECL_FLOAT_TYPE = 1, + ECL_DOUBLE_TYPE = 2, + ECL_INT_TYPE = 3, + ECL_BOOL_TYPE = 4, + ECL_MESS_TYPE = 5 +} ecl_type_enum; + +#define ECL_TYPE_ENUM_DEFS {.value = 0 , .name = "ECL_CHAR_TYPE"}, \ +{.value = 1 , .name = "ECL_FLOAT_TYPE"} , \ +{.value = 2 , .name = "ECL_DOUBLE_TYPE"}, \ +{.value = 3 , .name = "ECL_INT_TYPE"}, \ +{.value = 4 , .name = "ECL_BOOL_TYPE"}, \ +{.value = 5 , .name = "ECL_MESS_TYPE"} + +#define ECL_TYPE_ENUM_SIZE 6 + + + +/* + The libecl library has been built and tested 99.5% with ECLIPSE100 + as context, but in thye gravity code there is some very limited + functionality related to ECLIPSE100 versus ECLIPSE300 functionality. +*/ + +typedef enum { + ECLIPSE_UNDEFINED = 0, + ECLIPSE100 = 1, + ECLIPSE300 = 2 +} ecl_version_enum; + +/* + Observe that the numerical enum VALUES matches those found in item + 14 in the INTEHEAD keyword in the ECLIPSE INIT files; i.e. the + distribution of numerical values 1,2,4 can NOT BE CHANGED. + + The function ecl_util_get_phase_name() can be used to lookup a + string name from an enum value. + + The phases in a simulation will typically be a sum of these + fundamental phases, and represented as an integer. +*/ + +typedef enum { + ECL_OIL_PHASE = 1, + ECL_GAS_PHASE = 2, + ECL_WATER_PHASE = 4 +} ecl_phase_enum; + +#define ECL_PHASE_ENUM_DEFS {.value = 1 , .name = "ECL_OIL_PHASE"}, {.value = 2 , .name = "ECL_GAS_PHASE"} , {.value = 4 , .name = "ECL_WATER_PHASE"} +#define ECL_PHASE_ENUM_SIZE 3 + + + + +// For unformatted files: +#define ECL_BOOL_TRUE_INT -1 // Binary representation: 11111111 11111111 11111111 1111111 +#define ECL_BOOL_FALSE_INT 0 // Binary representation: 00000000 00000000 00000000 0000000 +#define ECL_COMMENT_STRING "--" +#define ECL_COMMENT_CHAR '-' // Need to consecutive to make an ECLIPSE comment +#define ECL_DATA_TERMINATION "/" + + +int ecl_util_get_sizeof_ctype(ecl_type_enum ); +ecl_type_enum ecl_util_get_type_from_name( const char * type_name ); +const char * ecl_util_get_type_name( ecl_type_enum ecl_type ); + +/*****************************************************************/ + +void ecl_util_init_stdin(const char * , const char *); +const char * ecl_util_file_type_name( ecl_file_enum file_type ); +char * ecl_util_alloc_base_guess(const char *); +int ecl_util_filename_report_nr(const char *); +ecl_file_enum ecl_util_get_file_type(const char * , bool * , int * ); +ecl_file_enum ecl_util_inspect_extension(const char * ext , bool *_fmt_file, int * _report_nr); +char * ecl_util_alloc_filename(const char * /* path */, const char * /* base */, ecl_file_enum , bool /* fmt_file */ , int /*report_nr*/); +char * ecl_util_alloc_exfilename(const char * /* path */, const char * /* base */, ecl_file_enum , bool /* fmt_file */ , int /*report_nr*/); +void ecl_util_memcpy_typed_data(void *, const void * , ecl_type_enum , ecl_type_enum , int ); +void ecl_util_escape_kw(char * kw); +bool ecl_util_alloc_summary_files(const char * , const char * , const char * , char ** , stringlist_type * ); +void ecl_util_alloc_summary_data_files(const char * path , const char * base , bool fmt_file , stringlist_type * filelist); +void ecl_util_alloc_restart_files(const char * , const char * , char *** , int * , bool * , bool *); +time_t ecl_util_get_start_date(const char * ); +int ecl_util_get_num_cpu(const char * data_file); +bool ecl_util_fmt_file(const char *); +char * ecl_util_alloc_exfilename_anyfmt(const char * path, const char * base , ecl_file_enum file_type , bool start_fmt , int report_nr); +int ecl_util_get_month_nr(const char * month_name); +int ecl_util_fname_report_cmp(const void *f1, const void *f2); + +bool ecl_util_valid_basename( const char * basename ); +const char * ecl_util_get_phase_name( ecl_phase_enum phase ); +const char * ecl_util_file_enum_iget( int index, int * value); + +int ecl_util_select_filelist( const char * path , const char * base , ecl_file_enum file_type , bool fmt_file , stringlist_type * filelist); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/ecl/include/fortio.h b/ThirdParty/Ert-windows/ecl/include/fortio.h new file mode 100644 index 0000000000..6b19123231 --- /dev/null +++ b/ThirdParty/Ert-windows/ecl/include/fortio.h @@ -0,0 +1,77 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'fortio.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __FORTIO_H__ +#define __FORTIO_H__ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +typedef enum { + FORTIO_NOENTRY = 0, /* File does not exists at all - application error. */ + FORTIO_EOF = 1, /* The file / record is empty */ + FORTIO_OK = 2, /* The file / record is OK with: [32 bit header | data | 32 bit footer] */ + FORTIO_MISSING_DATA = 3, + FORTIO_MISSING_TAIL = 4, + FORTIO_HEADER_MISMATCH = 5 +} fortio_status_type; + +#define FORTIO_READ 1 +#define FORTIO_WRITE 2 + +typedef struct fortio_struct fortio_type; + + fortio_status_type fortio_check_buffer( FILE * stream , bool endian_flip , size_t buffer_size ); + fortio_status_type fortio_check_file( const char * filename , bool endian_flip); + bool fortio_guess_endian_flip(const char * , bool *); + bool fortio_is_fortran_file(const char * , bool * ); + void fortio_copy_record(fortio_type * , fortio_type * , int , void * , bool *); + fortio_type * fortio_alloc_FILE_wrapper(const char * , bool , bool , FILE * ); + fortio_type * fortio_open_reader(const char *, bool fmt_file , bool endian_flip_header); + fortio_type * fortio_open_writer(const char *, bool fmt_file , bool endian_flip_header); + fortio_type * fortio_open_readwrite(const char *, bool fmt_file , bool endian_flip_header); + void fortio_free_FILE_wrapper(fortio_type *); + void fortio_fclose(fortio_type *); + int fortio_init_read(fortio_type *); + void fortio_complete_read(fortio_type *); + void fortio_init_write(fortio_type * , int); + void fortio_complete_write(fortio_type *); + void fortio_fskip_buffer(fortio_type *, int ); + int fortio_fskip_record(fortio_type *); + int fortio_fread_record(fortio_type * , char *buffer); + void fortio_fread_buffer(fortio_type * , char * , int ); + void fortio_fwrite_record(fortio_type * , const char *, int); + FILE * fortio_get_FILE(const fortio_type *); + void fortio_fflush(fortio_type * ) ; + int fortio_get_record_size(const fortio_type *); + bool fortio_is_fortio_file(fortio_type * ); + void fortio_rewind(const fortio_type *fortio); + const char * fortio_filename_ref(const fortio_type * ); + bool fortio_fmt_file(const fortio_type *); + long fortio_ftell( const fortio_type * fortio ); + int fortio_fseek( fortio_type * fortio , long offset , int whence); + int fortio_get_mode( const fortio_type * fortio ); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/ecl/include/smspec_node.h b/ThirdParty/Ert-windows/ecl/include/smspec_node.h new file mode 100644 index 0000000000..7566ea08b1 --- /dev/null +++ b/ThirdParty/Ert-windows/ecl/include/smspec_node.h @@ -0,0 +1,90 @@ +/* + Copyright (C) 2012 Statoil ASA, Norway. + + The file 'smspec_node.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#ifndef __SMSPEC_NODE_H__ +#define __SMSPEC_NODE_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + + +#define SMSPEC_NUMS_INVALID -991199 + + typedef struct smspec_node_struct smspec_node_type; + + char * smspec_alloc_block_ijk_key( const char * join_string , const char * keyword , int i , int j , int k); + char * smspec_alloc_completion_ijk_key( const char * join_string , const char * keyword, const char * wgname , int i , int j , int k); + char * smspec_alloc_completion_num_key( const char * join_string , const char * keyword, const char * wgname , int num); + char * smspec_alloc_group_key( const char * join_string , const char * keyword , const char * wgname); + char * smspec_alloc_well_key( const char * join_string , const char * keyword , const char * wgname); + char * smspec_alloc_region_key( const char * join_string , const char * keyword , int num); + char * smspec_alloc_segment_key( const char * join_string , const char * keyword , const char * wgname , int num); + char * smspec_alloc_block_num_key( const char * join_string , const char * keyword , int num); + char * smspec_alloc_local_well_key( const char * join_string , const char * keyword , const char * lgr_name , const char * wgname); + char * smspec_alloc_local_block_key( const char * join_string , const char * keyword , const char * lgr_name , int i , int j , int k); + char * smspec_alloc_local_completion_key( const char * join_string, const char * keyword , const char * lgr_name , const char * wgname , int i , int j , int k); + + + + + smspec_node_type * smspec_node_alloc_empty(ecl_smspec_var_type var_type, const char * keyword , const char * unit , int param_index); + void smspec_node_set_wgname( smspec_node_type * index , const char * wgname ); + void smspec_node_set_lgr_name( smspec_node_type * index , const char * lgr_name ); + void smspec_node_set_num( smspec_node_type * index , int num); + void smspec_node_set_gen_key( smspec_node_type * smspec_node , const char * key_join_string); + void smspec_node_set_flags( smspec_node_type * smspec_node); + + smspec_node_type * smspec_node_alloc( ecl_smspec_var_type var_type , + const char * wgname , + const char * keyword , + const char * unit , + const char * key_join_string , + int num , int index); + + smspec_node_type * smspec_node_alloc_lgr( ecl_smspec_var_type var_type , + const char * wgname , + const char * keyword , + const char * unit , + const char * lgr , + const char * key_join_string , + int lgr_i, int lgr_j , int lgr_k, + int index); + + void smspec_node_free( smspec_node_type * index ); + int smspec_node_get_index( const smspec_node_type * smspec_node ); + const char * smspec_node_get_gen_key( const smspec_node_type * smspec_node); + ecl_smspec_var_type smspec_node_get_var_type( const smspec_node_type * smspec_node); + int smspec_node_get_num( const smspec_node_type * smspec_node); + const char * smspec_node_get_wgname( const smspec_node_type * smspec_node); + const char * smspec_node_get_keyword( const smspec_node_type * smspec_node); + const char * smspec_node_get_unit( const smspec_node_type * smspec_node); + bool smspec_node_is_rate( const smspec_node_type * smspec_node ); + bool smspec_node_is_total( const smspec_node_type * smspec_node ); + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/ecl/include/stdbool.h b/ThirdParty/Ert-windows/ecl/include/stdbool.h new file mode 100644 index 0000000000..9cd5ec6a8a --- /dev/null +++ b/ThirdParty/Ert-windows/ecl/include/stdbool.h @@ -0,0 +1,20 @@ +/* + The ert code is based on C99, and in particular makes extensive use + of the C99 feature stdbool.h. When including the ert headers in a + VisualStudio C++ project this creates problems because the + VisualStudio C compiler is not C99 conforming, and the compiler will + complain it can not find the stdbool.h header. + + The symbols defined in the stdbool header are actually correctly(?) + defined by the VisualStudio compiler already, so this header file + does not define any bool related symbols! + + To actually use this file you should copy it manually into the ert + include directory as used by VisualStudio. +*/ + +#ifndef __STDBOOL_H__ +#define __STDBOOL_H__ + + +#endif diff --git a/ThirdParty/Ert-windows/ecl/lib/libecl.a b/ThirdParty/Ert-windows/ecl/lib/libecl.a new file mode 100644 index 0000000000..819ed5d936 Binary files /dev/null and b/ThirdParty/Ert-windows/ecl/lib/libecl.a differ diff --git a/ThirdParty/Ert-windows/ecl/lib/libecl.dll b/ThirdParty/Ert-windows/ecl/lib/libecl.dll new file mode 100644 index 0000000000..c7ad17fc9b Binary files /dev/null and b/ThirdParty/Ert-windows/ecl/lib/libecl.dll differ diff --git a/ThirdParty/Ert-windows/ecl/lib/libecl.dll.a b/ThirdParty/Ert-windows/ecl/lib/libecl.dll.a new file mode 100644 index 0000000000..a801c91cd0 Binary files /dev/null and b/ThirdParty/Ert-windows/ecl/lib/libecl.dll.a differ diff --git a/ThirdParty/Ert-windows/ecl/lib/libecl.lib b/ThirdParty/Ert-windows/ecl/lib/libecl.lib new file mode 100644 index 0000000000..98044c5bde Binary files /dev/null and b/ThirdParty/Ert-windows/ecl/lib/libecl.lib differ diff --git a/ThirdParty/Ert-windows/geometry/include/geo_pointset.h b/ThirdParty/Ert-windows/geometry/include/geo_pointset.h new file mode 100644 index 0000000000..d274136944 --- /dev/null +++ b/ThirdParty/Ert-windows/geometry/include/geo_pointset.h @@ -0,0 +1,42 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'geo_pointset.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __GEO_POINTSET_H__ +#define __GEO_POINTSET_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct geo_pointset_struct geo_pointset_type; + + + geo_pointset_type * geo_pointset_alloc( bool external_z ); + void geo_pointset_free( geo_pointset_type * pointset ); + void geo_pointset_add_xy( geo_pointset_type * pointset , double x , double y); + void geo_pointset_add_xyz( geo_pointset_type * pointset , double x , double y, double z); + int geo_pointset_get_size( const geo_pointset_type * pointset ); + void geo_pointset_iget_xy( const geo_pointset_type * pointset , int index , double * x , double * y); + const double * geo_pointset_get_zcoord( const geo_pointset_type * pointset ); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/geometry/include/geo_polygon.h b/ThirdParty/Ert-windows/geometry/include/geo_polygon.h new file mode 100644 index 0000000000..c1a35683a0 --- /dev/null +++ b/ThirdParty/Ert-windows/geometry/include/geo_polygon.h @@ -0,0 +1,40 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'geo_polygon.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __GEO_POLYGON_H__ +#define __GEO_POLYGON_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + + typedef struct geo_polygon_struct geo_polygon_type; + + geo_polygon_type * geo_polygon_alloc( ); + void geo_polygon_free( geo_polygon_type * polygon ); + void geo_polygon_free__( void * arg ); + void geo_polygon_add_point( geo_polygon_type * polygon , double x , double y ); + geo_polygon_type * geo_polygon_fload_alloc_irap( const char * filename ); + bool geo_polygon_contains_point( const geo_polygon_type * polygon , double x , double y); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/geometry/include/geo_region.h b/ThirdParty/Ert-windows/geometry/include/geo_region.h new file mode 100644 index 0000000000..57157409e5 --- /dev/null +++ b/ThirdParty/Ert-windows/geometry/include/geo_region.h @@ -0,0 +1,56 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'geo_region.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#include +#include +#include +#include +#include + +#ifndef __GEO_REGION_H__ +#define __GEO_REGION_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + + + typedef struct geo_region_struct geo_region_type; + + geo_region_type * geo_region_alloc( const geo_pointset_type * pointset , bool preselect); + void geo_region_free( geo_region_type * region ); + void geo_region_free__( void * arg ); + void geo_region_reset( geo_region_type * region ); + const int_vector_type * geo_region_get_index_list( geo_region_type * region ); + + void geo_region_select_inside_polygon( geo_region_type * region , const geo_polygon_type * polygon); + void geo_region_select_outside_polygon( geo_region_type * region , const geo_polygon_type * polygon); + void geo_region_deselect_inside_polygon( geo_region_type * region , const geo_polygon_type * polygon); + void geo_region_deselect_outside_polygon( geo_region_type * region , const geo_polygon_type * polygon); + + void geo_region_select_above_line( geo_region_type * region, const double xcoords[2] , const double ycoords[2]); + void geo_region_select_below_line( geo_region_type * region, const double xcoords[2] , const double ycoords[2]); + void geo_region_deselect_above_line( geo_region_type * region, const double xcoords[2] , const double ycoords[2]); + void geo_region_deselect_below_line( geo_region_type * region, const double xcoords[2] , const double ycoords[2]); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/geometry/include/geo_surface.h b/ThirdParty/Ert-windows/geometry/include/geo_surface.h new file mode 100644 index 0000000000..b97f9d50c6 --- /dev/null +++ b/ThirdParty/Ert-windows/geometry/include/geo_surface.h @@ -0,0 +1,46 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'geo_surface.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#ifndef __GEO_SURFACE_H__ +#define __GEO_SURFACE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + + + typedef struct geo_surface_struct geo_surface_type; + + + void geo_surface_free( geo_surface_type * geo_surface ); + void geo_surface_free__( void * arg); + geo_pointset_type * geo_surface_get_pointset( const geo_surface_type * surface ); + geo_surface_type * geo_surface_fload_alloc_irap( const char * filename , bool loadz); + void geo_surface_fload_irap_zcoord( const geo_surface_type * surface, const char * filename, double *zlist); + int geo_surface_get_size( const geo_surface_type * surface ); + void geo_surface_fprintf_irap( const geo_surface_type * surface, const char * filename ); + void geo_surface_fprintf_irap_external_zcoord( const geo_surface_type * surface, const char * filename , const double * zcoord); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/geometry/include/geo_util.h b/ThirdParty/Ert-windows/geometry/include/geo_util.h new file mode 100644 index 0000000000..f7eb45d6b7 --- /dev/null +++ b/ThirdParty/Ert-windows/geometry/include/geo_util.h @@ -0,0 +1,37 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'geo_util.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __GEO_UTIL_H__ +#define __GEO_UTIL_H__ + + +#ifdef __cplusplus +extern "C" { +#endif +#include + + +bool geo_util_inside_polygon(const double * xlist , const double * ylist , int num_points , double x0 , double y0); + + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/ThirdParty/Ert-windows/geometry/lib/libgeometry.a b/ThirdParty/Ert-windows/geometry/lib/libgeometry.a new file mode 100644 index 0000000000..477b6b024f Binary files /dev/null and b/ThirdParty/Ert-windows/geometry/lib/libgeometry.a differ diff --git a/ThirdParty/Ert-windows/geometry/lib/libgeometry.dll b/ThirdParty/Ert-windows/geometry/lib/libgeometry.dll new file mode 100644 index 0000000000..7916e8545b Binary files /dev/null and b/ThirdParty/Ert-windows/geometry/lib/libgeometry.dll differ diff --git a/ThirdParty/Ert-windows/geometry/lib/libgeometry.dll.a b/ThirdParty/Ert-windows/geometry/lib/libgeometry.dll.a new file mode 100644 index 0000000000..4bf41c8767 Binary files /dev/null and b/ThirdParty/Ert-windows/geometry/lib/libgeometry.dll.a differ diff --git a/ThirdParty/Ert-windows/geometry/lib/libgeometry.lib b/ThirdParty/Ert-windows/geometry/lib/libgeometry.lib new file mode 100644 index 0000000000..08ce62e10b Binary files /dev/null and b/ThirdParty/Ert-windows/geometry/lib/libgeometry.lib differ diff --git a/ThirdParty/Ert-windows/util/include/arg_pack.h b/ThirdParty/Ert-windows/util/include/arg_pack.h new file mode 100644 index 0000000000..a92a5ae913 --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/arg_pack.h @@ -0,0 +1,91 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'arg_pack.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __ARG_PACK_H__ +#define __ARG_PACK_H__ +#ifdef __cplusplus +extern "C" { +#endif +#include +#include + +#include +#include + +typedef struct arg_pack_struct arg_pack_type; +typedef void (arg_node_free_ftype) (void *); +typedef void * (arg_node_copyc_ftype) (void *); + + arg_pack_type * arg_pack_alloc(); + UTIL_SAFE_CAST_HEADER( arg_pack ); + + void arg_pack_free(arg_pack_type * ); + void arg_pack_free__(void *); + void arg_pack_clear(arg_pack_type *); + void arg_pack_lock(arg_pack_type *); + void arg_pack_fscanf(arg_pack_type * arg , FILE * stream); + void arg_pack_fprintf(const arg_pack_type * , FILE * ); + + void arg_pack_append_ptr(arg_pack_type * , const void *); + void arg_pack_append_owned_ptr(arg_pack_type * , void * , arg_node_free_ftype *); + void arg_pack_append_copy(arg_pack_type * , void * , arg_node_copyc_ftype * , arg_node_free_ftype *); + + void arg_pack_iset_copy(arg_pack_type * arg_pack , int index , void * ptr, arg_node_copyc_ftype * copyc , arg_node_free_ftype * freef); + void arg_pack_iset_ptr(arg_pack_type * arg_pack, int index , const void * ptr); + void arg_pack_iset_owned_ptr(arg_pack_type * arg_pack, int index , void * ptr, arg_node_free_ftype * freef); + + void * arg_pack_iget_ptr(const arg_pack_type * , int); + void * arg_pack_iget_adress(const arg_pack_type * , int); + node_ctype arg_pack_iget_ctype(const arg_pack_type * arg_pack ,int index); + + /*****************************************************************/ + +#define APPEND_TYPED_HEADER(type) void arg_pack_append_ ## type (arg_pack_type * , type); +#define IGET_TYPED_HEADER(type) type arg_pack_iget_ ## type( const arg_pack_type * , int ); +#define ISET_TYPED_HEADER(type) void arg_pack_iset_ ## type( arg_pack_type * , int , type value); + +APPEND_TYPED_HEADER(int) +APPEND_TYPED_HEADER(bool) +APPEND_TYPED_HEADER(char) +APPEND_TYPED_HEADER(float) +APPEND_TYPED_HEADER(double) +APPEND_TYPED_HEADER(size_t) + +IGET_TYPED_HEADER(int) +IGET_TYPED_HEADER(bool) +IGET_TYPED_HEADER(char) +IGET_TYPED_HEADER(float) +IGET_TYPED_HEADER(double) +IGET_TYPED_HEADER(size_t) + +ISET_TYPED_HEADER(int) +ISET_TYPED_HEADER(bool) +ISET_TYPED_HEADER(char) +ISET_TYPED_HEADER(float) +ISET_TYPED_HEADER(double) +ISET_TYPED_HEADER(size_t) + +#undef APPEND_TYPED_HEADER +#undef GET_TYPED_HEADER + + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/ThirdParty/Ert-windows/util/include/bool_vector.h b/ThirdParty/Ert-windows/util/include/bool_vector.h new file mode 100644 index 0000000000..210184d2fa --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/bool_vector.h @@ -0,0 +1,116 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'vector_template.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __bool_VECTOR_H__ +#define __bool_VECTOR_H__ +#ifdef __cplusplus +extern "C" { +#endif +#include + +#include +#include + +typedef struct bool_vector_struct bool_vector_type; +typedef bool (bool_ftype) (bool); + + + int bool_vector_lookup_bin( const bool_vector_type * limits , bool value , int guess); + int bool_vector_lookup_bin__( const bool_vector_type * limits , bool value , int guess); + void bool_vector_inplace_div( bool_vector_type * vector , const bool_vector_type * inv_factor); + void bool_vector_inplace_mul( bool_vector_type * vector , const bool_vector_type * factor); + void bool_vector_inplace_add( bool_vector_type * vector , const bool_vector_type * delta); + void bool_vector_set_read_only( bool_vector_type * vector , bool read_only); + bool bool_vector_get_read_only( const bool_vector_type * vector ); + void bool_vector_resize( bool_vector_type * vector , int new_alloc_size ); + void bool_vector_memcpy( bool_vector_type * target , const bool_vector_type * src); + void bool_vector_memcpy_data_block( bool_vector_type * target , const bool_vector_type * src , int target_offset , int src_offset , int len); + bool bool_vector_growable( const bool_vector_type * vector); + void bool_vector_select_unique(bool_vector_type * vector); + bool_vector_type * bool_vector_alloc( int init_size , bool ); + bool_vector_type * bool_vector_alloc_private_wrapper(int init_size, bool default_value , bool * data , int alloc_size); + bool_vector_type * bool_vector_alloc_shared_wrapper(int init_size, bool default_value , bool * data , int alloc_size); + bool_vector_type * bool_vector_alloc_strided_copy( const bool_vector_type * src , int start , int stop , int stride ); + bool_vector_type * bool_vector_alloc_copy( const bool_vector_type * src); + void bool_vector_imul(bool_vector_type * vector, int index, bool factor); + void bool_vector_scale(bool_vector_type * vector, bool factor); + bool bool_vector_iget(const bool_vector_type * , int); + bool bool_vector_safe_iget(const bool_vector_type * , int); + bool bool_vector_get_min(const bool_vector_type * vector); + bool bool_vector_get_max(const bool_vector_type * vector); + int bool_vector_get_min_index(const bool_vector_type * vector, bool reverse); + int bool_vector_get_max_index(const bool_vector_type * vector, bool reverse); + bool bool_vector_iadd( bool_vector_type * vector , int index , bool delta); + void bool_vector_iset(bool_vector_type * , int , bool); + void bool_vector_idel_block( bool_vector_type * vector , int index , int block_size); + bool bool_vector_idel( bool_vector_type * vector , int index); + void bool_vector_append(bool_vector_type * , bool); + void bool_vector_free(bool_vector_type *); + void bool_vector_free__(void *); + void bool_vector_free_data(bool_vector_type *); + void bool_vector_reset(bool_vector_type *); + void bool_vector_reset__(void * __vector); + int bool_vector_size(const bool_vector_type * ); + bool bool_vector_pop(bool_vector_type * vector); + bool bool_vector_get_first(const bool_vector_type * vector); + bool bool_vector_get_last(const bool_vector_type * ); + bool * bool_vector_get_ptr(const bool_vector_type * ); + bool * bool_vector_alloc_data_copy( const bool_vector_type * vector ); + const bool * bool_vector_get_const_ptr(const bool_vector_type * ); + void bool_vector_set_many(bool_vector_type * , int , const bool * , int ); + void bool_vector_set_all(bool_vector_type * vector , bool value); + void bool_vector_append_many(bool_vector_type * vector , const bool * data , int length); + void bool_vector_shrink(bool_vector_type * ); + bool bool_vector_sum(const bool_vector_type * ); + bool bool_vector_get_default(const bool_vector_type * ); + void bool_vector_set_default(bool_vector_type * vector, bool default_value); + void bool_vector_append_default(bool_vector_type * vector , bool default_value); + void bool_vector_iset_default(bool_vector_type * vector , int index , bool default_value); + bool bool_vector_is_sorted( const bool_vector_type * vector , bool reverse); + int bool_vector_index(const bool_vector_type * vector , bool value); + int bool_vector_index_sorted(const bool_vector_type * vector , bool value); + void bool_vector_sort(bool_vector_type * vector); + void bool_vector_rsort(bool_vector_type * vector); + void bool_vector_permute(bool_vector_type * vector , const int * perm); + int * bool_vector_alloc_sort_perm(const bool_vector_type * vector); + int * bool_vector_alloc_rsort_perm(const bool_vector_type * vector); + void bool_vector_fprintf(const bool_vector_type * vector , FILE * stream , const char * name , const char * fmt); + void bool_vector_fwrite(const bool_vector_type * vector , FILE * stream); + void bool_vector_buffer_fread(bool_vector_type * vector , buffer_type * buffer); + bool_vector_type * bool_vector_fread_alloc( FILE * stream ); + bool_vector_type * bool_vector_buffer_fread_alloc( buffer_type * buffer ); + void bool_vector_buffer_fwrite(const bool_vector_type * vector , buffer_type * buffer); + void bool_vector_fread( bool_vector_type * vector , FILE * stream ); + void bool_vector_fwrite_data( const bool_vector_type * vector , FILE * stream ); + void bool_vector_fread_data( bool_vector_type * vector , int size, FILE * stream); + bool bool_vector_equal(const bool_vector_type * vector1 , const bool_vector_type * vector2); + void bool_vector_apply(bool_vector_type * vector , bool_ftype *func); + int bool_vector_count_equal( const bool_vector_type * vector , bool cmp_value); + int bool_vector_element_size( const bool_vector_type * vector ); + + UTIL_SAFE_CAST_HEADER( bool_vector ); + +#ifdef __cplusplus +} +#endif +#endif +// + + + + diff --git a/ThirdParty/Ert-windows/util/include/buffer.h b/ThirdParty/Ert-windows/util/include/buffer.h new file mode 100644 index 0000000000..afc1ab9bbe --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/buffer.h @@ -0,0 +1,97 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'buffer.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __BUFFER_H__ +#define __BUFFER_H__ + +#ifdef __cplusplus +extern "C" { +#endif +#include +#include +#include +#include +#include + +#include + +typedef struct buffer_struct buffer_type; + +bool buffer_replace( buffer_type * buffer , const char * old_string , const char * new_string); +void buffer_shrink_to_fit( buffer_type * buffer ); +void buffer_memshift(buffer_type * buffer , size_t offset, ssize_t shift); +bool buffer_strstr( buffer_type * buffer , const char * expr ); +bool buffer_strchr( buffer_type * buffer , int c); +buffer_type * buffer_alloc( size_t buffer_size ); +buffer_type * buffer_alloc_private_wrapper(void * data , size_t buffer_size ); +void buffer_free_container( buffer_type * buffer ); +void buffer_free( buffer_type * buffer); +size_t buffer_safe_fread(buffer_type * buffer , void * target_ptr , size_t item_size , size_t items); +size_t buffer_fread(buffer_type * buffer , void * target_ptr , size_t item_size , size_t items); +size_t buffer_safe_fwrite(buffer_type * buffer , const void * src_ptr , size_t item_size , size_t items); +size_t buffer_fwrite(buffer_type * buffer , const void * src_ptr , size_t item_size , size_t items); +const char * buffer_fread_string(buffer_type * buffer); +char * buffer_fread_alloc_string(buffer_type * buffer); +void buffer_fwrite_string(buffer_type * buffer , const char * string); +void buffer_summarize(const buffer_type * buffer , const char *); + +void buffer_fwrite_char_ptr(buffer_type * buffer , const char * string_ptr ); +void buffer_terminate_char_ptr( buffer_type * buffer ); +void buffer_fwrite_char(buffer_type * buffer , char value); +void buffer_fwrite_int(buffer_type * buffer , int value); +void buffer_fskip_bool(buffer_type * buffer); +void buffer_fwrite_bool(buffer_type * buffer , bool value); +int buffer_fread_int(buffer_type * buffer ); +bool buffer_fread_bool(buffer_type * buffer); +long int buffer_fread_long(buffer_type * buffer); +void buffer_store(const buffer_type * buffer , const char * filename); +size_t buffer_get_offset(const buffer_type * buffer); +size_t buffer_get_alloc_size(const buffer_type * buffer); +size_t buffer_get_size(const buffer_type * buffer); +size_t buffer_get_remaining_size(const buffer_type * buffer); +void * buffer_get_data(const buffer_type * buffer); +void * buffer_alloc_data_copy(const buffer_type * buffer); +void buffer_stream_fwrite( const buffer_type * buffer , FILE * stream ); +int buffer_fgetc( buffer_type * buffer ); +void buffer_fseek(buffer_type * buffer , ssize_t offset , int whence); +void buffer_fskip(buffer_type * buffer, ssize_t offset); +void buffer_clear( buffer_type * buffer ); + +void buffer_fskip_int(buffer_type * buffer); +void buffer_fskip_time_t(buffer_type * buffer); +time_t buffer_fread_time_t(buffer_type * buffer); +void buffer_fwrite_time_t(buffer_type * buffer , time_t value); +void buffer_rewind(buffer_type * buffer ); + +double buffer_fread_double(buffer_type * buffer); +void buffer_fwrite_double(buffer_type * buffer , double value); + +size_t buffer_stream_fwrite_n( const buffer_type * buffer , size_t offset , ssize_t write_size , FILE * stream ); +void buffer_stream_fprintf( const buffer_type * buffer , FILE * stream ); +void buffer_stream_fread( buffer_type * buffer , size_t byte_size , FILE * stream); +buffer_type * buffer_fread_alloc(const char * filename); +void buffer_fread_realloc(buffer_type * buffer , const char * filename); +#ifdef HAVE_ZLIB +size_t buffer_fwrite_compressed(buffer_type * buffer, const void * ptr , size_t byte_size); +size_t buffer_fread_compressed(buffer_type * buffer , size_t compressed_size , void * target_ptr , size_t target_size); +#endif +#ifdef __cplusplus +} +#endif + +#endif diff --git a/ThirdParty/Ert-windows/util/include/double_vector.h b/ThirdParty/Ert-windows/util/include/double_vector.h new file mode 100644 index 0000000000..71c952fe4b --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/double_vector.h @@ -0,0 +1,116 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'vector_template.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __double_VECTOR_H__ +#define __double_VECTOR_H__ +#ifdef __cplusplus +extern "C" { +#endif +#include + +#include +#include + +typedef struct double_vector_struct double_vector_type; +typedef double (double_ftype) (double); + + + int double_vector_lookup_bin( const double_vector_type * limits , double value , int guess); + int double_vector_lookup_bin__( const double_vector_type * limits , double value , int guess); + void double_vector_inplace_div( double_vector_type * vector , const double_vector_type * inv_factor); + void double_vector_inplace_mul( double_vector_type * vector , const double_vector_type * factor); + void double_vector_inplace_add( double_vector_type * vector , const double_vector_type * delta); + void double_vector_set_read_only( double_vector_type * vector , bool read_only); + bool double_vector_get_read_only( const double_vector_type * vector ); + void double_vector_resize( double_vector_type * vector , int new_alloc_size ); + void double_vector_memcpy( double_vector_type * target , const double_vector_type * src); + void double_vector_memcpy_data_block( double_vector_type * target , const double_vector_type * src , int target_offset , int src_offset , int len); + bool double_vector_growable( const double_vector_type * vector); + void double_vector_select_unique(double_vector_type * vector); + double_vector_type * double_vector_alloc( int init_size , double ); + double_vector_type * double_vector_alloc_private_wrapper(int init_size, double default_value , double * data , int alloc_size); + double_vector_type * double_vector_alloc_shared_wrapper(int init_size, double default_value , double * data , int alloc_size); + double_vector_type * double_vector_alloc_strided_copy( const double_vector_type * src , int start , int stop , int stride ); + double_vector_type * double_vector_alloc_copy( const double_vector_type * src); + void double_vector_imul(double_vector_type * vector, int index, double factor); + void double_vector_scale(double_vector_type * vector, double factor); + double double_vector_iget(const double_vector_type * , int); + double double_vector_safe_iget(const double_vector_type * , int); + double double_vector_get_min(const double_vector_type * vector); + double double_vector_get_max(const double_vector_type * vector); + int double_vector_get_min_index(const double_vector_type * vector, bool reverse); + int double_vector_get_max_index(const double_vector_type * vector, bool reverse); + double double_vector_iadd( double_vector_type * vector , int index , double delta); + void double_vector_iset(double_vector_type * , int , double); + void double_vector_idel_block( double_vector_type * vector , int index , int block_size); + double double_vector_idel( double_vector_type * vector , int index); + void double_vector_append(double_vector_type * , double); + void double_vector_free(double_vector_type *); + void double_vector_free__(void *); + void double_vector_free_data(double_vector_type *); + void double_vector_reset(double_vector_type *); + void double_vector_reset__(void * __vector); + int double_vector_size(const double_vector_type * ); + double double_vector_pop(double_vector_type * vector); + double double_vector_get_first(const double_vector_type * vector); + double double_vector_get_last(const double_vector_type * ); + double * double_vector_get_ptr(const double_vector_type * ); + double * double_vector_alloc_data_copy( const double_vector_type * vector ); + const double * double_vector_get_const_ptr(const double_vector_type * ); + void double_vector_set_many(double_vector_type * , int , const double * , int ); + void double_vector_set_all(double_vector_type * vector , double value); + void double_vector_append_many(double_vector_type * vector , const double * data , int length); + void double_vector_shrink(double_vector_type * ); + double double_vector_sum(const double_vector_type * ); + double double_vector_get_default(const double_vector_type * ); + void double_vector_set_default(double_vector_type * vector, double default_value); + void double_vector_append_default(double_vector_type * vector , double default_value); + void double_vector_iset_default(double_vector_type * vector , int index , double default_value); + bool double_vector_is_sorted( const double_vector_type * vector , bool reverse); + int double_vector_index(const double_vector_type * vector , double value); + int double_vector_index_sorted(const double_vector_type * vector , double value); + void double_vector_sort(double_vector_type * vector); + void double_vector_rsort(double_vector_type * vector); + void double_vector_permute(double_vector_type * vector , const int * perm); + int * double_vector_alloc_sort_perm(const double_vector_type * vector); + int * double_vector_alloc_rsort_perm(const double_vector_type * vector); + void double_vector_fprintf(const double_vector_type * vector , FILE * stream , const char * name , const char * fmt); + void double_vector_fwrite(const double_vector_type * vector , FILE * stream); + void double_vector_buffer_fread(double_vector_type * vector , buffer_type * buffer); + double_vector_type * double_vector_fread_alloc( FILE * stream ); + double_vector_type * double_vector_buffer_fread_alloc( buffer_type * buffer ); + void double_vector_buffer_fwrite(const double_vector_type * vector , buffer_type * buffer); + void double_vector_fread( double_vector_type * vector , FILE * stream ); + void double_vector_fwrite_data( const double_vector_type * vector , FILE * stream ); + void double_vector_fread_data( double_vector_type * vector , int size, FILE * stream); + bool double_vector_equal(const double_vector_type * vector1 , const double_vector_type * vector2); + void double_vector_apply(double_vector_type * vector , double_ftype *func); + int double_vector_count_equal( const double_vector_type * vector , double cmp_value); + int double_vector_element_size( const double_vector_type * vector ); + + UTIL_SAFE_CAST_HEADER( double_vector ); + +#ifdef __cplusplus +} +#endif +#endif +// + + + + diff --git a/ThirdParty/Ert-windows/util/include/float_vector.h b/ThirdParty/Ert-windows/util/include/float_vector.h new file mode 100644 index 0000000000..3cdaac81c7 --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/float_vector.h @@ -0,0 +1,116 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'vector_template.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __float_VECTOR_H__ +#define __float_VECTOR_H__ +#ifdef __cplusplus +extern "C" { +#endif +#include + +#include +#include + +typedef struct float_vector_struct float_vector_type; +typedef float (float_ftype) (float); + + + int float_vector_lookup_bin( const float_vector_type * limits , float value , int guess); + int float_vector_lookup_bin__( const float_vector_type * limits , float value , int guess); + void float_vector_inplace_div( float_vector_type * vector , const float_vector_type * inv_factor); + void float_vector_inplace_mul( float_vector_type * vector , const float_vector_type * factor); + void float_vector_inplace_add( float_vector_type * vector , const float_vector_type * delta); + void float_vector_set_read_only( float_vector_type * vector , bool read_only); + bool float_vector_get_read_only( const float_vector_type * vector ); + void float_vector_resize( float_vector_type * vector , int new_alloc_size ); + void float_vector_memcpy( float_vector_type * target , const float_vector_type * src); + void float_vector_memcpy_data_block( float_vector_type * target , const float_vector_type * src , int target_offset , int src_offset , int len); + bool float_vector_growable( const float_vector_type * vector); + void float_vector_select_unique(float_vector_type * vector); + float_vector_type * float_vector_alloc( int init_size , float ); + float_vector_type * float_vector_alloc_private_wrapper(int init_size, float default_value , float * data , int alloc_size); + float_vector_type * float_vector_alloc_shared_wrapper(int init_size, float default_value , float * data , int alloc_size); + float_vector_type * float_vector_alloc_strided_copy( const float_vector_type * src , int start , int stop , int stride ); + float_vector_type * float_vector_alloc_copy( const float_vector_type * src); + void float_vector_imul(float_vector_type * vector, int index, float factor); + void float_vector_scale(float_vector_type * vector, float factor); + float float_vector_iget(const float_vector_type * , int); + float float_vector_safe_iget(const float_vector_type * , int); + float float_vector_get_min(const float_vector_type * vector); + float float_vector_get_max(const float_vector_type * vector); + int float_vector_get_min_index(const float_vector_type * vector, bool reverse); + int float_vector_get_max_index(const float_vector_type * vector, bool reverse); + float float_vector_iadd( float_vector_type * vector , int index , float delta); + void float_vector_iset(float_vector_type * , int , float); + void float_vector_idel_block( float_vector_type * vector , int index , int block_size); + float float_vector_idel( float_vector_type * vector , int index); + void float_vector_append(float_vector_type * , float); + void float_vector_free(float_vector_type *); + void float_vector_free__(void *); + void float_vector_free_data(float_vector_type *); + void float_vector_reset(float_vector_type *); + void float_vector_reset__(void * __vector); + int float_vector_size(const float_vector_type * ); + float float_vector_pop(float_vector_type * vector); + float float_vector_get_first(const float_vector_type * vector); + float float_vector_get_last(const float_vector_type * ); + float * float_vector_get_ptr(const float_vector_type * ); + float * float_vector_alloc_data_copy( const float_vector_type * vector ); + const float * float_vector_get_const_ptr(const float_vector_type * ); + void float_vector_set_many(float_vector_type * , int , const float * , int ); + void float_vector_set_all(float_vector_type * vector , float value); + void float_vector_append_many(float_vector_type * vector , const float * data , int length); + void float_vector_shrink(float_vector_type * ); + float float_vector_sum(const float_vector_type * ); + float float_vector_get_default(const float_vector_type * ); + void float_vector_set_default(float_vector_type * vector, float default_value); + void float_vector_append_default(float_vector_type * vector , float default_value); + void float_vector_iset_default(float_vector_type * vector , int index , float default_value); + bool float_vector_is_sorted( const float_vector_type * vector , bool reverse); + int float_vector_index(const float_vector_type * vector , float value); + int float_vector_index_sorted(const float_vector_type * vector , float value); + void float_vector_sort(float_vector_type * vector); + void float_vector_rsort(float_vector_type * vector); + void float_vector_permute(float_vector_type * vector , const int * perm); + int * float_vector_alloc_sort_perm(const float_vector_type * vector); + int * float_vector_alloc_rsort_perm(const float_vector_type * vector); + void float_vector_fprintf(const float_vector_type * vector , FILE * stream , const char * name , const char * fmt); + void float_vector_fwrite(const float_vector_type * vector , FILE * stream); + void float_vector_buffer_fread(float_vector_type * vector , buffer_type * buffer); + float_vector_type * float_vector_fread_alloc( FILE * stream ); + float_vector_type * float_vector_buffer_fread_alloc( buffer_type * buffer ); + void float_vector_buffer_fwrite(const float_vector_type * vector , buffer_type * buffer); + void float_vector_fread( float_vector_type * vector , FILE * stream ); + void float_vector_fwrite_data( const float_vector_type * vector , FILE * stream ); + void float_vector_fread_data( float_vector_type * vector , int size, FILE * stream); + bool float_vector_equal(const float_vector_type * vector1 , const float_vector_type * vector2); + void float_vector_apply(float_vector_type * vector , float_ftype *func); + int float_vector_count_equal( const float_vector_type * vector , float cmp_value); + int float_vector_element_size( const float_vector_type * vector ); + + UTIL_SAFE_CAST_HEADER( float_vector ); + +#ifdef __cplusplus +} +#endif +#endif +// + + + + diff --git a/ThirdParty/Ert-windows/util/include/hash.h b/ThirdParty/Ert-windows/util/include/hash.h new file mode 100644 index 0000000000..6f185c23cc --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/hash.h @@ -0,0 +1,85 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'hash.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __HASH_H__ +#define __HASH_H__ +#ifdef __cplusplus +extern"C" { +#endif + +#include +#include +#include +typedef struct hash_struct hash_type; +typedef struct hash_iter_struct hash_iter_type; +typedef void (hash_apply_ftype) (void * ); +#include + +void hash_lock (hash_type * ); +void hash_unlock(hash_type * ); +hash_type * hash_alloc(); +hash_type * hash_alloc_unlocked(); +hash_type * hash_safe_cast( void * arg); +void hash_iter_complete(hash_type * ); +void hash_free(hash_type *); +void hash_free__(void *); +void hash_insert_ref(hash_type * , const char * , const void *); +void hash_insert_copy(hash_type *, const char * , const void *, copyc_ftype *, free_ftype *); +void hash_insert_string(hash_type *, const char *, const char *); +bool hash_has_key(const hash_type *, const char *); +void * hash_pop( hash_type * hash , const char * key); +void * hash_safe_get( const hash_type * hash , const char * key ); +void * hash_get(const hash_type *, const char *); +char * hash_get_string(hash_type * , const char *); +void hash_del(hash_type *, const char *); +void hash_safe_del(hash_type * , const char * ); +void hash_clear(hash_type *); +int hash_get_size(const hash_type *); +void hash_set_keylist(const hash_type * , char **); +char ** hash_alloc_keylist(hash_type *); +stringlist_type * hash_alloc_stringlist(hash_type * ); + +char ** hash_alloc_sorted_keylist (hash_type *hash , int ( hash_get_cmp_value ) (const void *)); +char ** hash_alloc_key_sorted_list(hash_type *hash, int (*cmp)(const void *, const void *)); +bool hash_key_list_compare( hash_type * hash1, hash_type * hash2); +void hash_insert_hash_owned_ref(hash_type *, const char * , const void *, free_ftype *); +void hash_resize(hash_type *hash, int new_size); + +hash_iter_type * hash_iter_alloc(const hash_type *); +void hash_iter_free(hash_iter_type *); +bool hash_iter_is_complete(const hash_iter_type *); +const char * hash_iter_get_next_key(hash_iter_type *); +void * hash_iter_get_next_value(hash_iter_type *); +void hash_iter_restart( hash_iter_type * iter ); + +hash_type * hash_alloc_from_options(const stringlist_type *); + +int hash_inc_counter(hash_type * hash , const char * counter_key); +int hash_get_counter(hash_type * hash , const char * key); +void hash_insert_int(hash_type * , const char * , int); +int hash_get_int(hash_type * , const char *); +void hash_insert_double(hash_type * , const char * , double); +double hash_get_double(hash_type * , const char *); +void hash_apply( hash_type * hash , hash_apply_ftype * func); + +UTIL_IS_INSTANCE_HEADER(hash); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/util/include/hash_node.h b/ThirdParty/Ert-windows/util/include/hash_node.h new file mode 100644 index 0000000000..bd66eadd20 --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/hash_node.h @@ -0,0 +1,49 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'hash_node.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __HASH_NODE_H__ +#define __HASH_NODE_H__ +#ifdef __cplusplus +extern "C" { +#endif +#include +#include + +#include + +typedef struct hash_node_struct hash_node_type; +typedef uint32_t (hashf_type) (const char *key, size_t len); +typedef enum {hash_ref_data , hash_int_data , hash_double_data , hash_string_data} hash_data_type; + + +bool hash_node_key_eq(const hash_node_type * , uint32_t , const char *); +hash_node_type * hash_node_get_next(const hash_node_type * ); +uint32_t hash_node_get_insert_nr(const hash_node_type * ); +void hash_node_set_next(hash_node_type * , const hash_node_type * ); +hash_node_type * hash_node_alloc_new(const char *, node_data_type * , hashf_type *, uint32_t); +void hash_node_set_insert_nr(hash_node_type *, uint32_t ); +uint32_t hash_node_get_table_index(const hash_node_type * ); +uint32_t hash_node_get_global_index(const hash_node_type * ); +const char * hash_node_get_key(const hash_node_type * ); +node_data_type * hash_node_get_data(const hash_node_type *); +void hash_node_free(hash_node_type *); +uint32_t hash_node_set_table_index(hash_node_type *, uint32_t ); +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/util/include/hash_sll.h b/ThirdParty/Ert-windows/util/include/hash_sll.h new file mode 100644 index 0000000000..3154367013 --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/hash_sll.h @@ -0,0 +1,41 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'hash_sll.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __HASH_SLL_H__ +#define __HASH_SLL_H__ +#ifdef __cplusplus +extern "C" { +#endif + +#include + +typedef struct hash_sll_struct hash_sll_type; + +hash_sll_type **hash_sll_alloc_table(int ); +/*hash_sll_type * hash_sll_alloc(void);*/ +void hash_sll_del_node(hash_sll_type * , hash_node_type *); +void hash_sll_add_node(hash_sll_type *, hash_node_type *); +void hash_sll_free(hash_sll_type *); +bool hash_sll_has_key(const hash_sll_type *, uint32_t , const char *); +bool hash_sll_empty(const hash_sll_type * hash_sll); +hash_node_type * hash_sll_get(const hash_sll_type *, uint32_t , const char *); +hash_node_type * hash_sll_get_head(const hash_sll_type *); +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/util/include/int_vector.h b/ThirdParty/Ert-windows/util/include/int_vector.h new file mode 100644 index 0000000000..2d3b0d1c2d --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/int_vector.h @@ -0,0 +1,116 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'vector_template.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __int_VECTOR_H__ +#define __int_VECTOR_H__ +#ifdef __cplusplus +extern "C" { +#endif +#include + +#include +#include + +typedef struct int_vector_struct int_vector_type; +typedef int (int_ftype) (int); + + + int int_vector_lookup_bin( const int_vector_type * limits , int value , int guess); + int int_vector_lookup_bin__( const int_vector_type * limits , int value , int guess); + void int_vector_inplace_div( int_vector_type * vector , const int_vector_type * inv_factor); + void int_vector_inplace_mul( int_vector_type * vector , const int_vector_type * factor); + void int_vector_inplace_add( int_vector_type * vector , const int_vector_type * delta); + void int_vector_set_read_only( int_vector_type * vector , bool read_only); + bool int_vector_get_read_only( const int_vector_type * vector ); + void int_vector_resize( int_vector_type * vector , int new_alloc_size ); + void int_vector_memcpy( int_vector_type * target , const int_vector_type * src); + void int_vector_memcpy_data_block( int_vector_type * target , const int_vector_type * src , int target_offset , int src_offset , int len); + bool int_vector_growable( const int_vector_type * vector); + void int_vector_select_unique(int_vector_type * vector); + int_vector_type * int_vector_alloc( int init_size , int ); + int_vector_type * int_vector_alloc_private_wrapper(int init_size, int default_value , int * data , int alloc_size); + int_vector_type * int_vector_alloc_shared_wrapper(int init_size, int default_value , int * data , int alloc_size); + int_vector_type * int_vector_alloc_strided_copy( const int_vector_type * src , int start , int stop , int stride ); + int_vector_type * int_vector_alloc_copy( const int_vector_type * src); + void int_vector_imul(int_vector_type * vector, int index, int factor); + void int_vector_scale(int_vector_type * vector, int factor); + int int_vector_iget(const int_vector_type * , int); + int int_vector_safe_iget(const int_vector_type * , int); + int int_vector_get_min(const int_vector_type * vector); + int int_vector_get_max(const int_vector_type * vector); + int int_vector_get_min_index(const int_vector_type * vector, bool reverse); + int int_vector_get_max_index(const int_vector_type * vector, bool reverse); + int int_vector_iadd( int_vector_type * vector , int index , int delta); + void int_vector_iset(int_vector_type * , int , int); + void int_vector_idel_block( int_vector_type * vector , int index , int block_size); + int int_vector_idel( int_vector_type * vector , int index); + void int_vector_append(int_vector_type * , int); + void int_vector_free(int_vector_type *); + void int_vector_free__(void *); + void int_vector_free_data(int_vector_type *); + void int_vector_reset(int_vector_type *); + void int_vector_reset__(void * __vector); + int int_vector_size(const int_vector_type * ); + int int_vector_pop(int_vector_type * vector); + int int_vector_get_first(const int_vector_type * vector); + int int_vector_get_last(const int_vector_type * ); + int * int_vector_get_ptr(const int_vector_type * ); + int * int_vector_alloc_data_copy( const int_vector_type * vector ); + const int * int_vector_get_const_ptr(const int_vector_type * ); + void int_vector_set_many(int_vector_type * , int , const int * , int ); + void int_vector_set_all(int_vector_type * vector , int value); + void int_vector_append_many(int_vector_type * vector , const int * data , int length); + void int_vector_shrink(int_vector_type * ); + int int_vector_sum(const int_vector_type * ); + int int_vector_get_default(const int_vector_type * ); + void int_vector_set_default(int_vector_type * vector, int default_value); + void int_vector_append_default(int_vector_type * vector , int default_value); + void int_vector_iset_default(int_vector_type * vector , int index , int default_value); + bool int_vector_is_sorted( const int_vector_type * vector , bool reverse); + int int_vector_index(const int_vector_type * vector , int value); + int int_vector_index_sorted(const int_vector_type * vector , int value); + void int_vector_sort(int_vector_type * vector); + void int_vector_rsort(int_vector_type * vector); + void int_vector_permute(int_vector_type * vector , const int * perm); + int * int_vector_alloc_sort_perm(const int_vector_type * vector); + int * int_vector_alloc_rsort_perm(const int_vector_type * vector); + void int_vector_fprintf(const int_vector_type * vector , FILE * stream , const char * name , const char * fmt); + void int_vector_fwrite(const int_vector_type * vector , FILE * stream); + void int_vector_buffer_fread(int_vector_type * vector , buffer_type * buffer); + int_vector_type * int_vector_fread_alloc( FILE * stream ); + int_vector_type * int_vector_buffer_fread_alloc( buffer_type * buffer ); + void int_vector_buffer_fwrite(const int_vector_type * vector , buffer_type * buffer); + void int_vector_fread( int_vector_type * vector , FILE * stream ); + void int_vector_fwrite_data( const int_vector_type * vector , FILE * stream ); + void int_vector_fread_data( int_vector_type * vector , int size, FILE * stream); + bool int_vector_equal(const int_vector_type * vector1 , const int_vector_type * vector2); + void int_vector_apply(int_vector_type * vector , int_ftype *func); + int int_vector_count_equal( const int_vector_type * vector , int cmp_value); + int int_vector_element_size( const int_vector_type * vector ); + + UTIL_SAFE_CAST_HEADER( int_vector ); + +#ifdef __cplusplus +} +#endif +#endif +// + + + + diff --git a/ThirdParty/Ert-windows/util/include/lars.h b/ThirdParty/Ert-windows/util/include/lars.h new file mode 100644 index 0000000000..80ec223cf1 --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/lars.h @@ -0,0 +1,49 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'lars.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#ifndef __LARS_H__ +#define __LARS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +typedef struct lars_struct lars_type; + +int lars_get_sample( const lars_type * lars ); +int lars_get_nvar( const lars_type * lars ); +lars_type * lars_alloc1( int nsample , int nvars); +lars_type * lars_alloc2( matrix_type * X , matrix_type * Y , bool internal_copy ); +void lars_estimate(lars_type * lars , int max_vars , double max_beta , bool verbose); +void lars_isetX( lars_type * lars, int sample, int var , double value); +void lars_isetY( lars_type * lars, int sample, double value); +void lars_select_beta( lars_type * lars , int beta_index); +void lars_free( lars_type * lars ); +double lars_eval1( const lars_type * lars , const matrix_type * x); +double lars_eval2( const lars_type * lars , double * x); +double lars_getY0( const lars_type * lars); +double lars_iget_beta( const lars_type * lars , int index); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/util/include/log.h b/ThirdParty/Ert-windows/util/include/log.h new file mode 100644 index 0000000000..f7a8c38ab5 --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/log.h @@ -0,0 +1,50 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'log.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __LOG_H__ +#define __LOG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +typedef struct log_struct log_type; + + FILE * log_get_stream(log_type * logh ); + void log_reset_filename( log_type * logh , const char * filename ); + void log_set_file(log_type * , const char *); + log_type * log_alloc_new(const char *filename, int log_level); + log_type * log_alloc_existing(const char *filename, int log_level); + void log_add_message(log_type *logh, int message_level , FILE * dup_stream , char* message, bool free_message); + void log_add_fmt_message(log_type * logh , int message_level , FILE * dup_stream , const char * fmt , ...); + int log_get_level( const log_type * logh); + void log_set_level( log_type * logh , int new_level); + void log_close( log_type * logh ); + void log_sync(log_type * logh); + const char * log_get_filename( const log_type * logh ); + int log_get_level( const log_type * logh); + void log_set_level( log_type * logh , int log_level); + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/util/include/long_vector.h b/ThirdParty/Ert-windows/util/include/long_vector.h new file mode 100644 index 0000000000..f73757ba84 --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/long_vector.h @@ -0,0 +1,116 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'vector_template.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __long_VECTOR_H__ +#define __long_VECTOR_H__ +#ifdef __cplusplus +extern "C" { +#endif +#include + +#include +#include + +typedef struct long_vector_struct long_vector_type; +typedef long (long_ftype) (long); + + + int long_vector_lookup_bin( const long_vector_type * limits , long value , int guess); + int long_vector_lookup_bin__( const long_vector_type * limits , long value , int guess); + void long_vector_inplace_div( long_vector_type * vector , const long_vector_type * inv_factor); + void long_vector_inplace_mul( long_vector_type * vector , const long_vector_type * factor); + void long_vector_inplace_add( long_vector_type * vector , const long_vector_type * delta); + void long_vector_set_read_only( long_vector_type * vector , bool read_only); + bool long_vector_get_read_only( const long_vector_type * vector ); + void long_vector_resize( long_vector_type * vector , int new_alloc_size ); + void long_vector_memcpy( long_vector_type * target , const long_vector_type * src); + void long_vector_memcpy_data_block( long_vector_type * target , const long_vector_type * src , int target_offset , int src_offset , int len); + bool long_vector_growable( const long_vector_type * vector); + void long_vector_select_unique(long_vector_type * vector); + long_vector_type * long_vector_alloc( int init_size , long ); + long_vector_type * long_vector_alloc_private_wrapper(int init_size, long default_value , long * data , int alloc_size); + long_vector_type * long_vector_alloc_shared_wrapper(int init_size, long default_value , long * data , int alloc_size); + long_vector_type * long_vector_alloc_strided_copy( const long_vector_type * src , int start , int stop , int stride ); + long_vector_type * long_vector_alloc_copy( const long_vector_type * src); + void long_vector_imul(long_vector_type * vector, int index, long factor); + void long_vector_scale(long_vector_type * vector, long factor); + long long_vector_iget(const long_vector_type * , int); + long long_vector_safe_iget(const long_vector_type * , int); + long long_vector_get_min(const long_vector_type * vector); + long long_vector_get_max(const long_vector_type * vector); + int long_vector_get_min_index(const long_vector_type * vector, bool reverse); + int long_vector_get_max_index(const long_vector_type * vector, bool reverse); + long long_vector_iadd( long_vector_type * vector , int index , long delta); + void long_vector_iset(long_vector_type * , int , long); + void long_vector_idel_block( long_vector_type * vector , int index , int block_size); + long long_vector_idel( long_vector_type * vector , int index); + void long_vector_append(long_vector_type * , long); + void long_vector_free(long_vector_type *); + void long_vector_free__(void *); + void long_vector_free_data(long_vector_type *); + void long_vector_reset(long_vector_type *); + void long_vector_reset__(void * __vector); + int long_vector_size(const long_vector_type * ); + long long_vector_pop(long_vector_type * vector); + long long_vector_get_first(const long_vector_type * vector); + long long_vector_get_last(const long_vector_type * ); + long * long_vector_get_ptr(const long_vector_type * ); + long * long_vector_alloc_data_copy( const long_vector_type * vector ); + const long * long_vector_get_const_ptr(const long_vector_type * ); + void long_vector_set_many(long_vector_type * , int , const long * , int ); + void long_vector_set_all(long_vector_type * vector , long value); + void long_vector_append_many(long_vector_type * vector , const long * data , int length); + void long_vector_shrink(long_vector_type * ); + long long_vector_sum(const long_vector_type * ); + long long_vector_get_default(const long_vector_type * ); + void long_vector_set_default(long_vector_type * vector, long default_value); + void long_vector_append_default(long_vector_type * vector , long default_value); + void long_vector_iset_default(long_vector_type * vector , int index , long default_value); + bool long_vector_is_sorted( const long_vector_type * vector , bool reverse); + int long_vector_index(const long_vector_type * vector , long value); + int long_vector_index_sorted(const long_vector_type * vector , long value); + void long_vector_sort(long_vector_type * vector); + void long_vector_rsort(long_vector_type * vector); + void long_vector_permute(long_vector_type * vector , const int * perm); + int * long_vector_alloc_sort_perm(const long_vector_type * vector); + int * long_vector_alloc_rsort_perm(const long_vector_type * vector); + void long_vector_fprintf(const long_vector_type * vector , FILE * stream , const char * name , const char * fmt); + void long_vector_fwrite(const long_vector_type * vector , FILE * stream); + void long_vector_buffer_fread(long_vector_type * vector , buffer_type * buffer); + long_vector_type * long_vector_fread_alloc( FILE * stream ); + long_vector_type * long_vector_buffer_fread_alloc( buffer_type * buffer ); + void long_vector_buffer_fwrite(const long_vector_type * vector , buffer_type * buffer); + void long_vector_fread( long_vector_type * vector , FILE * stream ); + void long_vector_fwrite_data( const long_vector_type * vector , FILE * stream ); + void long_vector_fread_data( long_vector_type * vector , int size, FILE * stream); + bool long_vector_equal(const long_vector_type * vector1 , const long_vector_type * vector2); + void long_vector_apply(long_vector_type * vector , long_ftype *func); + int long_vector_count_equal( const long_vector_type * vector , long cmp_value); + int long_vector_element_size( const long_vector_type * vector ); + + UTIL_SAFE_CAST_HEADER( long_vector ); + +#ifdef __cplusplus +} +#endif +#endif +// + + + + diff --git a/ThirdParty/Ert-windows/util/include/lookup_table.h b/ThirdParty/Ert-windows/util/include/lookup_table.h new file mode 100644 index 0000000000..a7e0b3e0ef --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/lookup_table.h @@ -0,0 +1,46 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'lookup_table.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __LOOKUP_TABLE_H__ +#define __LOOKUP_TABLE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +typedef struct lookup_table_struct lookup_table_type; + + +void lookup_table_set_data( lookup_table_type * lt , double_vector_type * x , double_vector_type * y , bool data_owner ); +lookup_table_type * lookup_table_alloc( double_vector_type * x , double_vector_type * y , bool data_owner); +lookup_table_type * lookup_table_alloc_empty(); +void lookup_table_append( lookup_table_type * lt , double x , double y); +void lookup_table_free( lookup_table_type * lt ); +double lookup_table_interp( lookup_table_type * lt , double x); +double lookup_table_get_max_value( lookup_table_type * lookup_table ); +double lookup_table_get_min_value( lookup_table_type * lookup_table ); +double lookup_table_get_max_arg( lookup_table_type * lookup_table ); +double lookup_table_get_max_arg( lookup_table_type * lookup_table ); +int lookup_table_get_size( const lookup_table_type * lt ); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/util/include/matrix.h b/ThirdParty/Ert-windows/util/include/matrix.h new file mode 100644 index 0000000000..3a913b484e --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/matrix.h @@ -0,0 +1,136 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'matrix.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __MATRIX_H__ +#define __MATRIX_H__ +#include +#include +#include + +#include +#include +#ifdef HAVE_THREAD_POOL +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct matrix_struct matrix_type; + + void matrix_fscanf_data( matrix_type * matrix , bool row_major_order , FILE * stream ); + void matrix_fprintf( const matrix_type * matrix , const char * fmt , FILE * stream ); + void matrix_pretty_fprint(const matrix_type * matrix , const char * name , const char * fmt , FILE * stream); + matrix_type * matrix_alloc(int rows, int columns); + matrix_type * matrix_safe_alloc(int rows, int columns); + bool matrix_resize(matrix_type * matrix , int rows , int columns , bool copy_content); + bool matrix_safe_resize(matrix_type * matrix , int rows , int columns , bool copy_content); + matrix_type * matrix_alloc_copy(const matrix_type * src); + matrix_type * matrix_safe_alloc_copy(const matrix_type * src); + + matrix_type * matrix_alloc_shared(const matrix_type * src , int row , int column , int rows , int columns); + void matrix_free(matrix_type * matrix); + void matrix_safe_free( matrix_type * matrix ); + void matrix_pretty_print(const matrix_type * matrix , const char * name , const char * fmt); + void matrix_set(matrix_type * matrix, double value); + void matrix_set_name( matrix_type * matrix , const char * name); + void matrix_scale(matrix_type * matrix, double value); + void matrix_shift(matrix_type * matrix, double value); + + void matrix_assert_finite( const matrix_type * matrix ); + + void matrix_assign(matrix_type * A , const matrix_type * B); + void matrix_inplace_add(matrix_type * A , const matrix_type * B); + void matrix_inplace_sub(matrix_type * A , const matrix_type * B); + void matrix_inplace_mul(matrix_type * A , const matrix_type * B); + void matrix_inplace_div(matrix_type * A , const matrix_type * B); + void matrix_sub(matrix_type * A , const matrix_type * B , const matrix_type * C); + void matrix_mul( matrix_type * A , const matrix_type * B , const matrix_type * C); + void matrix_transpose(const matrix_type * A , matrix_type * T); + + void matrix_iset_safe(matrix_type * matrix , int i , int j, double value); + void matrix_iset(matrix_type * matrix , int i , int j, double value); + double matrix_iget(const matrix_type * matrix , int i , int j); + double matrix_iget_safe(const matrix_type * matrix , int i , int j); + void matrix_iadd(matrix_type * matrix , int i , int j , double value); + void matrix_isub(matrix_type * matrix , int i , int j , double value); + void matrix_imul(matrix_type * matrix , int i , int j , double value); + + + void matrix_inplace_matmul(matrix_type * A, const matrix_type * B); + void matrix_inplace_matmul_mt1(matrix_type * A, const matrix_type * B , int num_threads); +#ifdef HAVE_THREAD_POOL + void matrix_inplace_matmul_mt2(matrix_type * A, const matrix_type * B , thread_pool_type * thread_pool); +#endif + + void matrix_shift_column(matrix_type * matrix , int column, double shift); + void matrix_shift_row(matrix_type * matrix , int row , double shift); + double matrix_get_column_sum(const matrix_type * matrix , int column); + double matrix_get_row_sum(const matrix_type * matrix , int column); + double matrix_get_column_sum2(const matrix_type * matrix , int column); + double matrix_get_row_abssum(const matrix_type * matrix , int row); + double matrix_get_column_abssum(const matrix_type * matrix , int column); + double matrix_get_row_sum2(const matrix_type * matrix , int column); + void matrix_subtract_row_mean(matrix_type * matrix); + void matrix_subtract_and_store_row_mean(matrix_type * matrix, matrix_type * row_mean); + void matrix_scale_column(matrix_type * matrix , int column , double scale_factor); + void matrix_scale_row(matrix_type * matrix , int row , double scale_factor); + void matrix_set_const_column(matrix_type * matrix , const double value , int column); + void matrix_copy_column(matrix_type * target_matrix, const matrix_type * src_matrix , int src_column, int target_column); + void matrix_set_const_row(matrix_type * matrix , const double value , int row); + + double * matrix_get_data(const matrix_type * matrix); + bool matrix_is_finite(const matrix_type * matrix); + double matrix_orthonormality( const matrix_type * matrix ); + + matrix_type * matrix_alloc_steal_data(int rows , int columns , double * data , int data_size); + void matrix_set_column(matrix_type * matrix , const double * data , int column); + void matrix_set_many_on_column(matrix_type * matrix , int row_offset , int elements , const double * data , int column); + void matrix_ensure_rows(matrix_type * matrix, int rows, bool copy_content); + void matrix_shrink_header(matrix_type * matrix , int rows , int columns); + void matrix_full_size( matrix_type * matrix ); + int matrix_get_rows(const matrix_type * matrix); + int matrix_get_columns(const matrix_type * matrix); + int matrix_get_row_stride(const matrix_type * matrix); + int matrix_get_column_stride(const matrix_type * matrix); + void matrix_get_dims(const matrix_type * matrix , int * rows , int * columns , int * row_stride , int * column_stride); + bool matrix_is_quadratic(const matrix_type * matrix); + bool matrix_equal( const matrix_type * m1 , const matrix_type * m2); + + void matrix_diag_set_scalar(matrix_type * matrix , double value); + void matrix_diag_set(matrix_type * matrix , const double * diag); + void matrix_random_init(matrix_type * matrix , rng_type * rng); + void matrix_matlab_dump(const matrix_type * matrix, const char * filename); + + void matrix_imul_col( matrix_type * matrix , int column , double factor); + double matrix_column_column_dot_product(const matrix_type * m1 , int col1 , const matrix_type * m2 , int col2); + double matrix_row_column_dot_product(const matrix_type * m1 , int row1 , const matrix_type * m2 , int col2); + matrix_type * matrix_alloc_view(double * data , int rows , int columns); + matrix_type * matrix_alloc_transpose( const matrix_type * A); + void matrix_copy_row(matrix_type * target_matrix, const matrix_type * src_matrix , int target_row, int src_row); + void matrix_copy_block( matrix_type * target_matrix , int target_row , int target_column , int rows , int columns, + const matrix_type * src_matrix , int src_row , int src_column); + + void matrix_scalar_set( matrix_type * matrix , double value); + UTIL_SAFE_CAST_HEADER( matrix ); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/util/include/matrix_blas.h b/ThirdParty/Ert-windows/util/include/matrix_blas.h new file mode 100644 index 0000000000..d7d2b82c0b --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/matrix_blas.h @@ -0,0 +1,40 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'matrix_blas.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + + +void matrix_dgemm(matrix_type *C , const matrix_type *A , const matrix_type * B , bool transA, bool transB , double alpha , double beta); +void matrix_matmul(matrix_type * A, const matrix_type *B , const matrix_type * C); +matrix_type * matrix_alloc_matmul(const matrix_type * A, const matrix_type * B); +void matrix_dgemv(const matrix_type * A , const double * x , double * y , bool transA , double alpha , double beta); +void matrix_mul_vector(const matrix_type * A , const double * x , double * y); +void matrix_gram_set( const matrix_type * X , matrix_type * G, bool col); +matrix_type * matrix_alloc_gram( const matrix_type * X , bool col); + + +#ifdef __cplusplus +} +#endif + diff --git a/ThirdParty/Ert-windows/util/include/matrix_lapack.h b/ThirdParty/Ert-windows/util/include/matrix_lapack.h new file mode 100644 index 0000000000..a872e356e8 --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/matrix_lapack.h @@ -0,0 +1,93 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'matrix_lapack.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ +#ifndef __MATRIX_LAPACK_H__ +#define __MATRIX_LAPACK_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + This enum is just a simple way to label the different ways the + singular vectors in U and VT are returned to the calling scope. The + low level lapack routine uses a character variable, indicated + below. +*/ + + + + + + typedef enum { + /* A */ DGESVD_ALL, /* Returns all the singular vectors in U/VT. */ + /* S */ DGESVD_MIN_RETURN, /* Return the first min(m,n) vectors in U/VT. */ + /* O */ DGESVD_MIN_OVERWRITE, /* Return the first min(m,n) vectors of U/VT by overwriteing in A. */ + /* N */ DGESVD_NONE} /* Do not compute any singular vectors for U/VT */ + dgesvd_vector_enum; + + + typedef enum { + /* A */ DSYEVX_ALL, /* Compute all the eigenvalues */ + /* V */ DSYEVX_VALUE_INTERVAL, /* Computes eigenvalues in half open interval + for more details. +*/ + +#ifndef __MENU_H__ +#define __MENU_H__ + +typedef struct menu_struct menu_type; +typedef struct menu_item_struct menu_item_type; + +typedef void (menu_func_type) (void *); +typedef void (arg_free_ftype) (void *); + +menu_type * menu_alloc(const char * , const char * , const char *); +void menu_run(const menu_type * ); +void menu_free(menu_type * ); +menu_item_type * menu_get_item(const menu_type * , char ); +menu_item_type * menu_add_item(menu_type *, const char * , const char * , menu_func_type * , void * , arg_free_ftype * ); +void menu_add_separator(menu_type * ); +menu_item_type * menu_get_item(const menu_type * , char ); +void menu_set_title(menu_type *, const char *); +void menu_item_set_label( menu_item_type * , const char *); + +#endif diff --git a/ThirdParty/Ert-windows/util/include/msg.h b/ThirdParty/Ert-windows/util/include/msg.h new file mode 100644 index 0000000000..9dc5a55858 --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/msg.h @@ -0,0 +1,46 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'msg.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __MSG_H__ +#define __MSG_H__ +#ifdef __cplusplus +extern "C" { +#endif +#include +#include + + +typedef struct msg_struct msg_type; + + + +msg_type * msg_alloc(const char * , bool debug); +void msg_show(msg_type * ); +void msg_free(msg_type * , bool); +void msg_update(msg_type * , const char * ); +void msg_update_int(msg_type * , const char * , int ); +void msg_hide(msg_type *); +void msg_clear_msg(msg_type * msg); + + +UTIL_SAFE_CAST_HEADER( msg ); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/util/include/mzran.h b/ThirdParty/Ert-windows/util/include/mzran.h new file mode 100644 index 0000000000..6af24eac52 --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/mzran.h @@ -0,0 +1,46 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'mzran.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __MZRAN_H__ +#define __MZRAN_H__ + +#ifdef __cplusplus +extern "C" { +#endif +#include +#include + +typedef struct mzran_struct mzran_type; + +#define MZRAN_MAX_VALUE 4294967296 +#define MZRAN_STATE_SIZE 16 /* Size of the seed buffer - in bytes. */ + + +void mzran_fscanf_state( void * __rng , FILE * stream ); +unsigned int mzran_forward(void * __rng); +void * mzran_alloc( void ); +void mzran_set_state(void * __rng , const char * seed_buffer); +double mzran_get_double(mzran_type * rng); +int mzran_get_int( mzran_type * rng, int max); +void mzran_fprintf_state( const void * __rng , FILE * stream); +void mzran_free( void * __rng ); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/util/include/node_ctype.h b/ThirdParty/Ert-windows/util/include/node_ctype.h new file mode 100644 index 0000000000..147d75574c --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/node_ctype.h @@ -0,0 +1,50 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'node_ctype.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __NODE_CTYPE_H__ +#define __NODE_CTYPE_H__ +#ifdef __cplusplus +extern "C" { +#endif + + +/* + value : means a scalar which has been packed into the container + object. + + pointer: means a (typed) pointer which points to a memory location + outside the container object (however the container can own + the memory). + +*/ + +typedef enum {CTYPE_VOID_POINTER = 1, + CTYPE_INT_VALUE = 2, + CTYPE_DOUBLE_VALUE = 3, + CTYPE_FLOAT_VALUE = 4 , + CTYPE_CHAR_VALUE = 5 , + CTYPE_BOOL_VALUE = 6 , + CTYPE_SIZE_T_VALUE = 7 , + CTYPE_INVALID = 100} node_ctype; + + +const char * node_ctype_name(node_ctype ); +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/util/include/node_data.h b/ThirdParty/Ert-windows/util/include/node_data.h new file mode 100644 index 0000000000..2cbb1bf6af --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/node_data.h @@ -0,0 +1,57 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'node_data.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __NODE_DATA_H__ +#define __NODE_DATA_H__ +#ifdef __cplusplus +extern "C" { +#endif +#include + +typedef void * ( copyc_ftype ) (const void *); +typedef void ( free_ftype ) (void *); + + + +typedef struct node_data_struct node_data_type; + + +void node_data_free(node_data_type *); +void node_data_free_container(node_data_type * ); +node_data_type * node_data_alloc_deep_copy(const node_data_type * ); +node_data_type * node_data_alloc_shallow_copy(const node_data_type * ); +node_data_type * node_data_alloc_copy(const node_data_type * node , bool deep_copy); +void * node_data_get_ptr(const node_data_type *); +const void * node_data_get_const_ptr(const node_data_type *); +node_data_type * node_data_alloc_buffer(const void *, int ); +node_data_type * node_data_alloc_ptr(const void * , copyc_ftype * , free_ftype *); + +node_data_type * node_data_alloc_int(int ); +int node_data_get_int( const node_data_type * ); +int node_data_fetch_and_inc_int( node_data_type * node_data ); +node_data_type * node_data_alloc_double(double ); +double node_data_get_double( const node_data_type * ); +node_data_type * node_data_alloc_string(const char *); +char * node_data_get_string( const node_data_type * ); + + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/util/include/parser.h b/ThirdParty/Ert-windows/util/include/parser.h new file mode 100644 index 0000000000..dde0056f3b --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/parser.h @@ -0,0 +1,159 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'parser.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __PARSER_H__ +#define __PARSER_H__ +#include + +typedef struct parser_struct parser_type; + + +/** + GENERAL OVERVIEW + + The parser_type is used to create a series of "tokens" + from a file or string buffer. In it's simplest form, + we define a token as a subset of a string separated by + by some split characters. + + For example, if we define the normal space (i.e. " ") as + the only split character, "tokenizing" the string + "I like beer " would give the following result: + + Token number 0 is "I" + Token number 1 is "like" + Token number 2 is "beer" + + Note that all the white space (i.e. split characters) have been + removed. + + + + COMMENTS + + The parser can ignore comments when tokenzing + a file or buffer. To enable this feature, allocate + the parser_type with comment_start and comment_end + different from NULL. For example if we set both + comment_start and comment_end to "##", tokenizing + "I ## really ## like beer" would give: + + Token number 0 is "I" + Token number 1 is "like" + Token number 2 is "beer" + + + + SPECIAL CHARACTERS + + Some times it can be useful to define a set of characters which + behave like white space in the sense that they separate tokens in + the source, but they do not get dropped. For example, letting "=" be + a special character, tokenzing "key=value" would give: + + Token number 0 is "key" + Token number 1 is "=" + Token number 2 is "value" + + The special characters are given in the "specials" string when + allocating the parser. + + + + QUOTERS + + When parsing user input, the user often wants to provide e.g. a + filename with a white-space character in it. To support this, the + parser can be given a set of quoters. For example, letting " " be + white space and adding "'" to the quoters, tokenizing + + "my_file = 'my documents with space in.txt'" + + would give: + + Token number 0 is "my_file" + Token number 1 is "=" + Token number 2 is "'my documents with space in.txt'" + + If wanted, the quoting characters can be removed + using the strip_quote_marks options when running + the parser on the buffer. The last token + in the example above would then be: + + Token number 2 is "my documents with space in.txt" + + To use one of the quoter characters in a string, + place a "\" in front of it. Building on our previous + example, let the string be "my_file = 'my \'doc.txt'" + Tokenzing this with strip_quote_marks set to true + would give: + + Token number 0 is "my_file" + Token number 1 is "=" + Token number 2 is "my 'doc.txt" + + Note that the "\" in front of"'" has been removed. + If strip_quote_marks is set to false, the result is: + + + Token number 0 is "my_file" + Token number 1 is "=" + Token number 2 is "'my \'doc.txt'" + +*/ + + +parser_type * parser_alloc( + const char * whitespace, /** Set to NULL if not interessting. */ + const char * quoters, /** Set to NULL if not interessting. */ + const char * specials, /** Set to NULL if not interessting. */ + const char * delete_set, + const char * comment_start, /** Set to NULL if not interessting. */ + const char * comment_end); /** Set to NULL if not interessting. */ + + +void parser_set_splitters( parser_type * parser , const char * splitters ); +void parser_set_quoters( parser_type * parser , const char * quoters ); +void parser_set_specials( parser_type * parser , const char * specials ); +void parser_set_delete_set( parser_type * parser , const char * delete_set ); +void parser_set_comment_start( parser_type * parser , const char * comment_start ); +void parser_set_comment_end( parser_type * parser , const char * comment_end ); + + +void parser_free( + parser_type * parser); + + +stringlist_type * parser_tokenize_buffer( + const parser_type * parser, + const char * buffer, + bool strip_quote_marks); + + +stringlist_type * parser_tokenize_file( + const parser_type * parser, + const char * filename, + bool strip_quote_marks); + + +/* Pollution by Joakim: */ + +void parser_strip_buffer(const parser_type * parser , char ** __buffer); +bool parser_fseek_string(const parser_type * parser , FILE * stream , const char * string , bool skip_string , bool case_sensitive); +char * parser_fread_alloc_file_content(const char * filename , const char * quote_set , const char * delete_set , const char * comment_start , const char * comment_end); +#endif diff --git a/ThirdParty/Ert-windows/util/include/path_fmt.h b/ThirdParty/Ert-windows/util/include/path_fmt.h new file mode 100644 index 0000000000..6440e49268 --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/path_fmt.h @@ -0,0 +1,47 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'path_fmt.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __PATH_FMT_H__ +#define __PATH_FMT_H__ +#ifdef __cplusplus +extern "C" { +#endif +#include +#include +#include + +typedef struct path_fmt_struct path_fmt_type; + + +path_fmt_type * path_fmt_safe_cast(const void * arg); +path_fmt_type * path_fmt_alloc_directory_fmt(const char * ); +path_fmt_type * path_fmt_alloc_path_fmt(const char * ); +path_fmt_type * path_fmt_copyc(const path_fmt_type *); +path_fmt_type * path_fmt_scanf_alloc(const char * , int , const node_ctype * , bool ); +char * path_fmt_alloc_path(const path_fmt_type * , bool , ...); +char * path_fmt_alloc_file(const path_fmt_type * , bool , ...); +void path_fmt_free(path_fmt_type * ); +const char * path_fmt_get_fmt(const path_fmt_type * ); +void path_fmt_reset_fmt(path_fmt_type * , const char * ); +void path_fmt_make_path(const path_fmt_type * ); +path_fmt_type * path_fmt_realloc_path_fmt( path_fmt_type * path_fmt, const char * fmt ); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/util/include/regression.h b/ThirdParty/Ert-windows/util/include/regression.h new file mode 100644 index 0000000000..c5858e732f --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/regression.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'regression.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __REGRESSION_H__ +#define __REGRESSION_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + + +double regression_scale( matrix_type * X , matrix_type * Y , matrix_type * X_mean , matrix_type * X_norm); +double regression_unscale(const matrix_type * beta , const matrix_type * X_norm , const matrix_type * X_mean , double Y_mean , matrix_type * beta0); +void regression_OLS(const matrix_type * X , const matrix_type * Y , matrix_type * beta); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/util/include/rng.h b/ThirdParty/Ert-windows/util/include/rng.h new file mode 100644 index 0000000000..873bbd9fe0 --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/rng.h @@ -0,0 +1,75 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'rng.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __RNG_H__ +#define __RNG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + + +typedef enum { + INIT_DEFAULT = 0, /* The rng is initialized with the default seed values. */ + INIT_CLOCK = 1, /* Four random seeds are calculated with the util_clock_seed() function. */ + INIT_DEV_RANDOM = 2, /* Random content is read with the function util_fread_dev_random(). */ + INIT_DEV_URANDOM = 3 /* Random content is read with the function util_fread_dev_urandom(). */ +} rng_init_mode; + + +typedef enum { + MZRAN = 1 +} rng_alg_type; + + + typedef unsigned int ( rng_forward_ftype ) ( void * ); + typedef void ( rng_set_state_ftype ) ( void * , const char * ); + typedef void * ( rng_alloc_ftype ) ( void ); + typedef void ( rng_free_ftype ) ( void * ); + typedef void ( rng_fscanf_ftype ) ( void * , FILE * ); + typedef void ( rng_fprintf_ftype ) ( const void * , FILE * ); + + typedef struct rng_struct rng_type; + + rng_type * rng_alloc( rng_alg_type type , rng_init_mode init_mode ); + void rng_free( rng_type * rng); + void rng_free( rng_type * rng); + unsigned int rng_forward( rng_type * rng ); + double rng_get_double( rng_type * rng); + void rng_rng_init( rng_type * rng , rng_type * seed_src); + void rng_init( rng_type * rng , rng_init_mode init_mode ); + rng_alg_type rng_get_type( const rng_type * rng ); + void rng_fprintf_state( rng_type * rng , FILE * stream ); + void rng_fscanf_state( rng_type * rng , FILE * stream ); + + unsigned int rng_forward( rng_type * rng ); + double rng_get_double( rng_type * rng ); + int rng_get_int( rng_type * rng , int max_value ); + + double rng_std_normal( rng_type * rng ); + void rng_shuffle_int( rng_type * rng , int * data , size_t num_elements); + void rng_shuffle( rng_type * rng , char * data , size_t element_size , size_t num_elements); + + UTIL_SAFE_CAST_HEADER( rng ); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/util/include/set.h b/ThirdParty/Ert-windows/util/include/set.h new file mode 100644 index 0000000000..5febf85da8 --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/set.h @@ -0,0 +1,61 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'set.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __SET_H__ +#define __SET_H__ +#ifdef __cplusplus +extern "C" { +#endif +#include +#include +#include + +#include + +typedef struct set_struct set_type; +typedef struct set_iter_struct set_iter_type; + +void set_clear( set_type * set ); +void set_remove_key(set_type * , const char * ); +set_type * set_alloc(int , const char ** ); +set_type * set_alloc_empty(); +bool set_add_key(set_type * , const char * ); +bool set_has_key(const set_type * set, const char * ); +void set_free(set_type * ); +int set_get_size(const set_type *); +char ** set_alloc_keylist(const set_type * ); +void set_fwrite(const set_type * , FILE * ); +void set_fread(set_type * , FILE * ); +set_type * set_fread_alloc(FILE *); +void set_fprintf(const set_type * , const char * sep , FILE * ); +void set_intersect(set_type * , const set_type * ); +void set_union(set_type * , const set_type * ); +void set_minus(set_type * , const set_type * ); +set_type * set_copyc(const set_type *); + + +set_iter_type * set_iter_alloc(const set_type * set); +void set_iter_free(set_iter_type * set_iter); +bool set_iter_is_complete(const set_iter_type * set_iter); +const char * set_iter_get_next_key(set_iter_type * set_iter); + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/util/include/size_t_vector.h b/ThirdParty/Ert-windows/util/include/size_t_vector.h new file mode 100644 index 0000000000..212ff66064 --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/size_t_vector.h @@ -0,0 +1,116 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'vector_template.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __size_t_VECTOR_H__ +#define __size_t_VECTOR_H__ +#ifdef __cplusplus +extern "C" { +#endif +#include + +#include +#include + +typedef struct size_t_vector_struct size_t_vector_type; +typedef size_t (size_t_ftype) (size_t); + + + int size_t_vector_lookup_bin( const size_t_vector_type * limits , size_t value , int guess); + int size_t_vector_lookup_bin__( const size_t_vector_type * limits , size_t value , int guess); + void size_t_vector_inplace_div( size_t_vector_type * vector , const size_t_vector_type * inv_factor); + void size_t_vector_inplace_mul( size_t_vector_type * vector , const size_t_vector_type * factor); + void size_t_vector_inplace_add( size_t_vector_type * vector , const size_t_vector_type * delta); + void size_t_vector_set_read_only( size_t_vector_type * vector , bool read_only); + bool size_t_vector_get_read_only( const size_t_vector_type * vector ); + void size_t_vector_resize( size_t_vector_type * vector , int new_alloc_size ); + void size_t_vector_memcpy( size_t_vector_type * target , const size_t_vector_type * src); + void size_t_vector_memcpy_data_block( size_t_vector_type * target , const size_t_vector_type * src , int target_offset , int src_offset , int len); + bool size_t_vector_growable( const size_t_vector_type * vector); + void size_t_vector_select_unique(size_t_vector_type * vector); + size_t_vector_type * size_t_vector_alloc( int init_size , size_t ); + size_t_vector_type * size_t_vector_alloc_private_wrapper(int init_size, size_t default_value , size_t * data , int alloc_size); + size_t_vector_type * size_t_vector_alloc_shared_wrapper(int init_size, size_t default_value , size_t * data , int alloc_size); + size_t_vector_type * size_t_vector_alloc_strided_copy( const size_t_vector_type * src , int start , int stop , int stride ); + size_t_vector_type * size_t_vector_alloc_copy( const size_t_vector_type * src); + void size_t_vector_imul(size_t_vector_type * vector, int index, size_t factor); + void size_t_vector_scale(size_t_vector_type * vector, size_t factor); + size_t size_t_vector_iget(const size_t_vector_type * , int); + size_t size_t_vector_safe_iget(const size_t_vector_type * , int); + size_t size_t_vector_get_min(const size_t_vector_type * vector); + size_t size_t_vector_get_max(const size_t_vector_type * vector); + int size_t_vector_get_min_index(const size_t_vector_type * vector, bool reverse); + int size_t_vector_get_max_index(const size_t_vector_type * vector, bool reverse); + size_t size_t_vector_iadd( size_t_vector_type * vector , int index , size_t delta); + void size_t_vector_iset(size_t_vector_type * , int , size_t); + void size_t_vector_idel_block( size_t_vector_type * vector , int index , int block_size); + size_t size_t_vector_idel( size_t_vector_type * vector , int index); + void size_t_vector_append(size_t_vector_type * , size_t); + void size_t_vector_free(size_t_vector_type *); + void size_t_vector_free__(void *); + void size_t_vector_free_data(size_t_vector_type *); + void size_t_vector_reset(size_t_vector_type *); + void size_t_vector_reset__(void * __vector); + int size_t_vector_size(const size_t_vector_type * ); + size_t size_t_vector_pop(size_t_vector_type * vector); + size_t size_t_vector_get_first(const size_t_vector_type * vector); + size_t size_t_vector_get_last(const size_t_vector_type * ); + size_t * size_t_vector_get_ptr(const size_t_vector_type * ); + size_t * size_t_vector_alloc_data_copy( const size_t_vector_type * vector ); + const size_t * size_t_vector_get_const_ptr(const size_t_vector_type * ); + void size_t_vector_set_many(size_t_vector_type * , int , const size_t * , int ); + void size_t_vector_set_all(size_t_vector_type * vector , size_t value); + void size_t_vector_append_many(size_t_vector_type * vector , const size_t * data , int length); + void size_t_vector_shrink(size_t_vector_type * ); + size_t size_t_vector_sum(const size_t_vector_type * ); + size_t size_t_vector_get_default(const size_t_vector_type * ); + void size_t_vector_set_default(size_t_vector_type * vector, size_t default_value); + void size_t_vector_append_default(size_t_vector_type * vector , size_t default_value); + void size_t_vector_iset_default(size_t_vector_type * vector , int index , size_t default_value); + bool size_t_vector_is_sorted( const size_t_vector_type * vector , bool reverse); + int size_t_vector_index(const size_t_vector_type * vector , size_t value); + int size_t_vector_index_sorted(const size_t_vector_type * vector , size_t value); + void size_t_vector_sort(size_t_vector_type * vector); + void size_t_vector_rsort(size_t_vector_type * vector); + void size_t_vector_permute(size_t_vector_type * vector , const int * perm); + int * size_t_vector_alloc_sort_perm(const size_t_vector_type * vector); + int * size_t_vector_alloc_rsort_perm(const size_t_vector_type * vector); + void size_t_vector_fprintf(const size_t_vector_type * vector , FILE * stream , const char * name , const char * fmt); + void size_t_vector_fwrite(const size_t_vector_type * vector , FILE * stream); + void size_t_vector_buffer_fread(size_t_vector_type * vector , buffer_type * buffer); + size_t_vector_type * size_t_vector_fread_alloc( FILE * stream ); + size_t_vector_type * size_t_vector_buffer_fread_alloc( buffer_type * buffer ); + void size_t_vector_buffer_fwrite(const size_t_vector_type * vector , buffer_type * buffer); + void size_t_vector_fread( size_t_vector_type * vector , FILE * stream ); + void size_t_vector_fwrite_data( const size_t_vector_type * vector , FILE * stream ); + void size_t_vector_fread_data( size_t_vector_type * vector , int size, FILE * stream); + bool size_t_vector_equal(const size_t_vector_type * vector1 , const size_t_vector_type * vector2); + void size_t_vector_apply(size_t_vector_type * vector , size_t_ftype *func); + int size_t_vector_count_equal( const size_t_vector_type * vector , size_t cmp_value); + int size_t_vector_element_size( const size_t_vector_type * vector ); + + UTIL_SAFE_CAST_HEADER( size_t_vector ); + +#ifdef __cplusplus +} +#endif +#endif +// + + + + diff --git a/ThirdParty/Ert-windows/util/include/ssize_t.h b/ThirdParty/Ert-windows/util/include/ssize_t.h new file mode 100644 index 0000000000..f9e901aef9 --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/ssize_t.h @@ -0,0 +1,27 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ssize_t.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __SSIZE_T_H__ +#define __SSIZE_T_H__ + +#ifdef _MSC_VER +// This should of course check 32/64/... +typedef long ssize_t; +#endif + +#endif diff --git a/ThirdParty/Ert-windows/util/include/statistics.h b/ThirdParty/Ert-windows/util/include/statistics.h new file mode 100644 index 0000000000..fad1e4ec24 --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/statistics.h @@ -0,0 +1,34 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'statistics.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __STATISTICS_H__ +#define __STATISTICS_H__ + +#ifdef __cplusplus +extern "C" { +#endif +#include + +double statistics_mean( const double_vector_type * data_vector ); +double statistics_empirical_quantile( double_vector_type * data , double quantile ); +double statistics_empirical_quantile__( const double_vector_type * data , double quantile ); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/util/include/stepwise.h b/ThirdParty/Ert-windows/util/include/stepwise.h new file mode 100644 index 0000000000..3b1a9f2b67 --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/stepwise.h @@ -0,0 +1,35 @@ +#ifndef __STEPWISE_H__ +#define __STEPWISE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + + typedef struct stepwise_struct stepwise_type; + + + stepwise_type * stepwise_alloc2( matrix_type * X , matrix_type * Y , bool internal_copy , rng_type * rng); + stepwise_type * stepwise_alloc1(int nsample, int nvar, rng_type * rng); + stepwise_type * stepwise_alloc0(rng_type * rng); + + void stepwise_free( stepwise_type * stepwise); + void stepwise_estimate( stepwise_type * stepwise , double deltaR2_limit , int CV_blocks); + double stepwise_eval( const stepwise_type * stepwise , const matrix_type * x ); + void stepwise_set_Y0( stepwise_type * stepwise , matrix_type * Y); + void stepwise_set_X0( stepwise_type * stepwise , matrix_type * X); + void stepwise_set_beta( stepwise_type * stepwise , matrix_type * b); + void stepwise_set_active_set( stepwise_type * stepwise , bool_vector_type * a); + void stepwise_isetY0( stepwise_type * stepwise , int i , double value ); + + int stepwise_get_nvar( stepwise_type * stepwise ); + int stepwise_get_nsample( stepwise_type * stepwise ); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/ThirdParty/Ert-windows/util/include/stringlist.h b/ThirdParty/Ert-windows/util/include/stringlist.h new file mode 100644 index 0000000000..d05ac45d2d --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/stringlist.h @@ -0,0 +1,107 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'stringlist.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __STRINGLIST_H__ +#define __STRINGLIST_H__ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#include +#include +#include + +typedef struct stringlist_struct stringlist_type; +typedef int ( string_cmp_ftype) (const void * , const void *); + + + void stringlist_deep_copy( stringlist_type * target , const stringlist_type * src); + stringlist_type * stringlist_alloc_deep_copy_with_limits(const stringlist_type * src , int offset, int num_strings); + stringlist_type * stringlist_alloc_deep_copy_with_offset(const stringlist_type * src , int offset); + stringlist_type * stringlist_alloc_deep_copy( const stringlist_type * src ); + + stringlist_type * stringlist_alloc_new(); + void stringlist_free__(void * ); + void stringlist_free(stringlist_type *); + void stringlist_clear(stringlist_type * ); + + void stringlist_append_copy(stringlist_type * , const char *); + void stringlist_append_ref(stringlist_type * , const char *); + void stringlist_append_owned_ref(stringlist_type * , const char *); + + const char * stringlist_safe_iget( const stringlist_type * stringlist , int index); + bool stringlist_iequal( const stringlist_type * stringlist , int index, const char * s ); + const char * stringlist_iget(const stringlist_type * , int); + char * stringlist_iget_copy(const stringlist_type * stringlist , int ); + char * stringlist_alloc_joined_string(const stringlist_type * , const char * ); + char * stringlist_alloc_joined_substring( const stringlist_type * s , int start_index , int end_index , const char * sep ); + + void stringlist_iset_copy(stringlist_type *, int index , const char *); + void stringlist_iset_ref(stringlist_type *, int index , const char *); + void stringlist_iset_owned_ref(stringlist_type *, int index , const char *); + + void stringlist_insert_copy(stringlist_type *, int index , const char *); + void stringlist_insert_ref(stringlist_type *, int index , const char *); + void stringlist_insert_owned_ref(stringlist_type *, int index , const char *); + + void stringlist_idel(stringlist_type * stringlist , int index); + + int stringlist_get_size(const stringlist_type * ); + void stringlist_fprintf(const stringlist_type * , const char * , FILE *); + void stringlist_fprintf_fmt(const stringlist_type * stringlist, const stringlist_type * fmt_list , FILE * stream); + + + stringlist_type * stringlist_alloc_argv_copy(const char ** , int ); + stringlist_type * stringlist_alloc_argv_ref (const char ** , int ); + stringlist_type * stringlist_alloc_argv_owned_ref(const char ** argv , int argc); + stringlist_type * stringlist_alloc_shallow_copy(const stringlist_type *); + stringlist_type * stringlist_alloc_shallow_copy_with_offset(const stringlist_type * stringlist, int offset); + stringlist_type * stringlist_alloc_shallow_copy_with_limits(const stringlist_type * stringlist, int offset , int num_strings); + stringlist_type * stringlist_alloc_from_split( const char * input_string , const char * sep ); + stringlist_type * stringlist_fread_alloc(FILE * ); + + void stringlist_append_stringlist_copy(stringlist_type * , const stringlist_type * ); + void stringlist_append_stringlist_ref(stringlist_type * , const stringlist_type * ); + void stringlist_insert_stringlist_copy(stringlist_type * , const stringlist_type *, int); + + bool stringlist_equal(const stringlist_type * , const stringlist_type *); + bool stringlist_contains(const stringlist_type * , const char * ); + int_vector_type * stringlist_find(const stringlist_type *, const char *); + int stringlist_find_first(const stringlist_type * , const char * ); + int stringlist_get_argc(const stringlist_type * ); + char ** stringlist_alloc_char_copy(const stringlist_type * ); + void stringlist_fread(stringlist_type * , FILE * ); + void stringlist_fwrite(const stringlist_type * , FILE * ); + void stringlist_buffer_fread( stringlist_type * s , buffer_type * buffer ); + void stringlist_buffer_fwrite( const stringlist_type * s , buffer_type * buffer ); + void stringlist_sort(stringlist_type * , string_cmp_ftype * string_cmp); + void stringlist_python_sort( stringlist_type * s , int cmp_flag); + +#ifdef HAVE_GLOB + int stringlist_select_matching(stringlist_type * names , const char * pattern); +#endif + int stringlist_select_matching_files(stringlist_type * names , const char * path , const char * file_pattern); + UTIL_IS_INSTANCE_HEADER(stringlist); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/util/include/subst_func.h b/ThirdParty/Ert-windows/util/include/subst_func.h new file mode 100644 index 0000000000..1c0fee52dd --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/subst_func.h @@ -0,0 +1,56 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'subst_func.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __SUBST_FUNC_H__ +#define __SUBST_FUNC_H__ +#ifdef __cplusplus +extern "C" { +#endif + +#include + +typedef char * (subst_func_ftype) (const stringlist_type * , void * ); +typedef struct subst_func_struct subst_func_type; +typedef struct subst_func_pool_struct subst_func_pool_type; + + + char * subst_func_eval( const subst_func_type * subst_func , const stringlist_type * args); + +/*****************************************************************/ + +subst_func_pool_type * subst_func_pool_alloc( ); +void subst_func_pool_free( subst_func_pool_type * pool ); + void subst_func_pool_add_func( subst_func_pool_type * pool , const char * func_name , const char * doc_string , subst_func_ftype * func , bool vararg, int argc_min , int argc_max , void * arg); +subst_func_type * subst_func_pool_get_func( const subst_func_pool_type * pool , const char * func_name ); +bool subst_func_pool_has_func( const subst_func_pool_type * pool , const char * func_name ); +UTIL_IS_INSTANCE_HEADER( subst_func_pool ); + +/*****************************************************************/ +char * subst_func_randint( const stringlist_type * args , void * arg); +char * subst_func_randfloat( const stringlist_type * args , void * arg); +char * subst_func_add( const stringlist_type * args , void * arg); +char * subst_func_mul( const stringlist_type * args , void * arg); +char * subst_func_exp( const stringlist_type * args , void * arg); +char * subst_func_log( const stringlist_type * args , void * arg); +char * subst_func_pow10( const stringlist_type * args , void * arg); + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/util/include/subst_list.h b/ThirdParty/Ert-windows/util/include/subst_list.h new file mode 100644 index 0000000000..71f5d9666e --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/subst_list.h @@ -0,0 +1,66 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'subst_list.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __SUBST_H__ +#define __SUBST_H__ + +#ifdef __cplusplus +extern "C" { +#endif +#include + +#include +#include +#include + + typedef struct subst_list_struct subst_list_type; + void subst_list_update_buffer( const subst_list_type * subst_list , buffer_type * buffer ); + void subst_list_insert_func(subst_list_type * subst_list , const char * func_name , const char * local_func_name); + void subst_list_fprintf(const subst_list_type * , FILE * stream); + void subst_list_set_parent( subst_list_type * subst_list , const subst_list_type * parent); + const subst_list_type * subst_list_get_parent( const subst_list_type * subst_list ); + subst_list_type * subst_list_alloc( const void * input_arg ); + subst_list_type * subst_list_alloc_deep_copy(const subst_list_type * ); + void subst_list_free(subst_list_type *); + void subst_list_clear( subst_list_type * subst_list ); + void subst_list_append_copy(subst_list_type * , const char * , const char * , const char * doc_string); + void subst_list_append_ref(subst_list_type * , const char * , const char * , const char * doc_string); + void subst_list_append_owned_ref(subst_list_type * , const char * , const char * , const char * doc_string); + void subst_list_prepend_copy(subst_list_type * , const char * , const char * , const char * doc_string); + void subst_list_prepend_ref(subst_list_type * , const char * , const char * , const char * doc_string); + void subst_list_prepend_owned_ref(subst_list_type * , const char * , const char * , const char * doc_string); + + void subst_list_filter_file(const subst_list_type * , const char * , const char * ); + void subst_list_update_file(const subst_list_type * , const char * ); + void subst_list_update_string(const subst_list_type * , char ** ); + char * subst_list_alloc_filtered_string(const subst_list_type * , const char * ); + void subst_list_filtered_fprintf(const subst_list_type * , const char * , FILE * ); + int subst_list_get_size( const subst_list_type *); + const char * subst_list_iget_value( const subst_list_type * subst_list , int index); + const char * subst_list_iget_key( const subst_list_type * subst_list , int index); + const char * subst_list_iget_doc_string( const subst_list_type * subst_list , int index); + char * subst_list_alloc_string_representation( const subst_list_type * subst_list ); + int subst_list_add_from_string( subst_list_type * subst_list , const char * arg_string, bool append); + +#ifdef __cplusplus +} +#endif +#endif + + + diff --git a/ThirdParty/Ert-windows/util/include/template.h b/ThirdParty/Ert-windows/util/include/template.h new file mode 100644 index 0000000000..f751c58a26 --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/template.h @@ -0,0 +1,47 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'template.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __TEMPLATE_H__ +#define __TEMPLATE_H__ +#ifdef __cplusplus +extern "C" { +#endif + + +#include +#include + +typedef struct template_struct template_type; + + +template_type * template_alloc( const char * template_file , bool internalize_template, subst_list_type * parent_subst); +void template_free( template_type * template ); +void template_instansiate( const template_type * template , const char * __target_file , const subst_list_type * arg_list , bool override_symlink); +void template_add_arg( template_type * template , const char * key , const char * value ); + +void template_clear_args( template_type * template ); +int template_add_args_from_string( template_type * template , const char * arg_string); +char * template_get_args_as_string( template_type * template ); +void template_set_template_file( template_type * template , const char * template_file); +const char * template_get_template_file( const template_type * template ); + + +#endif +#ifdef __cplusplus +} +#endif diff --git a/ThirdParty/Ert-windows/util/include/thread_pool.h b/ThirdParty/Ert-windows/util/include/thread_pool.h new file mode 100644 index 0000000000..0aa675360a --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/thread_pool.h @@ -0,0 +1,26 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'thread_pool.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ +#ifndef __THREAD_POOL_H__ +#define __THREAD_POOL_H__ + +#ifdef HAVE_PTHREAD +#define HAVE_THREAD_POOL +#include "thread_pool_posix.h" +#endif + +#endif diff --git a/ThirdParty/Ert-windows/util/include/time_t_vector.h b/ThirdParty/Ert-windows/util/include/time_t_vector.h new file mode 100644 index 0000000000..f9847380b7 --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/time_t_vector.h @@ -0,0 +1,116 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'vector_template.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __time_t_VECTOR_H__ +#define __time_t_VECTOR_H__ +#ifdef __cplusplus +extern "C" { +#endif +#include + +#include +#include + +typedef struct time_t_vector_struct time_t_vector_type; +typedef time_t (time_t_ftype) (time_t); + + + int time_t_vector_lookup_bin( const time_t_vector_type * limits , time_t value , int guess); + int time_t_vector_lookup_bin__( const time_t_vector_type * limits , time_t value , int guess); + void time_t_vector_inplace_div( time_t_vector_type * vector , const time_t_vector_type * inv_factor); + void time_t_vector_inplace_mul( time_t_vector_type * vector , const time_t_vector_type * factor); + void time_t_vector_inplace_add( time_t_vector_type * vector , const time_t_vector_type * delta); + void time_t_vector_set_read_only( time_t_vector_type * vector , bool read_only); + bool time_t_vector_get_read_only( const time_t_vector_type * vector ); + void time_t_vector_resize( time_t_vector_type * vector , int new_alloc_size ); + void time_t_vector_memcpy( time_t_vector_type * target , const time_t_vector_type * src); + void time_t_vector_memcpy_data_block( time_t_vector_type * target , const time_t_vector_type * src , int target_offset , int src_offset , int len); + bool time_t_vector_growable( const time_t_vector_type * vector); + void time_t_vector_select_unique(time_t_vector_type * vector); + time_t_vector_type * time_t_vector_alloc( int init_size , time_t ); + time_t_vector_type * time_t_vector_alloc_private_wrapper(int init_size, time_t default_value , time_t * data , int alloc_size); + time_t_vector_type * time_t_vector_alloc_shared_wrapper(int init_size, time_t default_value , time_t * data , int alloc_size); + time_t_vector_type * time_t_vector_alloc_strided_copy( const time_t_vector_type * src , int start , int stop , int stride ); + time_t_vector_type * time_t_vector_alloc_copy( const time_t_vector_type * src); + void time_t_vector_imul(time_t_vector_type * vector, int index, time_t factor); + void time_t_vector_scale(time_t_vector_type * vector, time_t factor); + time_t time_t_vector_iget(const time_t_vector_type * , int); + time_t time_t_vector_safe_iget(const time_t_vector_type * , int); + time_t time_t_vector_get_min(const time_t_vector_type * vector); + time_t time_t_vector_get_max(const time_t_vector_type * vector); + int time_t_vector_get_min_index(const time_t_vector_type * vector, bool reverse); + int time_t_vector_get_max_index(const time_t_vector_type * vector, bool reverse); + time_t time_t_vector_iadd( time_t_vector_type * vector , int index , time_t delta); + void time_t_vector_iset(time_t_vector_type * , int , time_t); + void time_t_vector_idel_block( time_t_vector_type * vector , int index , int block_size); + time_t time_t_vector_idel( time_t_vector_type * vector , int index); + void time_t_vector_append(time_t_vector_type * , time_t); + void time_t_vector_free(time_t_vector_type *); + void time_t_vector_free__(void *); + void time_t_vector_free_data(time_t_vector_type *); + void time_t_vector_reset(time_t_vector_type *); + void time_t_vector_reset__(void * __vector); + int time_t_vector_size(const time_t_vector_type * ); + time_t time_t_vector_pop(time_t_vector_type * vector); + time_t time_t_vector_get_first(const time_t_vector_type * vector); + time_t time_t_vector_get_last(const time_t_vector_type * ); + time_t * time_t_vector_get_ptr(const time_t_vector_type * ); + time_t * time_t_vector_alloc_data_copy( const time_t_vector_type * vector ); + const time_t * time_t_vector_get_const_ptr(const time_t_vector_type * ); + void time_t_vector_set_many(time_t_vector_type * , int , const time_t * , int ); + void time_t_vector_set_all(time_t_vector_type * vector , time_t value); + void time_t_vector_append_many(time_t_vector_type * vector , const time_t * data , int length); + void time_t_vector_shrink(time_t_vector_type * ); + time_t time_t_vector_sum(const time_t_vector_type * ); + time_t time_t_vector_get_default(const time_t_vector_type * ); + void time_t_vector_set_default(time_t_vector_type * vector, time_t default_value); + void time_t_vector_append_default(time_t_vector_type * vector , time_t default_value); + void time_t_vector_iset_default(time_t_vector_type * vector , int index , time_t default_value); + bool time_t_vector_is_sorted( const time_t_vector_type * vector , bool reverse); + int time_t_vector_index(const time_t_vector_type * vector , time_t value); + int time_t_vector_index_sorted(const time_t_vector_type * vector , time_t value); + void time_t_vector_sort(time_t_vector_type * vector); + void time_t_vector_rsort(time_t_vector_type * vector); + void time_t_vector_permute(time_t_vector_type * vector , const int * perm); + int * time_t_vector_alloc_sort_perm(const time_t_vector_type * vector); + int * time_t_vector_alloc_rsort_perm(const time_t_vector_type * vector); + void time_t_vector_fprintf(const time_t_vector_type * vector , FILE * stream , const char * name , const char * fmt); + void time_t_vector_fwrite(const time_t_vector_type * vector , FILE * stream); + void time_t_vector_buffer_fread(time_t_vector_type * vector , buffer_type * buffer); + time_t_vector_type * time_t_vector_fread_alloc( FILE * stream ); + time_t_vector_type * time_t_vector_buffer_fread_alloc( buffer_type * buffer ); + void time_t_vector_buffer_fwrite(const time_t_vector_type * vector , buffer_type * buffer); + void time_t_vector_fread( time_t_vector_type * vector , FILE * stream ); + void time_t_vector_fwrite_data( const time_t_vector_type * vector , FILE * stream ); + void time_t_vector_fread_data( time_t_vector_type * vector , int size, FILE * stream); + bool time_t_vector_equal(const time_t_vector_type * vector1 , const time_t_vector_type * vector2); + void time_t_vector_apply(time_t_vector_type * vector , time_t_ftype *func); + int time_t_vector_count_equal( const time_t_vector_type * vector , time_t cmp_value); + int time_t_vector_element_size( const time_t_vector_type * vector ); + + UTIL_SAFE_CAST_HEADER( time_t_vector ); + +#ifdef __cplusplus +} +#endif +#endif +// + + + + diff --git a/ThirdParty/Ert-windows/util/include/timer.h b/ThirdParty/Ert-windows/util/include/timer.h new file mode 100644 index 0000000000..68ecec8c7a --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/timer.h @@ -0,0 +1,45 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'timer.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __TIMER_H__ +#define __TIMER_H__ + +#include +#include +#include +#include + + +typedef struct timer_struct timer_type; + + + +timer_type * timer_alloc(const char *, bool ); +void timer_free(timer_type *); +void timer_start(timer_type *); +double timer_stop(timer_type *); +void timer_reset(timer_type *); +void timer_report(const timer_type * , FILE *); +void timer_list_report(const timer_type ** , int , FILE *) ; + +double timer_get_total_time(const timer_type *timer); +double timer_get_max_time(const timer_type *timer); +double timer_get_min_time(const timer_type *timer); +double timer_get_avg_time(const timer_type *timer); +#endif + diff --git a/ThirdParty/Ert-windows/util/include/type_macros.h b/ThirdParty/Ert-windows/util/include/type_macros.h new file mode 100644 index 0000000000..f20eb37cfd --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/type_macros.h @@ -0,0 +1,98 @@ +#ifndef __TYPE_MACROS_H__ +#define __TYPE_MACROS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/*****************************************************************/ +/** + + The four macros UTIL_IS_INSTANCE_FUNCTION, UTIL_SAFE_CAST_FUNTION, + UTIL_TYPE_ID_DECLARATION and UTIL_TYPE_ID_INIT can be used to + implement a simple system for type checking (void *) at + runtime. The system is based on a unique integer for each class, + this must be provided by the user. + + The motivation for these functions is to be able to to type-check + the arguments to callback functions like pthread_create. + + UTIL_TYPE_ID_DECLARATION: Adds a field "int __type_id;" to the + struct defintion. + + UTIL_TYPE_ID_INIT: Should be added to the allocation routine, + inserts a "->__type_id = magic_int;" code line in the alloc + routine. + + UTIL_IS_INSTANCE_FUNCTION: This macro will generate a function + _is_instance(void *) which will cast the (void *) input to + (type *), and check the value of __type_id. If this is the + correct value true is returned, otherwise the function will + return false. Observe that the function will accept NULL as + input; in which case it will return false. + + UTIL_SAFE_CAST_FUNCTION: This is similar to + UTIL_IS_INSTANCE_FUNCTION, but it will return (type *) if the + cast succeeds, and fail hard if it fails. There is also a _CONST + variety of this function. + +*/ + + + + +#define UTIL_IS_INSTANCE_FUNCTION(type , TYPE_ID) \ +bool type ## _is_instance( const void * __arg ) { \ + if (__arg == NULL) \ + return false; \ + else { \ + const type ## _type * arg = (type ## _type *) __arg; \ + if ( arg->__type_id == TYPE_ID) \ + return true; \ + else \ + return false; \ + } \ +} + + +#define UTIL_IS_INSTANCE_HEADER(type) bool type ## _is_instance( const void * __arg ) + + +#define UTIL_SAFE_CAST_FUNCTION(type , TYPE_ID) \ +type ## _type * type ## _safe_cast( void * __arg ) { \ + if (__arg == NULL) { \ + util_abort("%s: runtime cast failed - tried to dereference NULL\n",__func__); \ + return NULL; \ + } \ + type ## _type * arg = (type ## _type *) __arg; \ + if ( arg->__type_id == TYPE_ID) \ + return arg; \ + else { \ + util_abort("%s: runtime cast failed: File:%s Line:%d. Got:%d Expected:%d \n", __func__ , __FILE__ , __LINE__ , arg->__type_id , TYPE_ID); \ + return NULL; \ + } \ +} +#define UTIL_SAFE_CAST_HEADER( type ) type ## _type * type ## _safe_cast( void * __arg ) + + +#define UTIL_SAFE_CAST_FUNCTION_CONST(type , TYPE_ID) \ +const type ## _type * type ## _safe_cast_const( const void * __arg ) { \ + const type ## _type * arg = (const type ## _type *) __arg; \ + if ( arg->__type_id == TYPE_ID) \ + return arg; \ + else { \ + util_abort("%s: runtime cast failed: File:%s Line:%d. Got:%d Expected:%d \n", __func__ , __FILE__ , __LINE__ , arg->__type_id , TYPE_ID); \ + return NULL; \ + } \ +} +#define UTIL_SAFE_CAST_HEADER_CONST( type ) const type ## _type * type ## _safe_cast_const( const void * __arg ) + +#define UTIL_TYPE_ID_DECLARATION int __type_id +#define UTIL_TYPE_ID_INIT(var , TYPE_ID) var->__type_id = TYPE_ID; + + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/util/include/util.h b/ThirdParty/Ert-windows/util/include/util.h new file mode 100644 index 0000000000..41215b76ff --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/util.h @@ -0,0 +1,421 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'util.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __UTIL_H__ +#define __UTIL_H__ + +#include +#include +#include +#include + +#ifdef HAVE_GETUID +#include +#include +#endif + +#define UTIL_PATH_SEP_STRING "/" /* A \0 terminated separator used when we want a (char *) instance. */ +#define UTIL_PATH_SEP_CHAR '/' /* A simple character used when we want an actual char instance (i.e. not a pointer). */ +#define UTIL_NEWLINE_STRING " \n" +#define UTIL_DEFAULT_MKDIR_MODE 0777 /* Directories are by default created with mode a+rwx - and then comes the umask ... */ + +//#include "type_macros.h" + +#ifdef __cplusplus +extern"C" { +#endif + + + +/*****************************************************************/ +/* + +*/ + + +/*****************************************************************/ +typedef void (walk_file_callback_ftype) (const char * , /* The current directory */ + const char * , /* The current file / directory */ + void *); /* Arbitrary argument */ + +typedef bool (walk_dir_callback_ftype) (const char * , /* The current directory */ + const char * , /* The current file / directory */ + int , /* The current depth in the file hiearcrcy. */ + void *); /* Arbitrary argument */ + + +typedef enum {left_pad = 0, + right_pad = 1, + center_pad = 2} string_alignement_type; + + //#define UTIL_CXX_MALLOC(var , num_elm) (typeof (var)) util_malloc( (num_elm) * sizeof var, __func__) + + void util_bitmask_on(int * , int ); + time_t util_make_datetime(int , int , int , int , int , int ); + void util_fprintf_datetime(time_t , FILE * ); + void util_fprintf_date(time_t , FILE * ); + time_t util_make_date(int , int , int); + void util_inplace_forward_days(time_t * , double); + double util_difftime(time_t , time_t , int * , int * , int * , int *); + double util_difftime_days(time_t , time_t ); + char * util_alloc_date_string( time_t t ); + char * util_alloc_date_stamp( ); + double util_pow10(double x); + bool util_char_in(char c, int , const char *); + char * util_alloc_sprintf_va(const char * fmt , va_list ap); + char * util_alloc_sprintf(const char * , ...); + char * util_realloc_sprintf(char * , const char * , ...); + void util_fprintf_int(int , int , FILE * ); + void util_fprintf_string(const char * , int , string_alignement_type , FILE * ); + void util_fprintf_double(double , int , int , char , FILE *); + bool util_fscanf_date(FILE * , time_t *); + bool util_sscanf_date(const char * , time_t *); + char * util_blocking_alloc_stdin_line(unsigned long ); + char * util_alloc_stdin_line(); + char * util_realloc_stdin_line(char * ); + bool util_is_executable(const char * ); + bool util_entry_exists( const char * entry ); + bool util_file_exists(const char *); + bool util_is_abs_path(const char * ); + char * util_alloc_abs_path( const char * path ); + bool util_fmt_bit8 (const char *); + bool util_fmt_bit8_stream(FILE * ); + void util_make_path (const char *); + char * util_newest_file(const char *, const char *); + double util_file_difftime(const char * , const char *); + bool util_file_update_required(const char *, const char *); + size_t util_file_size(const char *); + void util_clear_directory(const char *path, bool strict_uid , bool unlink_root); + void util_unlink_existing(const char *filename); + void util_strupr(char *); + bool util_string_equal(const char * s1 , const char * s2 ); + char * util_alloc_strupr_copy(const char * ); + void util_string_tr(char * , char , char); + bool util_copy_stream(FILE *, FILE *, int , void * , bool abort_on_error); + void util_move_file(const char * src_file , const char * target_file); + void util_move_file4( const char * src_name , const char * target_name , const char *src_path , const char * target_path); + bool util_copy_file(const char * , const char * ); + void util_copy_directory(const char * , const char * , const char *); + void util_walk_directory(const char * root_path , walk_file_callback_ftype * file_callback , void * file_callback_arg , walk_dir_callback_ftype * dir_callback , void * dir_callback_arg); + char * util_alloc_cwd(void); + char * util_alloc_realpath(const char * ); + bool util_string_match(const char * string , const char * pattern); + bool util_string_has_wildcard( const char * s); + bool util_entry_readable( const char * entry ); + +#ifdef HAVE_GETUID + uid_t util_get_entry_uid( const char * file ); + bool util_addmode_if_owner( const char * filename , mode_t add_mode ); + bool util_delmode_if_owner( const char * filename , mode_t del_mode); + bool util_chmod_if_owner( const char * filename , mode_t new_mode); +#endif + +#ifdef HAVE_PROC + bool util_proc_alive(pid_t pid); +#endif + + int util_forward_line(FILE * , bool * ); + void util_rewind_line(FILE *); + int util_count_content_file_lines(FILE * ); + int util_count_file_lines(FILE * ); + FILE * util_mkdir_fopen( const char * filename , const char * mode ); + int util_fmove( FILE * stream , long offset , long shift); + FILE * util_fopen(const char * , const char *); + void util_fclose( FILE * stream ); + bool util_fopen_test(const char *, const char *); + void util_alloc_file_components(const char * , char ** , char **, char **); + //char * util_realloc_full_path(char * , const char *, const char *); + char * util_alloc_tmp_file(const char * , const char * , bool ); + char * util_fscanf_alloc_line(FILE *, bool *); + char * util_fscanf_realloc_line(FILE *, bool * , char *); + char * util_fscanf_alloc_token(FILE * ); + void util_fskip_token(FILE * ); + void util_fskip_space(FILE * , bool *); + void util_fskip_chars(FILE * , const char * , bool *); + void util_fskip_cchars(FILE * , const char * , bool *); + bool util_fscanf_int(FILE * , int * ); + bool util_fscanf_bool(FILE * stream , bool * value); + bool util_sscanf_bool(const char * , bool *); + bool util_sscanf_octal_int(const char * buffer , unsigned int * value); + int util_strcmp_int( const char * s1 , const char * s2); + int util_strcmp_float( const char * s1 , const char * s2); + bool util_sscanf_int(const char * , int * ); + const char * util_parse_int(const char * , int * , bool *); + const char * util_skip_sep(const char * , const char * , bool *); + int util_scanf_int_with_limits(const char * , int , int , int ); + char * util_scanf_int_with_limits_return_char(const char * , int , int , int ); + void util_printf_prompt(const char * , int , char , const char *); + int util_scanf_int(const char * , int); + char * util_scanf_int_return_char(const char * , int); + double util_scanf_double(const char * prompt , int prompt_len); + char * util_scanf_alloc_string(const char * ); + bool util_sscanf_double(const char * , double * ); + //char * util_alloc_full_path(const char *, const char *); + char * util_alloc_filename(const char * , const char * , const char * ); + char * util_realloc_filename(char * , const char * , const char * , const char * ); + char * util_alloc_strip_copy(const char *); + char * util_realloc_strip_copy(char *); + void util_set_strip_copy(char * , const char *); + char * util_alloc_string_sum(const char ** , int); + char * util_strcat_realloc(char *, const char * ); + char * util_alloc_string_copy(const char *); + char ** util_stringlist_append_copy(char ** , int , const char * ); + char ** util_stringlist_append_ref(char ** , int , const char * ); + char ** util_alloc_stringlist_copy(const char **, int ); + void util_split_string(const char *, const char *, int *, char ***); + void util_path_split(const char * , int *, char ***); + void util_binary_split_string(const char * , const char * , bool , char ** , char ** ); + char * util_alloc_joined_string(const char ** , int , const char * ); + char * util_alloc_multiline_string(const char ** , int ); + char * util_string_replace_alloc(const char *, const char *, const char *); + char * util_string_replacen_alloc(const char *, int , const char ** , const char **); + int util_string_replace_inplace(char ** , const char * , const char *); + char * util_string_strip_chars_alloc(const char *, const char * ); + char * util_realloc_string_copy(char * , const char *); + char * util_realloc_substring_copy(char * , const char *, int ); + char * util_realloc_dequoted_string(char *); + char * util_alloc_dequoted_copy(const char *s); + void util_safe_free(void *); + void util_free_stringlist(char **, int ); + char * util_alloc_substring_copy(const char *, int ); + bool util_is_directory(const char * ); + bool util_is_file(const char * ); + void util_set_datetime_values(time_t , int * , int * , int * , int * , int * , int *); + void util_set_date_values(time_t , int * , int * , int * ); + + + void util_fread_from_buffer(void * , size_t , size_t , char ** ); + + unsigned int util_clock_seed( ); + void util_fread_dev_random(int , char * ); + void util_fread_dev_urandom(int , char * ); + char * util_alloc_string_copy(const char *); + void util_enkf_unlink_ensfiles(const char *, const char *, int , bool ); + bool util_string_isspace(const char * s); + + void util_exit(const char * fmt , ...); + void util_abort(const char * fmt , ...); + void util_abort_signal(int ); + void util_abort_append_version_info(const char * ); + void util_abort_free_version_info(); + void util_abort_set_executable( const char * executable ); + void * util_realloc(void * , size_t , const char * ); + void * util_malloc(size_t , const char * ); + void * util_realloc_copy(void * org_ptr , const void * src , size_t byte_size , const char * caller); + void * util_alloc_copy(const void * , size_t , const char * ); + void util_double_to_float(float * , const double * , int ); + void util_float_to_double(double * , const float * , int ); + + int util_get_month_nr(const char * ); + + char * util_fread_alloc_file_content(const char * , int *); + void util_fwrite_string(const char * , FILE *); + char * util_fread_realloc_string(char * , FILE *); + char * util_fread_alloc_string(FILE *); + void util_fskip_string(FILE *stream); + void util_endian_flip_vector(void *, int , int ); + int util_proc_mem_free(void); + + + void util_apply_int_limits(int * , int , int ); + void util_apply_float_limits(float * , float , float ); + void util_apply_double_limits(double * , double , double ); + double util_double_vector_mean(int , const double * ); + double util_double_vector_stddev(int , const double * ); + void util_double_vector_max_min(int , const double *, double * , double *); + void util_update_double_max_min(double , double * , double * ); + void util_update_float_max_min(float , float * , float * ); + void util_update_int_max_min(int , int * , int * ); + float util_float_max (float , float ); + long int util_long_max(long int a , long int b); + int util_int_max (int , int); + double util_double_max(double , double ); + float util_float_min (float , float ); + int util_int_min (int , int); + size_t util_size_t_min(size_t a , size_t b); + size_t util_size_t_max(size_t a , size_t b); + time_t util_time_t_min(time_t a , time_t b); + time_t util_time_t_max(time_t a , time_t b); + double util_double_min(double , double ); + void util_fskip_lines(FILE * , int); + bool util_same_file(const char * , const char * ); + void util_read_path(const char * , int , bool , char * ); + char * util_fscanf_alloc_filename(const char * , int , int); + void util_read_string(const char * , int , char * ); + void util_fread (void *, size_t , size_t , FILE * , const char * ); + void util_fwrite(const void *, size_t , size_t , FILE * , const char * ); + time_t util_fread_time_t(FILE * stream); + int util_fread_int(FILE * ); + long util_fread_long(FILE * ); + bool util_fread_bool(FILE * ); + double util_fread_double(FILE * stream); + void util_fwrite_int (int , FILE * ); + void util_fwrite_long (long , FILE * ); + void util_fwrite_bool (bool , FILE * ); + void util_fwrite_time_t (time_t , FILE * ); + void util_fwrite_double(double , FILE * ); + void util_fwrite_int_vector (const int * , int , FILE * , const char * ); + void util_fwrite_double_vector(const double * , int , FILE * , const char * ); + void util_fread_char_vector(char * , int , FILE * , const char * ); + int util_type_get_id( const void * data ); + + + + void util_block_growing_file(const char * ); + void util_block_growing_directory(const char * ); + char * util_alloc_realpath(const char * ); + bool util_sscanf_bytesize(const char * , size_t *); + void util_sscanf_active_range(const char * , int , bool * ); + int * util_sscanf_alloc_active_list(const char * , int * ); + int util_get_current_linenr(FILE * stream); + const char * util_update_path_var(const char * , const char * , bool ); + + + int util_get_type( void * data ); + void util_fskip_int(FILE * stream); + void util_fskip_long(FILE * stream); + void util_fskip_bool(FILE * stream); + bool util_fseek_string(FILE * stream , const char * string , bool skip_string , bool case_sensitive); + char * util_fscanf_alloc_upto(FILE * stream , const char * stop_string, bool include_stop_string); + bool util_files_equal( const char * file1 , const char * file2 ); + double util_kahan_sum(const double *data, size_t N); + int util_fnmatch( const char * pattern , const char * string ); + void util_localtime( time_t * t , struct tm * ts ); + + char * util_alloc_PATH_executable(const char * executable ); + char * util_isscanf_alloc_envvar( const char * string , int env_index ); + void util_setenv( const char * variable , const char * value); + const char * util_interp_setenv( const char * variable , const char * value); + void util_unsetenv( const char * variable); + char * util_alloc_envvar( const char * value ); + bool util_is_link(const char * ); // Will always return false on windows + +#define UTIL_FWRITE_SCALAR(s,stream) { if (fwrite(&s , sizeof s , 1 , stream) != 1) util_abort("%s: write failed: %s\n",__func__ , strerror(errno)); } +#define UTIL_FREAD_SCALAR(s,stream) { if (fread(&s , sizeof s , 1 , stream) != 1) util_abort("%s: read failed: %s\n",__func__ , strerror(errno)); } + +#define UTIL_FWRITE_VECTOR(s,n,stream) { if (fwrite(s , sizeof s , (n) , stream) != (n)) util_abort("%s: write failed: %s \n",__func__ , strerror(errno)); } +#define UTIL_FREAD_VECTOR(s,n,stream) { if (fread(s , sizeof s , (n) , stream) != (n)) util_abort("%s: read failed: %s \n",__func__ , strerror(errno)); } + +#define CONTAINS_HEADER(TYPE) int util_sorted_contains_ ## TYPE(const TYPE * data , int size , TYPE value); + CONTAINS_HEADER(int); + CONTAINS_HEADER(time_t); + CONTAINS_HEADER(size_t); +#undef CONTAINS_HEADER + +/*****************************************************************/ +/* + The code below here is a simple functionality to support 'enum + introspection'; the point is that when calling the library functions + from Python/ctypes it is very valuable to have access to the enum + values from the Python side. The enum defintions is just used during + the compile phase, and then subsequently dropped. It is therefor + impossible to determine enum values by inspecting the resulting + object files. + + The approach which has been chosen is that each of the enums which + should support 'introspection' from Python should have a function: + + const char * _iget(int index, int * value) { + ... + } + + which should take an enum element number as input argument and + return a string representation of the corresponding enum element and + also update the value reference to contain the corresponding enum + value. If index is out of range the function should return NULL and + also set value to -1. The python layer can then create an integer + variable with the correct name and value in the calling module. + + The util_enum_element_type and the util_enum_iget() function are + convenience functions which can be used to avoid indirectly + repeating the enum definition in the _iget() function. + + In the example below we create the enum definition in normal way in + the header file, and then in addition we repeat the defintion in a + #define a symbol which is used as argument in the _iget() + function: + + + header_file: + ------------ + enum my_enum { + INVALID = 0, + VALUE1 = 2, + VALUE2 = 17 + } + + // The enum definition is repeated; but at at least at the very same spot of the code. + + #define MY_ENUM_DEF { .value = INVALID, .name="INVALID"} , {.value = VALUE1 , .name="VALUE1"} , {.value = VALUE2 , .name="VALUE2"} + #define MY_ENUM_SIZE 3 + + + source file: + ------------ + + const char * my_enum_iget(int index, int * value) { + return util_enum_iget( index , MY_ENUM_SIZE , (const util_enum_element_type []) MY_ENUM_DEF , value); + } + +*/ + + +typedef struct { + int value; + const char * name; +} util_enum_element_type; + +const char * util_enum_iget( int index , int size , const util_enum_element_type * enum_defs , int * value); + + +/*****************************************************************/ +/* Conditional section below here */ + +#ifdef HAVE_ZLIB + void util_compress_buffer(const void * , int , void * , unsigned long * ); + int util_fread_sizeof_compressed(FILE * stream); + void util_fread_compressed(void * , FILE * ); + void * util_fread_alloc_compressed(FILE * ); + void util_fwrite_compressed(const void * , int , FILE * ); +#endif + +#ifdef HAVE_SYMLINK + void util_make_slink(const char *, const char * ); + char * util_alloc_link_target(const char * link); + #ifdef HAVE_READLINKAT + char * util_alloc_atlink_target(const char * path , const char * link); + #endif +#endif + +#ifdef HAVE_FORK +#include "util_fork.h" +#endif + + +#ifdef HAVE_LOCKF + FILE * util_fopen_lockf(const char * , const char * ); + bool util_try_lockf(const char * , mode_t , int * ); +#endif + + + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/util/include/vector.h b/ThirdParty/Ert-windows/util/include/vector.h new file mode 100644 index 0000000000..6a405858de --- /dev/null +++ b/ThirdParty/Ert-windows/util/include/vector.h @@ -0,0 +1,84 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'vector.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __VECTOR_H__ +#define __VECTOR_H__ + +#ifdef __cplusplus +extern "C" { +#endif +#include + +typedef void ( vector_func_type ) (void * , void *); +typedef int ( vector_cmp_ftype) (const void * , const void *); + +typedef struct vector_struct vector_type; + + + +vector_type * vector_alloc_new(); +vector_type * vector_alloc_NULL_initialized( int size ); + +int vector_append_ref( vector_type * , const void *); +int vector_append_owned_ref( vector_type * , const void * , free_ftype * del); +int vector_append_copy(vector_type * , const void *, copyc_ftype *, free_ftype *); + +void vector_iset_ref( vector_type * , int , const void *); +void vector_iset_owned_ref( vector_type * , int , const void * , free_ftype * del); +void vector_iset_copy(vector_type * , int , const void *, copyc_ftype *, free_ftype *); + +void vector_safe_iset_copy(vector_type * vector , int index , const void * data, copyc_ftype * copyc , free_ftype * del); +void vector_safe_iset_owned_ref(vector_type * vector , int index , const void * data, free_ftype * del); +void vector_safe_iset_ref(vector_type * vector , int index , const void * data); + +void vector_insert_ref( vector_type * , int , const void *); +void vector_insert_owned_ref( vector_type * , int , const void * , free_ftype * del); +void vector_insert_copy(vector_type * , int , const void *, copyc_ftype *, free_ftype *); +void vector_insert_buffer(vector_type * vector , int index , const void * buffer, int buffer_size); + +void vector_push_ref( vector_type * , const void *); +void vector_push_owned_ref( vector_type * , const void * , free_ftype * del); +void vector_push_copy(vector_type * , const void *, copyc_ftype *, free_ftype *); + + +void vector_clear(vector_type * vector); +void vector_free(vector_type * ); +void vector_free__( void * arg ); +void vector_append_buffer(vector_type * , const void * , int); +void vector_push_buffer(vector_type * , const void * , int); +int vector_get_size(const vector_type * ); +void * vector_safe_iget(const vector_type * vector, int index); +const void * vector_safe_iget_const(const vector_type * vector, int index); +const void * vector_iget_const(const vector_type * , int ); +void * vector_iget(const vector_type * , int ); +void vector_idel(vector_type * vector , int index); +void vector_shrink( vector_type * vector , int new_size ); +void * vector_get_last(const vector_type * ); +const void * vector_get_last_const(const vector_type * ); +int vector_get_size( const vector_type * ); +void * vector_pop(vector_type * ); +void vector_sort(vector_type * vector , vector_cmp_ftype * cmp); +vector_type * vector_alloc_copy(const vector_type * src , bool deep_copy); + +void vector_iset_buffer(vector_type * vector , int index , const void * buffer, int buffer_size); + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/util/lib/libutil.a b/ThirdParty/Ert-windows/util/lib/libutil.a new file mode 100644 index 0000000000..ec567dc55f Binary files /dev/null and b/ThirdParty/Ert-windows/util/lib/libutil.a differ diff --git a/ThirdParty/Ert-windows/util/lib/libutil.dll b/ThirdParty/Ert-windows/util/lib/libutil.dll new file mode 100644 index 0000000000..79fbc86cf0 Binary files /dev/null and b/ThirdParty/Ert-windows/util/lib/libutil.dll differ diff --git a/ThirdParty/Ert-windows/util/lib/libutil.dll.a b/ThirdParty/Ert-windows/util/lib/libutil.dll.a new file mode 100644 index 0000000000..f271cbaa4a Binary files /dev/null and b/ThirdParty/Ert-windows/util/lib/libutil.dll.a differ diff --git a/ThirdParty/Ert-windows/util/lib/libutil.lib b/ThirdParty/Ert-windows/util/lib/libutil.lib new file mode 100644 index 0000000000..3d5cb35c29 Binary files /dev/null and b/ThirdParty/Ert-windows/util/lib/libutil.lib differ diff --git a/ThirdParty/Ert-windows/well/include/well_branch.h b/ThirdParty/Ert-windows/well/include/well_branch.h new file mode 100644 index 0000000000..773a68c02d --- /dev/null +++ b/ThirdParty/Ert-windows/well/include/well_branch.h @@ -0,0 +1,42 @@ +/* + Copyright (C) 2012 Statoil ASA, Norway. + + The file 'well_branch.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __WELL_BRANCH_H__ +#define __WELL_BRANCH_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +#include + + typedef struct well_branch_struct well_branch_type; + + well_branch_type * well_branch_alloc(int branch_nr); + void well_branch_free( well_branch_type * branch ); + void well_branch_add_conn( well_branch_type * branch , const well_conn_type * connection ); + int well_branch_get_length( const well_branch_type * branch ); + const well_conn_type ** well_branch_get_connections( const well_branch_type * branch ); + int well_branch_get_nr( const well_branch_type * branch ); + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/ThirdParty/Ert-windows/well/include/well_conn.h b/ThirdParty/Ert-windows/well/include/well_conn.h new file mode 100644 index 0000000000..d6321909aa --- /dev/null +++ b/ThirdParty/Ert-windows/well/include/well_conn.h @@ -0,0 +1,69 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'well_conn.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#ifndef __WELL_CONN_H__ +#define __WELL_CONN_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include +#include + + typedef enum { + well_conn_dirX = 1, + well_conn_dirY = 2, + well_conn_dirZ = 3, + well_conn_fracX = 4, + well_conn_fracY = 5 + } well_conn_dir_enum; + + + + /* + Observe that when the (ijk) values are initialized they are + shifted to zero offset values, to be aligned with the rest of the + ert libraries. + */ + + typedef struct { + int i; + int j; + int k; + int branch; + int segment; // -1: Ordinary well + bool open; + well_conn_dir_enum dir; + } well_conn_type; + + + + void well_conn_free( well_conn_type * conn); + void well_conn_free__( void * arg ); + well_conn_type * well_conn_alloc( const ecl_kw_type * icon_kw , const ecl_kw_type * iseg_kw , const ecl_intehead_type * header , int well_nr , int seg_well_nr , int conn_nr); + well_conn_type * well_conn_alloc_wellhead( const ecl_kw_type * iwel_kw , const ecl_intehead_type * header , int well_nr); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert-windows/well/include/well_const.h b/ThirdParty/Ert-windows/well/include/well_const.h new file mode 100644 index 0000000000..a73809f583 --- /dev/null +++ b/ThirdParty/Ert-windows/well/include/well_const.h @@ -0,0 +1,90 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'well_const.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#ifndef __WELL_CONST_H__ +#define __WELL_CONST_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + Observe that the values given as _ITEM are not indices which can + be directly used in the IWEL or ICON keywords; an offset must be + added. +*/ + +#define IWEL_HEADI_ITEM 0 +#define IWEL_HEADJ_ITEM 1 +#define IWEL_HEADK_ITEM 2 +#define IWEL_CONNECTIONS_ITEM 4 +#define IWEL_TYPE_ITEM 6 +#define IWEL_STATUS_ITEM 10 +#define IWEL_LGR_ITEM 42 +#define IWEL_SEGMENTED_WELL_NR_ITEM 70 + +#define ISEG_BRANCH_ITEM 3 + +#define ICON_IC_ITEM 0 +#define ICON_I_ITEM 1 +#define ICON_J_ITEM 2 +#define ICON_K_ITEM 3 +#define ICON_STATUS_ITEM 5 +#define ICON_DIRECTION_ITEM 13 +#define ICON_SEGMENT_ITEM 14 + +#define ICON_DIRX 1 +#define ICON_DIRY 2 +#define ICON_DIRZ 3 +#define ICON_FRACX 4 +#define ICON_FRACY 5 +#define ICON_DEFAULT_DIR_VALUE 0 +#define ICON_DEFAULT_DIR_TARGET ICON_DIRZ + + +/* + The ECLIPSE documentation says that a certain item in the IWEL array + should indicate the type of the well, the available types are the + ones given in the enum below. Unfortunately it turns out that when + the well is closed the integer value in the IWEL array can be 0, if + the well is indeed closed we accept this zero - otherwise we fail + hard. Theese hoops are in the well_state_alloc() routine. +*/ + +#define IWEL_UNDOCUMENTED_ZERO 0 +#define IWEL_PRODUCER 1 +#define IWEL_OIL_INJECTOR 2 +#define IWEL_WATER_INJECTOR 3 +#define IWEL_GAS_INJECTOR 4 + + typedef enum { + UNDOCUMENTED_ZERO = 0, + PRODUCER = 10, + WATER_INJECTOR = 22, + GAS_INJECTOR = 21, + OIL_INJECTOR = 78 + } well_type_enum; + + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/ThirdParty/Ert-windows/well/include/well_info.h b/ThirdParty/Ert-windows/well/include/well_info.h new file mode 100644 index 0000000000..246b52ebcf --- /dev/null +++ b/ThirdParty/Ert-windows/well/include/well_info.h @@ -0,0 +1,52 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'well_info.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __WELL_INFO_H__ +#define __WELL_INFO_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + + typedef struct well_info_struct well_info_type; + + well_info_type * well_info_alloc(const ecl_grid_type * grid); + void well_info_add_UNRST_wells( well_info_type * well_info , ecl_file_type * rst_file); + void well_info_add_wells( well_info_type * well_info , ecl_file_type * rst_file , int report_nr ); + void well_info_load_rstfile( well_info_type * well_info , const char * filename); + void well_info_free( well_info_type * well_info ); + + well_ts_type * well_info_get_ts( const well_info_type * well_info , const char *well_name); + int well_info_get_num_wells( const well_info_type * well_info ); + const char * well_info_iget_well_name( const well_info_type * well_info, int well_index); + + well_state_type * well_info_get_state_from_time( const well_info_type * well_info , const char * well_name , time_t sim_time); + well_state_type * well_info_get_state_from_report( const well_info_type * well_info , const char * well_name , int report_step ); + well_state_type * well_info_iget_state_from_report( const well_info_type * well_info , const char * well_name , int time_index); + well_state_type * well_info_iiget_state( const well_info_type * well_info , int well_index , int time_index); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/ThirdParty/Ert-windows/well/include/well_path.h b/ThirdParty/Ert-windows/well/include/well_path.h new file mode 100644 index 0000000000..0b10f3322a --- /dev/null +++ b/ThirdParty/Ert-windows/well/include/well_path.h @@ -0,0 +1,47 @@ +/* + Copyright (C) 2012 Statoil ASA, Norway. + + The file 'well_path.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __WELL_PATH_H__ +#define __WELL_PATH_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + + + typedef struct well_path_struct well_path_type; + + well_path_type * well_path_alloc(const char * grid_name ); + void well_path_free( well_path_type * path ); + void well_path_add_conn( well_path_type * well_path , well_conn_type * conn); + well_branch_type * well_path_iget_branch( const well_path_type * well_path , int branch_nr); + void well_path_free__(void * arg); + int well_path_get_max_branches( const well_path_type * well_path ); + int well_path_get_num_active_branches( const well_path_type * well_path ); + const char * well_path_get_grid_name( const well_path_type * well_path ); + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/ThirdParty/Ert-windows/well/include/well_state.h b/ThirdParty/Ert-windows/well/include/well_state.h new file mode 100644 index 0000000000..82a936b8af --- /dev/null +++ b/ThirdParty/Ert-windows/well/include/well_state.h @@ -0,0 +1,73 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'well_state.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#ifndef __WELL_STATE_H__ +#define __WELL_STATE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include +#include + +#include +#include + + +#define GLOBAL_GRID_NAME "GLOBAL" // The name assigned to the global grid for name based lookup. + + typedef struct well_state_struct well_state_type; + + well_state_type * well_state_alloc( ecl_file_type * ecl_file , int report_step , int well_nr); + void well_state_free( well_state_type * well ); + const char * well_state_get_name( const well_state_type * well ); + int well_state_get_report_nr( const well_state_type * well_state ); + time_t well_state_get_sim_time( const well_state_type * well_state ); + well_conn_type * well_state_iget_connection( const well_state_type * well_state , int index); + well_type_enum well_state_get_type( const well_state_type * well_state); + bool well_state_is_open( const well_state_type * well_state ); + + const well_conn_type * well_state_iget_wellhead( const well_state_type * well_state , int grid_nr); + const well_conn_type * well_state_get_wellhead( const well_state_type * well_state , const char * grid_name); + + + const well_conn_type ** well_state_iget_lgr_connections(const well_state_type * well_state , int grid_nr , int branch_nr ); + const well_conn_type ** well_state_get_lgr_connections(const well_state_type * well_state , const char * lgr_name , int branch_nr); + const well_conn_type ** well_state_get_connections(const well_state_type * well_state , int branch_nr ); + + int well_state_iget_num_lgr_connections(const well_state_type * well_state , int grid_nr , int branch_nr ); + int well_state_get_num_lgr_connections(const well_state_type * well_state , const char * lgr_name , int branch_nr); + int well_state_get_num_connections(const well_state_type * well_state , int branch_nr ); + + int well_state_iget_lgr_num_branches( const well_state_type * well_state , int grid_nr); + int well_state_get_lgr_num_branches( const well_state_type * well_state , const char * lgr_name); + int well_state_get_num_branches(const well_state_type * well_state ); + + void well_state_summarize( const well_state_type * well_state , FILE * stream ); + + UTIL_IS_INSTANCE_HEADER( well_state ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/ThirdParty/Ert-windows/well/include/well_ts.h b/ThirdParty/Ert-windows/well/include/well_ts.h new file mode 100644 index 0000000000..69b56aa8cc --- /dev/null +++ b/ThirdParty/Ert-windows/well/include/well_ts.h @@ -0,0 +1,48 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'well_ts.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#ifndef __WELL_TS_H__ +#define __WELL_TS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + + + typedef struct well_ts_struct well_ts_type; + + void well_ts_free( well_ts_type * well_ts ); + void well_ts_add_well( well_ts_type * well_ts , well_state_type * well_state ); + well_ts_type * well_ts_alloc( const char * well_name ); + void well_ts_free__( void * arg ); + well_state_type * well_ts_get_state_from_sim_time( const well_ts_type * well_ts , time_t sim_time); + well_state_type * well_ts_get_state_from_report( const well_ts_type * well_ts , int report_nr); + well_state_type * well_ts_iget_state( const well_ts_type * well_ts , int index); + int well_ts_get_size( const well_ts_type * well_ts); + + well_state_type * well_ts_get_first_state( const well_ts_type * well_ts); + well_state_type * well_ts_get_last_state( const well_ts_type * well_ts); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/ThirdParty/Ert-windows/well/lib/libwell.a b/ThirdParty/Ert-windows/well/lib/libwell.a new file mode 100644 index 0000000000..a8658f3761 Binary files /dev/null and b/ThirdParty/Ert-windows/well/lib/libwell.a differ diff --git a/ThirdParty/Ert-windows/well/lib/libwell.dll b/ThirdParty/Ert-windows/well/lib/libwell.dll new file mode 100644 index 0000000000..0988339eb2 Binary files /dev/null and b/ThirdParty/Ert-windows/well/lib/libwell.dll differ diff --git a/ThirdParty/Ert-windows/well/lib/libwell.dll.a b/ThirdParty/Ert-windows/well/lib/libwell.dll.a new file mode 100644 index 0000000000..b8ba6bc05f Binary files /dev/null and b/ThirdParty/Ert-windows/well/lib/libwell.dll.a differ diff --git a/ThirdParty/Ert-windows/well/lib/libwell.lib b/ThirdParty/Ert-windows/well/lib/libwell.lib new file mode 100644 index 0000000000..dd713a1843 Binary files /dev/null and b/ThirdParty/Ert-windows/well/lib/libwell.lib differ diff --git a/ThirdParty/Ert/ecl/include/ecl_file.h b/ThirdParty/Ert/ecl/include/ecl_file.h index 6290184d68..8c57f0cd85 100644 --- a/ThirdParty/Ert/ecl/include/ecl_file.h +++ b/ThirdParty/Ert/ecl/include/ecl_file.h @@ -106,7 +106,7 @@ extern "C" { ecl_file_type * ecl_file_open_smryblock( const char * filename , int ministep_nr ); -UTIL_IS_INSTANCE_HEADER( ecl_file ) + UTIL_IS_INSTANCE_HEADER( ecl_file ); #ifdef __cplusplus } diff --git a/ThirdParty/Ert/ecl/include/ecl_grav_common.h b/ThirdParty/Ert/ecl/include/ecl_grav_common.h new file mode 100644 index 0000000000..d95ac487c7 --- /dev/null +++ b/ThirdParty/Ert/ecl/include/ecl_grav_common.h @@ -0,0 +1,38 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_grav_common.h' is part of ERT - Ensemble based + Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __ECL_GRAV_COMMON_H__ +#define __ECL_GRAV_COMMON_H__ + +#ifdef __cplusplus +extern "C" { +#endif +#include + +#include +#include + + bool * ecl_grav_common_alloc_aquifer_cell( const ecl_grid_cache_type * grid_cache , const ecl_file_type * init_file); + double ecl_grav_common_eval_biot_savart( const ecl_grid_cache_type * grid_cache , ecl_region_type * region , const bool * aquifer , const double * weight , double utm_x , double utm_y , double depth); + +#ifdef __cplusplus +} + +#endif +#endif diff --git a/ThirdParty/Ert/ecl/include/ecl_grid.h b/ThirdParty/Ert/ecl/include/ecl_grid.h index 22f0c70dfa..a1865e0fc8 100644 --- a/ThirdParty/Ert/ecl/include/ecl_grid.h +++ b/ThirdParty/Ert/ecl/include/ecl_grid.h @@ -22,124 +22,130 @@ extern "C" { #endif #include + #include #include -#include #include -//typedef enum { -// NO_HINT = 0, -// NORTH = 1, -// CENTRAL = 2, -// SOUTH = 4, -// +#include + + + typedef double (block_function_ftype) ( const double_vector_type *); + typedef struct ecl_grid_struct ecl_grid_type; + + void ecl_grid_get_column_property(const ecl_grid_type * ecl_grid , const ecl_kw_type * ecl_kw , int i , int j, double_vector_type * column); + int ecl_grid_get_global_index_from_xy_top( const ecl_grid_type * ecl_grid , double x , double y); + int ecl_grid_get_global_index_from_xy_bottom( const ecl_grid_type * ecl_grid , double x , double y); + + void ecl_grid_get_corner_xyz3(const ecl_grid_type * grid , int i , int j , int k, int corner_nr , double * xpos , double * ypos , double * zpos ); + void ecl_grid_get_corner_xyz1(const ecl_grid_type * grid , int global_index , int corner_nr , double * xpos , double * ypos , double * zpos ); + + double ecl_grid_get_cell_thickness3( const ecl_grid_type * grid , int i , int j , int k); + double ecl_grid_get_cell_thickness1( const ecl_grid_type * grid , int global_index ); + double ecl_grid_get_cdepth1(const ecl_grid_type * grid , int global_index); + double ecl_grid_get_cdepth3(const ecl_grid_type * grid , int i, int j , int k); + double ecl_grid_get_depth3(const ecl_grid_type * grid , int i, int j , int k); + int ecl_grid_get_global_index_from_xy( const ecl_grid_type * ecl_grid , int k , bool lower_layer , double x , double y); + bool ecl_grid_cell_contains_xyz1( const ecl_grid_type * ecl_grid , int global_index , double x , double y , double z); + bool ecl_grid_cell_contains_xyz3( const ecl_grid_type * ecl_grid , int i , int j , int k, double x , double y , double z ); + double ecl_grid_get_cell_volume1( const ecl_grid_type * ecl_grid, int global_index ); + double ecl_grid_get_cell_volume3( const ecl_grid_type * ecl_grid, int i , int j , int k); + bool ecl_grid_cell_contains1(const ecl_grid_type * grid , int global_index , double x , double y , double z); + bool ecl_grid_cell_contains3(const ecl_grid_type * grid , int i , int j ,int k , double x , double y , double z); + int ecl_grid_get_global_index_from_xyz(ecl_grid_type * grid , double x , double y , double z , int start_index); + const char * ecl_grid_get_name( const ecl_grid_type * ); + int ecl_grid_get_active_index3(const ecl_grid_type * ecl_grid , int i , int j , int k); + int ecl_grid_get_active_index1(const ecl_grid_type * ecl_grid , int global_index); + bool ecl_grid_cell_active3(const ecl_grid_type * , int , int , int ); + bool ecl_grid_cell_active1(const ecl_grid_type * , int); + bool ecl_grid_ijk_valid(const ecl_grid_type * , int , int , int ); + int ecl_grid_get_global_index3(const ecl_grid_type * , int , int , int ); + int ecl_grid_get_global_index1A(const ecl_grid_type * ecl_grid , int active_index); + ecl_grid_type * ecl_grid_alloc_GRDECL_kw( int nx, int ny , int nz , const ecl_kw_type * zcorn_kw , const ecl_kw_type * coord_kw , const ecl_kw_type * actnum_kw , const ecl_kw_type * mapaxes_kw ); + ecl_grid_type * ecl_grid_alloc_GRDECL_data(int , int , int , const float * , const float * , const int * , const float * mapaxes); + ecl_grid_type * ecl_grid_alloc_GRID_data(int num_coords , int nx, int ny , int nz , int coords_size , int ** coords , float ** corners , const float * mapaxes); + ecl_grid_type * ecl_grid_alloc(const char * ); + ecl_grid_type * ecl_grid_load_case( const char * case_input ); + bool ecl_grid_exists( const char * case_input ); + char * ecl_grid_alloc_case_filename( const char * case_input ); + + void ecl_grid_free(ecl_grid_type * ); + void ecl_grid_free__( void * arg ); + void ecl_grid_get_dims(const ecl_grid_type * , int *, int * , int * , int *); + int ecl_grid_get_nz( const ecl_grid_type * grid ); + int ecl_grid_get_nx( const ecl_grid_type * grid ); + int ecl_grid_get_ny( const ecl_grid_type * grid ); + int ecl_grid_get_active_index(const ecl_grid_type * , int , int , int ); + void ecl_grid_summarize(const ecl_grid_type * ); + void ecl_grid_get_ijk1(const ecl_grid_type * , int global_index , int *, int * , int *); + void ecl_grid_get_ijk1A(const ecl_grid_type * , int active_index, int *, int * , int *); + void ecl_grid_get_ijk_from_active_index(const ecl_grid_type *, int , int *, int * , int * ); + void ecl_grid_get_xyz3(const ecl_grid_type * , int , int , int , double * , double * , double *); + void ecl_grid_get_xyz1(const ecl_grid_type * grid , int global_index , double *xpos , double *ypos , double *zpos); + void ecl_grid_get_xyz1A(const ecl_grid_type * grid , int active_index , double *xpos , double *ypos , double *zpos); + int ecl_grid_get_global_size( const ecl_grid_type * ecl_grid ); + bool ecl_grid_compare(const ecl_grid_type * g1 , const ecl_grid_type * g2 , bool include_lgr); + int ecl_grid_get_active_size( const ecl_grid_type * ecl_grid ); + + double ecl_grid_get_bottom1(const ecl_grid_type * grid , int global_index); + double ecl_grid_get_bottom3(const ecl_grid_type * grid , int i, int j , int k); + double ecl_grid_get_bottom1A(const ecl_grid_type * grid , int active_index); + double ecl_grid_get_top1(const ecl_grid_type * grid , int global_index); + double ecl_grid_get_top3(const ecl_grid_type * grid , int i, int j , int k); + double ecl_grid_get_top1A(const ecl_grid_type * grid , int active_index); + double ecl_grid_get_top2(const ecl_grid_type * grid , int i, int j); + double ecl_grid_get_bottom2(const ecl_grid_type * grid , int i, int j); + int ecl_grid_locate_depth( const ecl_grid_type * grid , double depth , int i , int j ); + + void ecl_grid_alloc_blocking_variables(ecl_grid_type * , int ); + void ecl_grid_init_blocking(ecl_grid_type * ); + double ecl_grid_block_eval3d(ecl_grid_type * grid , int i, int j , int k ,block_function_ftype * blockf ); + int ecl_grid_get_block_count3d(const ecl_grid_type * ecl_grid , int i , int j, int k); + bool ecl_grid_block_value_3d(ecl_grid_type * , double , double ,double , double); + + bool ecl_grid_cell_invalid1(const ecl_grid_type * ecl_grid , int global_index); + bool ecl_grid_cell_invalid3(const ecl_grid_type * ecl_grid , int i , int j , int k); + double ecl_grid_cell_invalid1A(const ecl_grid_type * grid , int active_index); + + void ecl_grid_dump(const ecl_grid_type * grid , FILE * stream); + void ecl_grid_dump_ascii(const ecl_grid_type * grid , bool active_only , FILE * stream); + + /* lgr related functions */ + const ecl_grid_type * ecl_grid_get_cell_lgr3(const ecl_grid_type * grid , int i, int j , int k); + const ecl_grid_type * ecl_grid_get_cell_lgr1A(const ecl_grid_type * grid , int active_index); + const ecl_grid_type * ecl_grid_get_cell_lgr1(const ecl_grid_type * grid , int global_index ); + int ecl_grid_get_num_lgr(const ecl_grid_type * main_grid ); + int ecl_grid_get_grid_nr( const ecl_grid_type * ecl_grid ); + ecl_grid_type * ecl_grid_iget_lgr(const ecl_grid_type * main_grid , int lgr_nr); + ecl_grid_type * ecl_grid_get_lgr(const ecl_grid_type * main_grid, const char * __lgr_name); + bool ecl_grid_has_lgr(const ecl_grid_type * main_grid, const char * __lgr_name); + stringlist_type * ecl_grid_alloc_lgr_name_list(const ecl_grid_type * ecl_grid); + int ecl_grid_get_parent_cell1( const ecl_grid_type * grid , int global_index); + int ecl_grid_get_parent_cell3( const ecl_grid_type * grid , int i , int j , int k); + const ecl_grid_type * ecl_grid_get_global_grid( const ecl_grid_type * grid ); + bool ecl_grid_is_lgr( const ecl_grid_type * ecl_grid ); - - -typedef double (block_function_ftype) ( const double_vector_type *); -typedef struct ecl_grid_struct ecl_grid_type; - -void ecl_grid_get_column_property(const ecl_grid_type * ecl_grid , const ecl_kw_type * ecl_kw , int i , int j, double_vector_type * column); -int ecl_grid_get_global_index_from_xy_top( const ecl_grid_type * ecl_grid , double x , double y); -int ecl_grid_get_global_index_from_xy_bottom( const ecl_grid_type * ecl_grid , double x , double y); - -void ecl_grid_get_corner_xyz3(const ecl_grid_type * grid , int i , int j , int k, int corner_nr , double * xpos , double * ypos , double * zpos ); -void ecl_grid_get_corner_xyz1(const ecl_grid_type * grid , int global_index , int corner_nr , double * xpos , double * ypos , double * zpos ); - -double ecl_grid_get_cell_thickness3( const ecl_grid_type * grid , int i , int j , int k); -double ecl_grid_get_cell_thickness1( const ecl_grid_type * grid , int global_index ); -double ecl_grid_get_cdepth1(const ecl_grid_type * grid , int global_index); -double ecl_grid_get_cdepth3(const ecl_grid_type * grid , int i, int j , int k); -double ecl_grid_get_depth3(const ecl_grid_type * grid , int i, int j , int k); -int ecl_grid_get_global_index_from_xy( const ecl_grid_type * ecl_grid , int k , bool lower_layer , double x , double y); -bool ecl_grid_cell_contains_xyz1( const ecl_grid_type * ecl_grid , int global_index , double x , double y , double z); -bool ecl_grid_cell_contains_xyz3( const ecl_grid_type * ecl_grid , int i , int j , int k, double x , double y , double z ); -double ecl_grid_get_cell_volume1( const ecl_grid_type * ecl_grid, int global_index ); -double ecl_grid_get_cell_volume3( const ecl_grid_type * ecl_grid, int i , int j , int k); -bool ecl_grid_cell_contains1(const ecl_grid_type * grid , int global_index , double x , double y , double z); -bool ecl_grid_cell_contains3(const ecl_grid_type * grid , int i , int j ,int k , double x , double y , double z); -int ecl_grid_get_global_index_from_xyz(ecl_grid_type * grid , double x , double y , double z , int start_index); -const char * ecl_grid_get_name( const ecl_grid_type * ); -int ecl_grid_get_active_index3(const ecl_grid_type * ecl_grid , int i , int j , int k); -int ecl_grid_get_active_index1(const ecl_grid_type * ecl_grid , int global_index); -bool ecl_grid_cell_active3(const ecl_grid_type * , int , int , int ); -bool ecl_grid_cell_active1(const ecl_grid_type * , int); -bool ecl_grid_ijk_valid(const ecl_grid_type * , int , int , int ); -int ecl_grid_get_global_index3(const ecl_grid_type * , int , int , int ); -int ecl_grid_get_global_index1A(const ecl_grid_type * ecl_grid , int active_index); -ecl_grid_type * ecl_grid_alloc_GRDECL_kw( const ecl_kw_type * gridhead_kw , const ecl_kw_type * zcorn_kw , const ecl_kw_type * coord_kw , const ecl_kw_type * actnum_kw , const ecl_kw_type * mapaxes_kw ); -ecl_grid_type * ecl_grid_alloc_GRDECL_data(int , int , int , const float * , const float * , const int * , const float * mapaxes); -ecl_grid_type * ecl_grid_alloc(const char * ); -ecl_grid_type * ecl_grid_load_case( const char * case_input ); -bool ecl_grid_exists( const char * case_input ); -char * ecl_grid_alloc_case_filename( const char * case_input ); - -void ecl_grid_free(ecl_grid_type * ); -void ecl_grid_free__( void * arg ); -void ecl_grid_get_dims(const ecl_grid_type * , int *, int * , int * , int *); -int ecl_grid_get_nz( const ecl_grid_type * grid ); -int ecl_grid_get_nx( const ecl_grid_type * grid ); -int ecl_grid_get_ny( const ecl_grid_type * grid ); -int ecl_grid_get_active_index(const ecl_grid_type * , int , int , int ); -void ecl_grid_summarize(const ecl_grid_type * ); -void ecl_grid_get_ijk1(const ecl_grid_type * , int global_index , int *, int * , int *); -void ecl_grid_get_ijk1A(const ecl_grid_type * , int active_index, int *, int * , int *); -void ecl_grid_get_ijk_from_active_index(const ecl_grid_type *, int , int *, int * , int * ); -void ecl_grid_get_xyz3(const ecl_grid_type * , int , int , int , double * , double * , double *); -void ecl_grid_get_xyz1(const ecl_grid_type * grid , int global_index , double *xpos , double *ypos , double *zpos); -void ecl_grid_get_xyz1A(const ecl_grid_type * grid , int active_index , double *xpos , double *ypos , double *zpos); -int ecl_grid_get_global_size( const ecl_grid_type * ecl_grid ); -bool ecl_grid_compare(const ecl_grid_type * g1 , const ecl_grid_type * g2); -int ecl_grid_get_active_size( const ecl_grid_type * ecl_grid ); - -double ecl_grid_get_bottom1(const ecl_grid_type * grid , int global_index); -double ecl_grid_get_bottom3(const ecl_grid_type * grid , int i, int j , int k); -double ecl_grid_get_bottom1A(const ecl_grid_type * grid , int active_index); -double ecl_grid_get_top1(const ecl_grid_type * grid , int global_index); -double ecl_grid_get_top3(const ecl_grid_type * grid , int i, int j , int k); -double ecl_grid_get_top1A(const ecl_grid_type * grid , int active_index); -double ecl_grid_get_top2(const ecl_grid_type * grid , int i, int j); -double ecl_grid_get_bottom2(const ecl_grid_type * grid , int i, int j); -int ecl_grid_locate_depth( const ecl_grid_type * grid , double depth , int i , int j ); - -void ecl_grid_alloc_blocking_variables(ecl_grid_type * , int ); -void ecl_grid_init_blocking(ecl_grid_type * ); -double ecl_grid_block_eval2d(ecl_grid_type * grid , int i, int j , block_function_ftype * blockf ); -double ecl_grid_block_eval3d(ecl_grid_type * grid , int i, int j , int k ,block_function_ftype * blockf ); -int ecl_grid_get_block_count3d(const ecl_grid_type * ecl_grid , int i , int j, int k); -int ecl_grid_get_block_count2d(const ecl_grid_type * ecl_grid , int i , int j); -bool ecl_grid_block_value_2d(ecl_grid_type * , double , double ,double ); -bool ecl_grid_block_value_3d(ecl_grid_type * , double , double ,double , double); - -bool ecl_grid_cell_invalid1(const ecl_grid_type * ecl_grid , int global_index); -bool ecl_grid_cell_invalid3(const ecl_grid_type * ecl_grid , int i , int j , int k); -double ecl_grid_cell_invalid1A(const ecl_grid_type * grid , int active_index); - -void ecl_grid_dump(const ecl_grid_type * grid , FILE * stream); - -/* lgr related functions */ -const ecl_grid_type * ecl_grid_get_cell_lgr3(const ecl_grid_type * grid , int i, int j , int k); -const ecl_grid_type * ecl_grid_get_cell_lgr1A(const ecl_grid_type * grid , int active_index); -const ecl_grid_type * ecl_grid_get_cell_lgr1(const ecl_grid_type * grid , int global_index ); -int ecl_grid_get_num_lgr(const ecl_grid_type * main_grid ); -int ecl_grid_get_grid_nr( const ecl_grid_type * ecl_grid ); -ecl_grid_type * ecl_grid_iget_lgr(const ecl_grid_type * main_grid , int lgr_nr); -ecl_grid_type * ecl_grid_get_lgr(const ecl_grid_type * main_grid, const char * __lgr_name); -bool ecl_grid_has_lgr(const ecl_grid_type * main_grid, const char * __lgr_name); -stringlist_type * ecl_grid_alloc_lgr_name_list(const ecl_grid_type * ecl_grid); -int ecl_grid_get_parent_cell1( const ecl_grid_type * grid , int global_index); -int ecl_grid_get_parent_cell3( const ecl_grid_type * grid , int i , int j , int k); -const ecl_grid_type * ecl_grid_get_global_grid( const ecl_grid_type * grid ); -bool ecl_grid_is_lgr( const ecl_grid_type * ecl_grid ); - double ecl_grid_get_property(const ecl_grid_type * ecl_grid , const ecl_kw_type * ecl_kw , int i , int j , int k); float ecl_grid_get_float_property(const ecl_grid_type * ecl_grid , const ecl_kw_type * ecl_kw , int i , int j , int k); double ecl_grid_get_double_property(const ecl_grid_type * ecl_grid , const ecl_kw_type * ecl_kw , int i , int j , int k); int ecl_grid_get_int_property(const ecl_grid_type * ecl_grid , const ecl_kw_type * ecl_kw , int i , int j , int k); + + void ecl_grid_grdecl_fprintf_kw( const ecl_grid_type * ecl_grid , const ecl_kw_type * ecl_kw , FILE * stream , double double_default); + bool ecl_grid_test_lgr_consistency( const ecl_grid_type * ecl_grid ); + + void ecl_grid_fwrite_EGRID( const ecl_grid_type * grid , const char * filename); + void ecl_grid_fwrite_GRID( const ecl_grid_type * grid , const char * filename); + void ecl_grid_fprintf_grdecl( const ecl_grid_type * grid , FILE * stream ); -void ecl_grid_grdecl_fprintf_kw( const ecl_grid_type * ecl_grid , const ecl_kw_type * ecl_kw , FILE * stream , double double_default); -bool ecl_grid_test_lgr_consistency( const ecl_grid_type * ecl_grid ); - + float * ecl_grid_alloc_coord_data( const ecl_grid_type * grid ); + ecl_kw_type * ecl_grid_alloc_coord_kw( const ecl_grid_type * grid ); + float * ecl_grid_alloc_zcorn_data( const ecl_grid_type * grid ); + ecl_kw_type * ecl_grid_alloc_zcorn_kw( const ecl_grid_type * grid ); + int * ecl_grid_alloc_actnum_data( const ecl_grid_type * grid ); + ecl_kw_type * ecl_grid_alloc_actnum_kw( const ecl_grid_type * grid ); + ecl_kw_type * ecl_grid_alloc_hostnum_kw( const ecl_grid_type * grid ); + ecl_kw_type * ecl_grid_alloc_gridhead_kw( int nx, int ny , int nz , int grid_nr); + #ifdef __cplusplus } #endif diff --git a/ThirdParty/Ert/ecl/include/ecl_grid_cache.h b/ThirdParty/Ert/ecl/include/ecl_grid_cache.h new file mode 100644 index 0000000000..407d50a27e --- /dev/null +++ b/ThirdParty/Ert/ecl/include/ecl_grid_cache.h @@ -0,0 +1,46 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_grid_cache.h' is part of ERT - Ensemble based + Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __ECL_GRID_CACHE_H__ +#define __ECL_GRID_CACHE_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + typedef struct ecl_grid_cache_struct ecl_grid_cache_type; + + + ecl_grid_cache_type * ecl_grid_cache_alloc( const ecl_grid_type * grid ); + int ecl_grid_cache_get_size( const ecl_grid_cache_type * grid_cache ); + int ecl_grid_cache_iget_global_index( const ecl_grid_cache_type * grid_cache , int active_index); + const int * ecl_grid_cache_get_global_index( const ecl_grid_cache_type * grid_cache ); + const double * ecl_grid_cache_get_xpos( const ecl_grid_cache_type * grid_cache ); + const double * ecl_grid_cache_get_ypos( const ecl_grid_cache_type * grid_cache ); + const double * ecl_grid_cache_get_zpos( const ecl_grid_cache_type * grid_cache ); + void ecl_grid_cache_free( ecl_grid_cache_type * grid_cache ); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/ThirdParty/Ert/ecl/include/ecl_kw.h b/ThirdParty/Ert/ecl/include/ecl_kw.h index 060a9c236e..89caeb3e46 100644 --- a/ThirdParty/Ert/ecl/include/ecl_kw.h +++ b/ThirdParty/Ert/ecl/include/ecl_kw.h @@ -35,7 +35,7 @@ extern "C" { typedef struct ecl_kw_struct ecl_kw_type; - void ecl_kw_set_data_ptr(ecl_kw_type * ecl_kw , char * data); + void ecl_kw_set_data_ptr(ecl_kw_type * ecl_kw , void * data); void ecl_kw_fwrite_data(const ecl_kw_type *_ecl_kw , fortio_type *fortio); void ecl_kw_fread_realloc_data(ecl_kw_type *ecl_kw, fortio_type *fortio); ecl_type_enum ecl_kw_get_type(const ecl_kw_type *); @@ -46,9 +46,6 @@ extern "C" { void ecl_kw_set_header_name(ecl_kw_type * , const char * ); void ecl_kw_set_header(ecl_kw_type * , const char * , int , const char *); void ecl_kw_set_header_alloc(ecl_kw_type * , const char * , int , const char *); - bool ecl_kw_grdecl_fseek_kw(const char * , bool , bool , FILE * ); - ecl_kw_type * ecl_kw_fscanf_alloc_grdecl_dynamic( FILE * stream , const char * kw , ecl_type_enum ecl_type); - ecl_kw_type * ecl_kw_fscanf_alloc_grdecl_dynamic__( FILE * stream , const char * kw , bool strict , ecl_type_enum ecl_type); bool ecl_kw_fseek_kw(const char * , bool , bool , fortio_type *); bool ecl_kw_fseek_last_kw(const char * , bool , fortio_type *); void ecl_kw_inplace_update_file(const ecl_kw_type * , const char * , int ) ; @@ -58,8 +55,6 @@ extern "C" { void ecl_kw_alloc_float_data(ecl_kw_type * ecl_kw , float * values); bool ecl_kw_fread_realloc(ecl_kw_type *, fortio_type *); void ecl_kw_fread(ecl_kw_type * , fortio_type * ); - ecl_kw_type * ecl_kw_fscanf_alloc_grdecl_data(FILE * , int , ecl_type_enum ); - void ecl_kw_fprintf_grdecl(const ecl_kw_type * , FILE * stream); ecl_kw_type * ecl_kw_fread_alloc(fortio_type *); void ecl_kw_free_data(ecl_kw_type *); void ecl_kw_free(ecl_kw_type *); @@ -77,12 +72,15 @@ extern "C" { void ecl_kw_set_memcpy_data(ecl_kw_type * , const void *); void ecl_kw_fwrite(const ecl_kw_type *, fortio_type *); void ecl_kw_iget(const ecl_kw_type *, int , void *); + void ecl_kw_iset(ecl_kw_type *ecl_kw , int i , const void *iptr); void ecl_kw_iset_char_ptr( ecl_kw_type * ecl_kw , int index, const char * s); + void ecl_kw_iset_string8(ecl_kw_type * ecl_kw , int index , const char *s8); const char * ecl_kw_iget_char_ptr( const ecl_kw_type * ecl_kw , int i); void * ecl_kw_iget_ptr(const ecl_kw_type *, int); int ecl_kw_get_size(const ecl_kw_type *); bool ecl_kw_header_eq(const ecl_kw_type *, const char *); bool ecl_kw_ichar_eq(const ecl_kw_type *, int , const char *); + ecl_kw_type * ecl_kw_alloc( const char * header , int size , ecl_type_enum ecl_type ); ecl_kw_type * ecl_kw_alloc_new(const char * , int , ecl_type_enum , const void * ); ecl_kw_type * ecl_kw_alloc_new_shared(const char * , int , ecl_type_enum , void * ); void ecl_kw_fwrite_param(const char * , bool , const char * , ecl_type_enum , int , void * ); diff --git a/ThirdParty/Ert/ecl/include/ecl_kw_grdecl.h b/ThirdParty/Ert/ecl/include/ecl_kw_grdecl.h index bb7afae111..bd824dc599 100644 --- a/ThirdParty/Ert/ecl/include/ecl_kw_grdecl.h +++ b/ThirdParty/Ert/ecl/include/ecl_kw_grdecl.h @@ -16,10 +16,11 @@ for more details. */ -// This header does not define datatypes; just a couple of functions. It should -// be included from the ecl_kw.h header, so application do not need to include this -// header explicitly. - +/* + This header does not define datatypes; just a couple of functions. It should + be included from the ecl_kw.h header, so applications do not need to include this + header explicitly. +*/ #ifndef __ECL_KW_GRDECL_H__ #define __ECL_KW_GRDECL_H__ @@ -28,6 +29,25 @@ extern "C" { #endif + + bool ecl_kw_grdecl_fseek_kw(const char * , bool , FILE * ); + + ecl_kw_type * ecl_kw_fscanf_alloc_grdecl_dynamic__( FILE * stream , const char * kw , bool strict , ecl_type_enum ecl_type); + ecl_kw_type * ecl_kw_fscanf_alloc_grdecl_dynamic( FILE * stream , const char * kw , ecl_type_enum ecl_type); + + ecl_kw_type * ecl_kw_fscanf_alloc_grdecl_data__(FILE * stream , bool strict , int size, ecl_type_enum ecl_type ); + ecl_kw_type * ecl_kw_fscanf_alloc_grdecl_data( FILE * stream , int size , ecl_type_enum ecl_type); + + ecl_kw_type * ecl_kw_fscanf_alloc_grdecl__(FILE * stream, const char * kw , bool strict , int size, ecl_type_enum ecl_type); + ecl_kw_type * ecl_kw_fscanf_alloc_grdecl(FILE * stream , const char * kw, int size, ecl_type_enum ecl_type); + + ecl_kw_type * ecl_kw_fscanf_alloc_current_grdecl__( FILE * stream , bool strict , ecl_type_enum ecl_type); + ecl_kw_type * ecl_kw_fscanf_alloc_current_grdecl( FILE * stream , ecl_type_enum ecl_type); + + bool ecl_kw_grdecl_fseek_next_kw( FILE * stream ); + char * ecl_kw_grdecl_alloc_next_header( FILE * stream ); + + void ecl_kw_fprintf_grdecl(const ecl_kw_type * ecl_kw , FILE * stream); #ifdef __cplusplus } diff --git a/ThirdParty/Ert/ecl/include/ecl_kw_magic.h b/ThirdParty/Ert/ecl/include/ecl_kw_magic.h index 75f608f01c..40b9c2cdf3 100644 --- a/ThirdParty/Ert/ecl/include/ecl_kw_magic.h +++ b/ThirdParty/Ert/ecl/include/ecl_kw_magic.h @@ -134,10 +134,14 @@ extern "C" { /* Common keywords */ +#define SPECGRID_KW "SPECGRID" #define MAPAXES_KW "MAPAXES" /* Keyword used to transform from grid coordinates to world coordinates. */ #define LGR_KW "LGR" /* Name of LGR; for GRID files it can contain two elements, the second element will be the name of the parent. */ +#define MAPUNITS_KW "MAPUNITS" +#define GRIDUNIT_KW "GRIDUNIT" + /* EGRID keywords */ #define LGR_PARENT_KW "LGRPARNT" /* The name of the parent for an LGR. */ @@ -146,12 +150,16 @@ extern "C" { #define ACTNUM_KW "ACTNUM" /* Integer flag of with active=0,1. */ #define HOSTNUM_KW "HOSTNUM" /* For cells in LGR - pointing back to cell nr in parent grid. */ +#define FILEHEAD_KW "FILEHEAD" +#define ENDGRID_KW "ENDGRID" +#define ENDLGR_KW "ENDLGR" /* GRID keywords */ #define GRIDHEAD_KW "GRIDHEAD" /* Header information for GRID files. */ #define COORD_KW "COORD" /* Header information for one cell in GRID file. */ #define CORNERS_KW "CORNERS" /* Vector containing (x,y,z) x 8 elements - all corners in a cell. */ #define DIMENS_KW "DIMENS" /* The dimensions of the grid. */ +#define RADIAL_KW "RADIAL" #define GLOBAL_STRING "GLOBAL" @@ -159,13 +167,28 @@ extern "C" { #define GRIDHEAD_NX_INDEX 1 #define GRIDHEAD_NY_INDEX 2 #define GRIDHEAD_NZ_INDEX 3 +#define GRIDHEAD_LGR_INDEX 4 +#define GRIDHEAD_SIZE 100 -/* Observe that these indices are one value lower the values used +/* Observe that these indices are one value lower than the values used in the ecl_smspec file. */ #define DIMENS_NX_INDEX 0 #define DIMENS_NY_INDEX 1 #define DIMENS_NZ_INDEX 2 +#define FILEHEAD_VERSION_INDEX 0 +#define FILEHEAD_YEAR_INDEX 1 +#define FILEHEAD_COMPAT_INDEX 3 +#define FILEHEAD_TYPE_INDEX 4 +#define FILEHEAD_DUALP_INDEX 5 +#define FILEHEAD_ORGFORMAT_INDEX 6 + +#define GRIDHEAD_GRIDTYPE_CORNERPOINT 1 /* <----\ */ + /* | Fucking hysterical! */ +#define FILEHEAD_GRIDTYPE_CORNERPOINT 0 /* <----/ */ +#define FILEHEAD_SINGLE_POROSITY 0 +#define FILEHEAD_ORGTYPE_CORNERPOINT 1 + #ifdef __cplusplus } #endif diff --git a/ThirdParty/Ert/ecl/include/ecl_region.h b/ThirdParty/Ert/ecl/include/ecl_region.h index 8c2cc7f3ee..f7b1b5467c 100644 --- a/ThirdParty/Ert/ecl/include/ecl_region.h +++ b/ThirdParty/Ert/ecl/include/ecl_region.h @@ -21,11 +21,15 @@ #ifdef __cplusplus extern "C" { #endif +#include + +#include + +#include + #include #include -#include -#include -#include + typedef enum { SELECT_ALL = 0, diff --git a/ThirdParty/Ert/ecl/include/ecl_rft_file.h b/ThirdParty/Ert/ecl/include/ecl_rft_file.h index cd3dfa5d48..24bc7a1696 100644 --- a/ThirdParty/Ert/ecl/include/ecl_rft_file.h +++ b/ThirdParty/Ert/ecl/include/ecl_rft_file.h @@ -22,9 +22,11 @@ extern "C" { #endif #include -#include + #include +#include + typedef struct ecl_rft_file_struct ecl_rft_file_type; char * ecl_rft_file_alloc_case_filename(const char * case_input ); diff --git a/ThirdParty/Ert/ecl/include/ecl_rft_node.h b/ThirdParty/Ert/ecl/include/ecl_rft_node.h index fc16f1252d..3c830eac0d 100644 --- a/ThirdParty/Ert/ecl/include/ecl_rft_node.h +++ b/ThirdParty/Ert/ecl/include/ecl_rft_node.h @@ -21,9 +21,10 @@ #ifdef __cplusplus extern "C" { #endif -#include #include +#include + typedef enum { RFT = 1 , PLT = 2 , SEGMENT = 3 /* Not really implemented */ } ecl_rft_enum; diff --git a/ThirdParty/Ert/ecl/include/ecl_smspec.h b/ThirdParty/Ert/ecl/include/ecl_smspec.h index dfb2b381d1..ea2062f0da 100644 --- a/ThirdParty/Ert/ecl/include/ecl_smspec.h +++ b/ThirdParty/Ert/ecl/include/ecl_smspec.h @@ -29,6 +29,7 @@ extern "C" { typedef struct ecl_smspec_struct ecl_smspec_type; + /** These are the different variable types, see table 3.4 in the ECLIPFE file format docuemntation for naming conventions. @@ -59,7 +60,7 @@ ecl_smspec_var_type ecl_smspec_iget_var_type( const ecl_smspec_type * smspec , i bool ecl_smspec_needs_num( ecl_smspec_var_type var_type ); bool ecl_smspec_needs_wgname( ecl_smspec_var_type var_type ); const char * ecl_smspec_get_var_type_name( ecl_smspec_var_type var_type ); -ecl_smspec_var_type ecl_smspec_identify_var_type(const ecl_smspec_type * smspec , const char * ); +ecl_smspec_var_type ecl_smspec_identify_var_type(const char * var); bool ecl_smspec_general_is_total(const ecl_smspec_type * ecl_smspec , const char * gen_key); bool ecl_smspec_is_rate(const ecl_smspec_type * smspec , int kw_index); diff --git a/ThirdParty/Ert/ecl/include/ecl_subsidence.h b/ThirdParty/Ert/ecl/include/ecl_subsidence.h new file mode 100644 index 0000000000..1c9250c9f7 --- /dev/null +++ b/ThirdParty/Ert/ecl/include/ecl_subsidence.h @@ -0,0 +1,47 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_subsidence.h' is part of ERT - Ensemble based + Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __ECL_SUBSIDENCE_H__ +#define __ECL_SUBSICENCE_H__ +#ifdef __plusplus +extern "C" { +#endif + +#include +#include +#include + + typedef struct ecl_subsidence_struct ecl_subsidence_type; + typedef struct ecl_subsidence_survey_struct ecl_subsidence_survey_type; + + + void ecl_subsidence_free( ecl_subsidence_type * ecl_subsidence_config ); + ecl_subsidence_type * ecl_subsidence_alloc( const ecl_grid_type * ecl_grid, const ecl_file_type * init_file ); + ecl_subsidence_survey_type * ecl_subsidence_add_survey_PRESSURE( ecl_subsidence_type * subsidence , + const char * name , const ecl_file_type * restart_file ); + double ecl_subsidence_eval( const ecl_subsidence_type * subsidence , + const char * base, const char * monitor , + ecl_region_type * region , + double utm_x, double utm_y , double depth, double compressibility, double poisson_ratio); + + +#ifdef __plusplus +} +#endif +#endif diff --git a/ThirdParty/Ert/ecl/include/ecl_sum.h b/ThirdParty/Ert/ecl/include/ecl_sum.h index 29c692c6c3..bd80ef7cc1 100644 --- a/ThirdParty/Ert/ecl/include/ecl_sum.h +++ b/ThirdParty/Ert/ecl/include/ecl_sum.h @@ -26,10 +26,11 @@ extern "C" { #include #include #include -#include + #include -#include + #include +#include #include typedef struct ecl_sum_struct ecl_sum_type; @@ -103,6 +104,7 @@ bool ecl_sum_has_well_completion_var(const ecl_sum_type * ecl_sum , double ecl_sum_get_general_var(const ecl_sum_type * ecl_sum , int time_index , const char * lookup_kw); int ecl_sum_get_general_var_index(const ecl_sum_type * ecl_sum , const char * lookup_kw); bool ecl_sum_has_general_var(const ecl_sum_type * ecl_sum , const char * lookup_kw); +bool ecl_sum_has_key(const ecl_sum_type * ecl_sum , const char * lookup_kw); double ecl_sum_get_general_var_from_sim_days( const ecl_sum_type * ecl_sum , double sim_days , const char * var); double ecl_sum_get_general_var_from_sim_time( const ecl_sum_type * ecl_sum , time_t sim_time , const char * var); const char * ecl_sum_get_general_var_unit( const ecl_sum_type * ecl_sum , const char * var); @@ -150,7 +152,7 @@ stringlist_type * ecl_sum_alloc_well_var_list( const ecl_sum_type * ecl_sum stringlist_type * ecl_sum_alloc_matching_general_var_list(const ecl_sum_type * ecl_sum , const char * pattern); void ecl_sum_select_matching_general_var_list( const ecl_sum_type * ecl_sum , const char * pattern , stringlist_type * keys); const ecl_smspec_type * ecl_sum_get_smspec( const ecl_sum_type * ecl_sum ); -ecl_smspec_var_type ecl_sum_identify_var_type(const ecl_sum_type * ecl_sum , const char * var); +ecl_smspec_var_type ecl_sum_identify_var_type(const char * var); ecl_smspec_var_type ecl_sum_get_var_type( const ecl_sum_type * ecl_sum , const char * gen_key); bool ecl_sum_var_is_rate( const ecl_sum_type * ecl_sum , const char * gen_key); bool ecl_sum_var_is_total( const ecl_sum_type * ecl_sum , const char * gen_key); diff --git a/ThirdParty/Ert/ecl/include/ecl_sum_data.h b/ThirdParty/Ert/ecl/include/ecl_sum_data.h index 575de3ea1d..a35b866b9c 100644 --- a/ThirdParty/Ert/ecl/include/ecl_sum_data.h +++ b/ThirdParty/Ert/ecl/include/ecl_sum_data.h @@ -25,6 +25,7 @@ extern "C" { #endif #include #include + #include #include #include diff --git a/ThirdParty/Ert/ecl/include/ecl_util.h b/ThirdParty/Ert/ecl/include/ecl_util.h index 0cc1386730..36a480b5d0 100644 --- a/ThirdParty/Ert/ecl/include/ecl_util.h +++ b/ThirdParty/Ert/ecl/include/ecl_util.h @@ -143,6 +143,7 @@ typedef enum { #define ECL_BOOL_TRUE_INT -1 // Binary representation: 11111111 11111111 11111111 1111111 #define ECL_BOOL_FALSE_INT 0 // Binary representation: 00000000 00000000 00000000 0000000 #define ECL_COMMENT_STRING "--" +#define ECL_COMMENT_CHAR '-' // Need to consecutive to make an ECLIPSE comment #define ECL_DATA_TERMINATION "/" diff --git a/ThirdParty/Ert/ecl/include/fortio.h b/ThirdParty/Ert/ecl/include/fortio.h index 3add92f63a..6b19123231 100644 --- a/ThirdParty/Ert/ecl/include/fortio.h +++ b/ThirdParty/Ert/ecl/include/fortio.h @@ -46,9 +46,9 @@ typedef struct fortio_struct fortio_type; bool fortio_is_fortran_file(const char * , bool * ); void fortio_copy_record(fortio_type * , fortio_type * , int , void * , bool *); fortio_type * fortio_alloc_FILE_wrapper(const char * , bool , bool , FILE * ); - fortio_type * fortio_open_reader(const char *, bool , bool); - fortio_type * fortio_open_writer(const char *, bool , bool); - fortio_type * fortio_open_readwrite(const char *, bool , bool); + fortio_type * fortio_open_reader(const char *, bool fmt_file , bool endian_flip_header); + fortio_type * fortio_open_writer(const char *, bool fmt_file , bool endian_flip_header); + fortio_type * fortio_open_readwrite(const char *, bool fmt_file , bool endian_flip_header); void fortio_free_FILE_wrapper(fortio_type *); void fortio_fclose(fortio_type *); int fortio_init_read(fortio_type *); diff --git a/ThirdParty/Ert/ecl/include/smspec_node.h b/ThirdParty/Ert/ecl/include/smspec_node.h new file mode 100644 index 0000000000..7566ea08b1 --- /dev/null +++ b/ThirdParty/Ert/ecl/include/smspec_node.h @@ -0,0 +1,90 @@ +/* + Copyright (C) 2012 Statoil ASA, Norway. + + The file 'smspec_node.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#ifndef __SMSPEC_NODE_H__ +#define __SMSPEC_NODE_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + + +#define SMSPEC_NUMS_INVALID -991199 + + typedef struct smspec_node_struct smspec_node_type; + + char * smspec_alloc_block_ijk_key( const char * join_string , const char * keyword , int i , int j , int k); + char * smspec_alloc_completion_ijk_key( const char * join_string , const char * keyword, const char * wgname , int i , int j , int k); + char * smspec_alloc_completion_num_key( const char * join_string , const char * keyword, const char * wgname , int num); + char * smspec_alloc_group_key( const char * join_string , const char * keyword , const char * wgname); + char * smspec_alloc_well_key( const char * join_string , const char * keyword , const char * wgname); + char * smspec_alloc_region_key( const char * join_string , const char * keyword , int num); + char * smspec_alloc_segment_key( const char * join_string , const char * keyword , const char * wgname , int num); + char * smspec_alloc_block_num_key( const char * join_string , const char * keyword , int num); + char * smspec_alloc_local_well_key( const char * join_string , const char * keyword , const char * lgr_name , const char * wgname); + char * smspec_alloc_local_block_key( const char * join_string , const char * keyword , const char * lgr_name , int i , int j , int k); + char * smspec_alloc_local_completion_key( const char * join_string, const char * keyword , const char * lgr_name , const char * wgname , int i , int j , int k); + + + + + smspec_node_type * smspec_node_alloc_empty(ecl_smspec_var_type var_type, const char * keyword , const char * unit , int param_index); + void smspec_node_set_wgname( smspec_node_type * index , const char * wgname ); + void smspec_node_set_lgr_name( smspec_node_type * index , const char * lgr_name ); + void smspec_node_set_num( smspec_node_type * index , int num); + void smspec_node_set_gen_key( smspec_node_type * smspec_node , const char * key_join_string); + void smspec_node_set_flags( smspec_node_type * smspec_node); + + smspec_node_type * smspec_node_alloc( ecl_smspec_var_type var_type , + const char * wgname , + const char * keyword , + const char * unit , + const char * key_join_string , + int num , int index); + + smspec_node_type * smspec_node_alloc_lgr( ecl_smspec_var_type var_type , + const char * wgname , + const char * keyword , + const char * unit , + const char * lgr , + const char * key_join_string , + int lgr_i, int lgr_j , int lgr_k, + int index); + + void smspec_node_free( smspec_node_type * index ); + int smspec_node_get_index( const smspec_node_type * smspec_node ); + const char * smspec_node_get_gen_key( const smspec_node_type * smspec_node); + ecl_smspec_var_type smspec_node_get_var_type( const smspec_node_type * smspec_node); + int smspec_node_get_num( const smspec_node_type * smspec_node); + const char * smspec_node_get_wgname( const smspec_node_type * smspec_node); + const char * smspec_node_get_keyword( const smspec_node_type * smspec_node); + const char * smspec_node_get_unit( const smspec_node_type * smspec_node); + bool smspec_node_is_rate( const smspec_node_type * smspec_node ); + bool smspec_node_is_total( const smspec_node_type * smspec_node ); + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert/ecl/lib/libecl.a b/ThirdParty/Ert/ecl/lib/libecl.a index 188969d586..2ad7ab0b9e 100644 Binary files a/ThirdParty/Ert/ecl/lib/libecl.a and b/ThirdParty/Ert/ecl/lib/libecl.a differ diff --git a/ThirdParty/Ert/ecl/lib/libecl.so b/ThirdParty/Ert/ecl/lib/libecl.so new file mode 100644 index 0000000000..0050debd81 Binary files /dev/null and b/ThirdParty/Ert/ecl/lib/libecl.so differ diff --git a/ThirdParty/Ert/geometry/lib/libgeometry.a b/ThirdParty/Ert/geometry/lib/libgeometry.a index f105774633..50bf2899f3 100644 Binary files a/ThirdParty/Ert/geometry/lib/libgeometry.a and b/ThirdParty/Ert/geometry/lib/libgeometry.a differ diff --git a/ThirdParty/Ert/geometry/lib/libgeometry.so b/ThirdParty/Ert/geometry/lib/libgeometry.so new file mode 100644 index 0000000000..92b9585bf8 Binary files /dev/null and b/ThirdParty/Ert/geometry/lib/libgeometry.so differ diff --git a/ThirdParty/Ert/util/include/arg_pack.h b/ThirdParty/Ert/util/include/arg_pack.h index a29c77aec5..a92a5ae913 100644 --- a/ThirdParty/Ert/util/include/arg_pack.h +++ b/ThirdParty/Ert/util/include/arg_pack.h @@ -23,37 +23,38 @@ extern "C" { #endif #include #include + #include -#include +#include typedef struct arg_pack_struct arg_pack_type; typedef void (arg_node_free_ftype) (void *); typedef void * (arg_node_copyc_ftype) (void *); -arg_pack_type * arg_pack_alloc(); -UTIL_SAFE_CAST_HEADER( arg_pack ); - -void arg_pack_free(arg_pack_type * ); -void arg_pack_free__(void *); -void arg_pack_clear(arg_pack_type *); -void arg_pack_lock(arg_pack_type *); -void arg_pack_fscanf(arg_pack_type * arg , FILE * stream); -void arg_pack_fprintf(const arg_pack_type * , FILE * ); - -void arg_pack_append_ptr(arg_pack_type * , const void *); -void arg_pack_append_owned_ptr(arg_pack_type * , void * , arg_node_free_ftype *); -void arg_pack_append_copy(arg_pack_type * , void * , arg_node_copyc_ftype * , arg_node_free_ftype *); - -void arg_pack_iset_copy(arg_pack_type * arg_pack , int index , void * ptr, arg_node_copyc_ftype * copyc , arg_node_free_ftype * freef); -void arg_pack_iset_ptr(arg_pack_type * arg_pack, int index , const void * ptr); -void arg_pack_iset_owned_ptr(arg_pack_type * arg_pack, int index , void * ptr, arg_node_free_ftype * freef); - -void * arg_pack_iget_ptr(const arg_pack_type * , int); -void * arg_pack_iget_adress(const arg_pack_type * , int); -node_ctype arg_pack_iget_ctype(const arg_pack_type * arg_pack ,int index); + arg_pack_type * arg_pack_alloc(); + UTIL_SAFE_CAST_HEADER( arg_pack ); + void arg_pack_free(arg_pack_type * ); + void arg_pack_free__(void *); + void arg_pack_clear(arg_pack_type *); + void arg_pack_lock(arg_pack_type *); + void arg_pack_fscanf(arg_pack_type * arg , FILE * stream); + void arg_pack_fprintf(const arg_pack_type * , FILE * ); + + void arg_pack_append_ptr(arg_pack_type * , const void *); + void arg_pack_append_owned_ptr(arg_pack_type * , void * , arg_node_free_ftype *); + void arg_pack_append_copy(arg_pack_type * , void * , arg_node_copyc_ftype * , arg_node_free_ftype *); + + void arg_pack_iset_copy(arg_pack_type * arg_pack , int index , void * ptr, arg_node_copyc_ftype * copyc , arg_node_free_ftype * freef); + void arg_pack_iset_ptr(arg_pack_type * arg_pack, int index , const void * ptr); + void arg_pack_iset_owned_ptr(arg_pack_type * arg_pack, int index , void * ptr, arg_node_free_ftype * freef); + + void * arg_pack_iget_ptr(const arg_pack_type * , int); + void * arg_pack_iget_adress(const arg_pack_type * , int); + node_ctype arg_pack_iget_ctype(const arg_pack_type * arg_pack ,int index); + /*****************************************************************/ - + #define APPEND_TYPED_HEADER(type) void arg_pack_append_ ## type (arg_pack_type * , type); #define IGET_TYPED_HEADER(type) type arg_pack_iget_ ## type( const arg_pack_type * , int ); #define ISET_TYPED_HEADER(type) void arg_pack_iset_ ## type( arg_pack_type * , int , type value); diff --git a/ThirdParty/Ert/util/include/block_fs.h b/ThirdParty/Ert/util/include/block_fs.h index 18c30a490c..b7add48364 100644 --- a/ThirdParty/Ert/util/include/block_fs.h +++ b/ThirdParty/Ert/util/include/block_fs.h @@ -19,45 +19,49 @@ #ifndef __BLOCK_FS__ #define __BLOCK_FS__ #include -#include #include +#include -typedef struct block_fs_struct block_fs_type; -typedef struct user_file_node_struct user_file_node_type; - -typedef enum { - NO_SORT = 0, - STRING_SORT = 1, - OFFSET_SORT = 2 -} block_fs_sort_type; - -size_t block_fs_get_cache_usage( const block_fs_type * block_fs ); -double block_fs_get_fragmentation( const block_fs_type * block_fs ); -bool block_fs_rotate( block_fs_type * block_fs , double fragmentation_limit); -void block_fs_fsync( block_fs_type * block_fs ); -bool block_fs_is_mount( const char * mount_file ); -block_fs_type * block_fs_mount( const char * mount_file , int block_size , int max_cache_size , float fragmentation_limit , int fsync_interval , bool preload , bool read_only); -void block_fs_close( block_fs_type * block_fs , bool unlink_empty); -void block_fs_fwrite_file(block_fs_type * block_fs , const char * filename , const void * ptr , size_t byte_size); -void block_fs_fwrite_buffer(block_fs_type * block_fs , const char * filename , const buffer_type * buffer); -void block_fs_fread_file( block_fs_type * block_fs , const char * filename , void * ptr); -int block_fs_get_filesize( block_fs_type * block_fs , const char * filename); -void block_fs_fread_realloc_buffer( block_fs_type * block_fs , const char * filename , buffer_type * buffer); -void block_fs_sync( block_fs_type * block_fs ); -void block_fs_unlink_file( block_fs_type * block_fs , const char * filename); -bool block_fs_has_file( block_fs_type * block_fs , const char * filename); -vector_type * block_fs_alloc_filelist( block_fs_type * block_fs , const char * pattern , block_fs_sort_type sort_mode , bool include_free_nodes ); -void block_fs_defrag( block_fs_type * block_fs ); - -long int user_file_node_get_node_offset( const user_file_node_type * user_file_node ); -long int user_file_node_get_data_offset( const user_file_node_type * user_file_node ); -int user_file_node_get_node_size( const user_file_node_type * user_file_node ); -int user_file_node_get_data_size( const user_file_node_type * user_file_node ); -bool user_file_node_in_use( const user_file_node_type * user_file_node ); -const char * user_file_node_get_filename( const user_file_node_type * user_file_node ); - +#ifdef __cplusplus +extern "C" { +#endif + typedef struct block_fs_struct block_fs_type; + typedef struct user_file_node_struct user_file_node_type; + + typedef enum { + NO_SORT = 0, + STRING_SORT = 1, + OFFSET_SORT = 2 + } block_fs_sort_type; + + size_t block_fs_get_cache_usage( const block_fs_type * block_fs ); + double block_fs_get_fragmentation( const block_fs_type * block_fs ); + bool block_fs_rotate( block_fs_type * block_fs , double fragmentation_limit); + void block_fs_fsync( block_fs_type * block_fs ); + bool block_fs_is_mount( const char * mount_file ); + block_fs_type * block_fs_mount( const char * mount_file , int block_size , int max_cache_size , float fragmentation_limit , int fsync_interval , bool preload , bool read_only); + void block_fs_close( block_fs_type * block_fs , bool unlink_empty); + void block_fs_fwrite_file(block_fs_type * block_fs , const char * filename , const void * ptr , size_t byte_size); + void block_fs_fwrite_buffer(block_fs_type * block_fs , const char * filename , const buffer_type * buffer); + void block_fs_fread_file( block_fs_type * block_fs , const char * filename , void * ptr); + int block_fs_get_filesize( block_fs_type * block_fs , const char * filename); + void block_fs_fread_realloc_buffer( block_fs_type * block_fs , const char * filename , buffer_type * buffer); + void block_fs_sync( block_fs_type * block_fs ); + void block_fs_unlink_file( block_fs_type * block_fs , const char * filename); + bool block_fs_has_file( block_fs_type * block_fs , const char * filename); + vector_type * block_fs_alloc_filelist( block_fs_type * block_fs , const char * pattern , block_fs_sort_type sort_mode , bool include_free_nodes ); + void block_fs_defrag( block_fs_type * block_fs ); + + long int user_file_node_get_node_offset( const user_file_node_type * user_file_node ); + long int user_file_node_get_data_offset( const user_file_node_type * user_file_node ); + int user_file_node_get_node_size( const user_file_node_type * user_file_node ); + int user_file_node_get_data_size( const user_file_node_type * user_file_node ); + bool user_file_node_in_use( const user_file_node_type * user_file_node ); + const char * user_file_node_get_filename( const user_file_node_type * user_file_node ); UTIL_IS_INSTANCE_HEADER( block_fs ); - +#ifdef __cplusplus +} +#endif #endif diff --git a/ThirdParty/Ert/util/include/bool_vector.h b/ThirdParty/Ert/util/include/bool_vector.h index 75f67de169..210184d2fa 100644 --- a/ThirdParty/Ert/util/include/bool_vector.h +++ b/ThirdParty/Ert/util/include/bool_vector.h @@ -24,7 +24,7 @@ extern "C" { #include #include -#include +#include typedef struct bool_vector_struct bool_vector_type; typedef bool (bool_ftype) (bool); diff --git a/ThirdParty/Ert/util/include/buffer.h b/ThirdParty/Ert/util/include/buffer.h index 890e65e971..afc1ab9bbe 100644 --- a/ThirdParty/Ert/util/include/buffer.h +++ b/ThirdParty/Ert/util/include/buffer.h @@ -28,6 +28,8 @@ extern "C" { #include #include +#include + typedef struct buffer_struct buffer_type; bool buffer_replace( buffer_type * buffer , const char * old_string , const char * new_string); diff --git a/ThirdParty/Ert/util/include/double_vector.h b/ThirdParty/Ert/util/include/double_vector.h index f70784db1c..71c952fe4b 100644 --- a/ThirdParty/Ert/util/include/double_vector.h +++ b/ThirdParty/Ert/util/include/double_vector.h @@ -24,7 +24,7 @@ extern "C" { #include #include -#include +#include typedef struct double_vector_struct double_vector_type; typedef double (double_ftype) (double); diff --git a/ThirdParty/Ert/util/include/float_vector.h b/ThirdParty/Ert/util/include/float_vector.h index 0b8b3df789..3cdaac81c7 100644 --- a/ThirdParty/Ert/util/include/float_vector.h +++ b/ThirdParty/Ert/util/include/float_vector.h @@ -24,7 +24,7 @@ extern "C" { #include #include -#include +#include typedef struct float_vector_struct float_vector_type; typedef float (float_ftype) (float); diff --git a/ThirdParty/Ert/util/include/hash.h b/ThirdParty/Ert/util/include/hash.h index 767e1c4fa7..6f185c23cc 100644 --- a/ThirdParty/Ert/util/include/hash.h +++ b/ThirdParty/Ert/util/include/hash.h @@ -24,6 +24,7 @@ extern"C" { #include #include +#include typedef struct hash_struct hash_type; typedef struct hash_iter_struct hash_iter_type; typedef void (hash_apply_ftype) (void * ); diff --git a/ThirdParty/Ert/util/include/hash_node.h b/ThirdParty/Ert/util/include/hash_node.h index eca6180b38..bd66eadd20 100644 --- a/ThirdParty/Ert/util/include/hash_node.h +++ b/ThirdParty/Ert/util/include/hash_node.h @@ -23,6 +23,7 @@ extern "C" { #endif #include #include + #include typedef struct hash_node_struct hash_node_type; diff --git a/ThirdParty/Ert/util/include/int_vector.h b/ThirdParty/Ert/util/include/int_vector.h index d845e5a04b..2d3b0d1c2d 100644 --- a/ThirdParty/Ert/util/include/int_vector.h +++ b/ThirdParty/Ert/util/include/int_vector.h @@ -24,7 +24,7 @@ extern "C" { #include #include -#include +#include typedef struct int_vector_struct int_vector_type; typedef int (int_ftype) (int); diff --git a/ThirdParty/Ert/util/include/log.h b/ThirdParty/Ert/util/include/log.h index 4ab8915738..f7a8c38ab5 100644 --- a/ThirdParty/Ert/util/include/log.h +++ b/ThirdParty/Ert/util/include/log.h @@ -28,22 +28,20 @@ extern "C" { typedef struct log_struct log_type; -FILE * log_get_stream(log_type * logh ); -void log_reset_filename( log_type * logh , const char * filename ); -void log_set_file(log_type * , const char *); -log_type * log_alloc_new(const char *filename, int log_level); -log_type * log_alloc_existing(const char *filename, int log_level); -void log_add_message(log_type *logh, int message_level , FILE * dup_stream , char* message, bool free_message); -void log_add_fmt_message(log_type * logh , int message_level , FILE * dup_stream , const char * fmt , ...); -int log_get_level( const log_type * logh); -void log_set_level( log_type * logh , int new_level); -void log_close( log_type * logh ); -inline void log_sync(log_type * logh); -const char * log_get_filename( const log_type * logh ); -int log_get_level( const log_type * logh); -void log_set_level( log_type * logh , int log_level); - - + FILE * log_get_stream(log_type * logh ); + void log_reset_filename( log_type * logh , const char * filename ); + void log_set_file(log_type * , const char *); + log_type * log_alloc_new(const char *filename, int log_level); + log_type * log_alloc_existing(const char *filename, int log_level); + void log_add_message(log_type *logh, int message_level , FILE * dup_stream , char* message, bool free_message); + void log_add_fmt_message(log_type * logh , int message_level , FILE * dup_stream , const char * fmt , ...); + int log_get_level( const log_type * logh); + void log_set_level( log_type * logh , int new_level); + void log_close( log_type * logh ); + void log_sync(log_type * logh); + const char * log_get_filename( const log_type * logh ); + int log_get_level( const log_type * logh); + void log_set_level( log_type * logh , int log_level); #ifdef __cplusplus diff --git a/ThirdParty/Ert/util/include/long_vector.h b/ThirdParty/Ert/util/include/long_vector.h index ab01aad713..f73757ba84 100644 --- a/ThirdParty/Ert/util/include/long_vector.h +++ b/ThirdParty/Ert/util/include/long_vector.h @@ -24,7 +24,7 @@ extern "C" { #include #include -#include +#include typedef struct long_vector_struct long_vector_type; typedef long (long_ftype) (long); diff --git a/ThirdParty/Ert/util/include/matrix.h b/ThirdParty/Ert/util/include/matrix.h index 7e48548a31..3a913b484e 100644 --- a/ThirdParty/Ert/util/include/matrix.h +++ b/ThirdParty/Ert/util/include/matrix.h @@ -21,8 +21,12 @@ #include #include #include + #include +#include +#ifdef HAVE_THREAD_POOL #include +#endif #ifdef __cplusplus extern "C" { @@ -30,99 +34,101 @@ extern "C" { typedef struct matrix_struct matrix_type; -void matrix_fscanf_data( matrix_type * matrix , bool row_major_order , FILE * stream ); -void matrix_fprintf( const matrix_type * matrix , const char * fmt , FILE * stream ); -void matrix_pretty_fprint(const matrix_type * matrix , const char * name , const char * fmt , FILE * stream); -matrix_type * matrix_alloc(int rows, int columns); -matrix_type * matrix_safe_alloc(int rows, int columns); -bool matrix_resize(matrix_type * matrix , int rows , int columns , bool copy_content); -bool matrix_safe_resize(matrix_type * matrix , int rows , int columns , bool copy_content); -matrix_type * matrix_alloc_copy(const matrix_type * src); -matrix_type * matrix_safe_alloc_copy(const matrix_type * src); - -matrix_type * matrix_alloc_shared(const matrix_type * src , int row , int column , int rows , int columns); -void matrix_free(matrix_type * matrix); -void matrix_safe_free( matrix_type * matrix ); -void matrix_pretty_print(const matrix_type * matrix , const char * name , const char * fmt); -void matrix_set(matrix_type * matrix, double value); -void matrix_set_name( matrix_type * matrix , const char * name); -void matrix_scale(matrix_type * matrix, double value); -void matrix_shift(matrix_type * matrix, double value); - -void matrix_assert_finite( const matrix_type * matrix ); - -void matrix_assign(matrix_type * A , const matrix_type * B); -void matrix_inplace_add(matrix_type * A , const matrix_type * B); -void matrix_inplace_sub(matrix_type * A , const matrix_type * B); -void matrix_inplace_mul(matrix_type * A , const matrix_type * B); -void matrix_inplace_div(matrix_type * A , const matrix_type * B); -void matrix_sub(matrix_type * A , const matrix_type * B , const matrix_type * C); -void matrix_mul( matrix_type * A , const matrix_type * B , const matrix_type * C); -void matrix_transpose(const matrix_type * A , matrix_type * T); - -void matrix_iset_safe(matrix_type * matrix , int i , int j, double value); -void matrix_iset(matrix_type * matrix , int i , int j, double value); -double matrix_iget(const matrix_type * matrix , int i , int j); -double matrix_iget_safe(const matrix_type * matrix , int i , int j); -void matrix_iadd(matrix_type * matrix , int i , int j , double value); -void matrix_isub(matrix_type * matrix , int i , int j , double value); -void matrix_imul(matrix_type * matrix , int i , int j , double value); - - -void matrix_inplace_matmul(matrix_type * A, const matrix_type * B); -void matrix_inplace_matmul_mt1(matrix_type * A, const matrix_type * B , int num_threads); -void matrix_inplace_matmul_mt2(matrix_type * A, const matrix_type * B , thread_pool_type * thread_pool); - -void matrix_shift_column(matrix_type * matrix , int column, double shift); -void matrix_shift_row(matrix_type * matrix , int row , double shift); -double matrix_get_column_sum(const matrix_type * matrix , int column); -double matrix_get_row_sum(const matrix_type * matrix , int column); -double matrix_get_column_sum2(const matrix_type * matrix , int column); -double matrix_get_row_abssum(const matrix_type * matrix , int row); -double matrix_get_column_abssum(const matrix_type * matrix , int column); -double matrix_get_row_sum2(const matrix_type * matrix , int column); -void matrix_subtract_row_mean(matrix_type * matrix); -void matrix_subtract_and_store_row_mean(matrix_type * matrix, matrix_type * row_mean); -void matrix_scale_column(matrix_type * matrix , int column , double scale_factor); -void matrix_scale_row(matrix_type * matrix , int row , double scale_factor); -void matrix_set_const_column(matrix_type * matrix , const double value , int column); -void matrix_copy_column(matrix_type * target_matrix, const matrix_type * src_matrix , int src_column, int target_column); -void matrix_set_const_row(matrix_type * matrix , const double value , int row); - -double * matrix_get_data(const matrix_type * matrix); -bool matrix_is_finite(const matrix_type * matrix); -double matrix_orthonormality( const matrix_type * matrix ); - -matrix_type * matrix_alloc_steal_data(int rows , int columns , double * data , int data_size); -void matrix_set_column(matrix_type * matrix , const double * data , int column); -void matrix_set_many_on_column(matrix_type * matrix , int row_offset , int elements , const double * data , int column); -void matrix_ensure_rows(matrix_type * matrix, int rows, bool copy_content); -void matrix_shrink_header(matrix_type * matrix , int rows , int columns); -void matrix_full_size( matrix_type * matrix ); -int matrix_get_rows(const matrix_type * matrix); -int matrix_get_columns(const matrix_type * matrix); -int matrix_get_row_stride(const matrix_type * matrix); -int matrix_get_column_stride(const matrix_type * matrix); -void matrix_get_dims(const matrix_type * matrix , int * rows , int * columns , int * row_stride , int * column_stride); -bool matrix_is_quadratic(const matrix_type * matrix); -bool matrix_equal( const matrix_type * m1 , const matrix_type * m2); - -void matrix_diag_set_scalar(matrix_type * matrix , double value); -void matrix_diag_set(matrix_type * matrix , const double * diag); -void matrix_random_init(matrix_type * matrix , rng_type * rng); -void matrix_matlab_dump(const matrix_type * matrix, const char * filename); - -void matrix_imul_col( matrix_type * matrix , int column , double factor); -double matrix_column_column_dot_product(const matrix_type * m1 , int col1 , const matrix_type * m2 , int col2); -double matrix_row_column_dot_product(const matrix_type * m1 , int row1 , const matrix_type * m2 , int col2); -matrix_type * matrix_alloc_view(double * data , int rows , int columns); -matrix_type * matrix_alloc_transpose( const matrix_type * A); -void matrix_copy_row(matrix_type * target_matrix, const matrix_type * src_matrix , int target_row, int src_row); -void matrix_copy_block( matrix_type * target_matrix , int target_row , int target_column , int rows , int columns, - const matrix_type * src_matrix , int src_row , int src_column); - -void matrix_scalar_set( matrix_type * matrix , double value); -UTIL_SAFE_CAST_HEADER( matrix ) + void matrix_fscanf_data( matrix_type * matrix , bool row_major_order , FILE * stream ); + void matrix_fprintf( const matrix_type * matrix , const char * fmt , FILE * stream ); + void matrix_pretty_fprint(const matrix_type * matrix , const char * name , const char * fmt , FILE * stream); + matrix_type * matrix_alloc(int rows, int columns); + matrix_type * matrix_safe_alloc(int rows, int columns); + bool matrix_resize(matrix_type * matrix , int rows , int columns , bool copy_content); + bool matrix_safe_resize(matrix_type * matrix , int rows , int columns , bool copy_content); + matrix_type * matrix_alloc_copy(const matrix_type * src); + matrix_type * matrix_safe_alloc_copy(const matrix_type * src); + + matrix_type * matrix_alloc_shared(const matrix_type * src , int row , int column , int rows , int columns); + void matrix_free(matrix_type * matrix); + void matrix_safe_free( matrix_type * matrix ); + void matrix_pretty_print(const matrix_type * matrix , const char * name , const char * fmt); + void matrix_set(matrix_type * matrix, double value); + void matrix_set_name( matrix_type * matrix , const char * name); + void matrix_scale(matrix_type * matrix, double value); + void matrix_shift(matrix_type * matrix, double value); + + void matrix_assert_finite( const matrix_type * matrix ); + + void matrix_assign(matrix_type * A , const matrix_type * B); + void matrix_inplace_add(matrix_type * A , const matrix_type * B); + void matrix_inplace_sub(matrix_type * A , const matrix_type * B); + void matrix_inplace_mul(matrix_type * A , const matrix_type * B); + void matrix_inplace_div(matrix_type * A , const matrix_type * B); + void matrix_sub(matrix_type * A , const matrix_type * B , const matrix_type * C); + void matrix_mul( matrix_type * A , const matrix_type * B , const matrix_type * C); + void matrix_transpose(const matrix_type * A , matrix_type * T); + + void matrix_iset_safe(matrix_type * matrix , int i , int j, double value); + void matrix_iset(matrix_type * matrix , int i , int j, double value); + double matrix_iget(const matrix_type * matrix , int i , int j); + double matrix_iget_safe(const matrix_type * matrix , int i , int j); + void matrix_iadd(matrix_type * matrix , int i , int j , double value); + void matrix_isub(matrix_type * matrix , int i , int j , double value); + void matrix_imul(matrix_type * matrix , int i , int j , double value); + + + void matrix_inplace_matmul(matrix_type * A, const matrix_type * B); + void matrix_inplace_matmul_mt1(matrix_type * A, const matrix_type * B , int num_threads); +#ifdef HAVE_THREAD_POOL + void matrix_inplace_matmul_mt2(matrix_type * A, const matrix_type * B , thread_pool_type * thread_pool); +#endif + + void matrix_shift_column(matrix_type * matrix , int column, double shift); + void matrix_shift_row(matrix_type * matrix , int row , double shift); + double matrix_get_column_sum(const matrix_type * matrix , int column); + double matrix_get_row_sum(const matrix_type * matrix , int column); + double matrix_get_column_sum2(const matrix_type * matrix , int column); + double matrix_get_row_abssum(const matrix_type * matrix , int row); + double matrix_get_column_abssum(const matrix_type * matrix , int column); + double matrix_get_row_sum2(const matrix_type * matrix , int column); + void matrix_subtract_row_mean(matrix_type * matrix); + void matrix_subtract_and_store_row_mean(matrix_type * matrix, matrix_type * row_mean); + void matrix_scale_column(matrix_type * matrix , int column , double scale_factor); + void matrix_scale_row(matrix_type * matrix , int row , double scale_factor); + void matrix_set_const_column(matrix_type * matrix , const double value , int column); + void matrix_copy_column(matrix_type * target_matrix, const matrix_type * src_matrix , int src_column, int target_column); + void matrix_set_const_row(matrix_type * matrix , const double value , int row); + + double * matrix_get_data(const matrix_type * matrix); + bool matrix_is_finite(const matrix_type * matrix); + double matrix_orthonormality( const matrix_type * matrix ); + + matrix_type * matrix_alloc_steal_data(int rows , int columns , double * data , int data_size); + void matrix_set_column(matrix_type * matrix , const double * data , int column); + void matrix_set_many_on_column(matrix_type * matrix , int row_offset , int elements , const double * data , int column); + void matrix_ensure_rows(matrix_type * matrix, int rows, bool copy_content); + void matrix_shrink_header(matrix_type * matrix , int rows , int columns); + void matrix_full_size( matrix_type * matrix ); + int matrix_get_rows(const matrix_type * matrix); + int matrix_get_columns(const matrix_type * matrix); + int matrix_get_row_stride(const matrix_type * matrix); + int matrix_get_column_stride(const matrix_type * matrix); + void matrix_get_dims(const matrix_type * matrix , int * rows , int * columns , int * row_stride , int * column_stride); + bool matrix_is_quadratic(const matrix_type * matrix); + bool matrix_equal( const matrix_type * m1 , const matrix_type * m2); + + void matrix_diag_set_scalar(matrix_type * matrix , double value); + void matrix_diag_set(matrix_type * matrix , const double * diag); + void matrix_random_init(matrix_type * matrix , rng_type * rng); + void matrix_matlab_dump(const matrix_type * matrix, const char * filename); + + void matrix_imul_col( matrix_type * matrix , int column , double factor); + double matrix_column_column_dot_product(const matrix_type * m1 , int col1 , const matrix_type * m2 , int col2); + double matrix_row_column_dot_product(const matrix_type * m1 , int row1 , const matrix_type * m2 , int col2); + matrix_type * matrix_alloc_view(double * data , int rows , int columns); + matrix_type * matrix_alloc_transpose( const matrix_type * A); + void matrix_copy_row(matrix_type * target_matrix, const matrix_type * src_matrix , int target_row, int src_row); + void matrix_copy_block( matrix_type * target_matrix , int target_row , int target_column , int rows , int columns, + const matrix_type * src_matrix , int src_row , int src_column); + + void matrix_scalar_set( matrix_type * matrix , double value); + UTIL_SAFE_CAST_HEADER( matrix ); #ifdef __cplusplus } diff --git a/ThirdParty/Ert/util/include/msg.h b/ThirdParty/Ert/util/include/msg.h index fbe363b3a9..9dc5a55858 100644 --- a/ThirdParty/Ert/util/include/msg.h +++ b/ThirdParty/Ert/util/include/msg.h @@ -21,8 +21,8 @@ #ifdef __cplusplus extern "C" { #endif -#include #include +#include typedef struct msg_struct msg_type; diff --git a/ThirdParty/Ert/util/include/mzran.h b/ThirdParty/Ert/util/include/mzran.h index c5f75c4479..6af24eac52 100644 --- a/ThirdParty/Ert/util/include/mzran.h +++ b/ThirdParty/Ert/util/include/mzran.h @@ -33,7 +33,7 @@ typedef struct mzran_struct mzran_type; void mzran_fscanf_state( void * __rng , FILE * stream ); unsigned int mzran_forward(void * __rng); -void * mzran_alloc( ); +void * mzran_alloc( void ); void mzran_set_state(void * __rng , const char * seed_buffer); double mzran_get_double(mzran_type * rng); int mzran_get_int( mzran_type * rng, int max); diff --git a/ThirdParty/Ert/util/include/rng.h b/ThirdParty/Ert/util/include/rng.h index 90dc5e1c8a..873bbd9fe0 100644 --- a/ThirdParty/Ert/util/include/rng.h +++ b/ThirdParty/Ert/util/include/rng.h @@ -23,7 +23,7 @@ extern "C" { #endif -#include +#include typedef enum { @@ -39,36 +39,36 @@ typedef enum { } rng_alg_type; -typedef unsigned int ( rng_forward_ftype ) ( void * ); -typedef void ( rng_set_state_ftype ) ( void * , const char * ); -typedef void * ( rng_alloc_ftype ) ( ); -typedef void ( rng_free_ftype ) ( void * ); -typedef void ( rng_fscanf_ftype ) ( void * , FILE * ); -typedef void ( rng_fprintf_ftype ) ( const void * , FILE * ); - -typedef struct rng_struct rng_type; - -rng_type * rng_alloc( rng_alg_type type , rng_init_mode init_mode ); -void rng_free( rng_type * rng); -void rng_free( rng_type * rng); -unsigned int rng_forward( rng_type * rng ); -double rng_get_double( rng_type * rng); -void rng_rng_init( rng_type * rng , rng_type * seed_src); -void rng_init( rng_type * rng , rng_init_mode init_mode ); -rng_alg_type rng_get_type( const rng_type * rng ); -void rng_fprintf_state( rng_type * rng , FILE * stream ); -void rng_fscanf_state( rng_type * rng , FILE * stream ); - -unsigned int rng_forward( rng_type * rng ); -double rng_get_double( rng_type * rng ); -int rng_get_int( rng_type * rng , int max_value ); - -double rng_std_normal( rng_type * rng ); -void rng_shuffle_int( rng_type * rng , int * data , size_t num_elements); -void rng_shuffle( rng_type * rng , char * data , size_t element_size , size_t num_elements); - -UTIL_SAFE_CAST_HEADER( rng ); - + typedef unsigned int ( rng_forward_ftype ) ( void * ); + typedef void ( rng_set_state_ftype ) ( void * , const char * ); + typedef void * ( rng_alloc_ftype ) ( void ); + typedef void ( rng_free_ftype ) ( void * ); + typedef void ( rng_fscanf_ftype ) ( void * , FILE * ); + typedef void ( rng_fprintf_ftype ) ( const void * , FILE * ); + + typedef struct rng_struct rng_type; + + rng_type * rng_alloc( rng_alg_type type , rng_init_mode init_mode ); + void rng_free( rng_type * rng); + void rng_free( rng_type * rng); + unsigned int rng_forward( rng_type * rng ); + double rng_get_double( rng_type * rng); + void rng_rng_init( rng_type * rng , rng_type * seed_src); + void rng_init( rng_type * rng , rng_init_mode init_mode ); + rng_alg_type rng_get_type( const rng_type * rng ); + void rng_fprintf_state( rng_type * rng , FILE * stream ); + void rng_fscanf_state( rng_type * rng , FILE * stream ); + + unsigned int rng_forward( rng_type * rng ); + double rng_get_double( rng_type * rng ); + int rng_get_int( rng_type * rng , int max_value ); + + double rng_std_normal( rng_type * rng ); + void rng_shuffle_int( rng_type * rng , int * data , size_t num_elements); + void rng_shuffle( rng_type * rng , char * data , size_t element_size , size_t num_elements); + + UTIL_SAFE_CAST_HEADER( rng ); + #ifdef __cplusplus } #endif diff --git a/ThirdParty/Ert/util/include/size_t_vector.h b/ThirdParty/Ert/util/include/size_t_vector.h index 8cb9d76f8f..212ff66064 100644 --- a/ThirdParty/Ert/util/include/size_t_vector.h +++ b/ThirdParty/Ert/util/include/size_t_vector.h @@ -24,7 +24,7 @@ extern "C" { #include #include -#include +#include typedef struct size_t_vector_struct size_t_vector_type; typedef size_t (size_t_ftype) (size_t); diff --git a/ThirdParty/Ert/util/include/ssize_t.h b/ThirdParty/Ert/util/include/ssize_t.h new file mode 100644 index 0000000000..f9e901aef9 --- /dev/null +++ b/ThirdParty/Ert/util/include/ssize_t.h @@ -0,0 +1,27 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ssize_t.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __SSIZE_T_H__ +#define __SSIZE_T_H__ + +#ifdef _MSC_VER +// This should of course check 32/64/... +typedef long ssize_t; +#endif + +#endif diff --git a/ThirdParty/Ert/util/include/stringlist.h b/ThirdParty/Ert/util/include/stringlist.h index 3f1f7b191f..d05ac45d2d 100644 --- a/ThirdParty/Ert/util/include/stringlist.h +++ b/ThirdParty/Ert/util/include/stringlist.h @@ -25,6 +25,7 @@ extern "C" { #include #include +#include #include #include @@ -94,7 +95,10 @@ typedef int ( string_cmp_ftype) (const void * , const void *); void stringlist_sort(stringlist_type * , string_cmp_ftype * string_cmp); void stringlist_python_sort( stringlist_type * s , int cmp_flag); +#ifdef HAVE_GLOB int stringlist_select_matching(stringlist_type * names , const char * pattern); +#endif + int stringlist_select_matching_files(stringlist_type * names , const char * path , const char * file_pattern); UTIL_IS_INSTANCE_HEADER(stringlist); #ifdef __cplusplus diff --git a/ThirdParty/Ert/util/include/subst_list.h b/ThirdParty/Ert/util/include/subst_list.h index 9843505c4c..71f5d9666e 100644 --- a/ThirdParty/Ert/util/include/subst_list.h +++ b/ThirdParty/Ert/util/include/subst_list.h @@ -23,39 +23,40 @@ extern "C" { #endif #include + #include #include #include -typedef struct subst_list_struct subst_list_type; -void subst_list_update_buffer( const subst_list_type * subst_list , buffer_type * buffer ); -void subst_list_insert_func(subst_list_type * subst_list , const char * func_name , const char * local_func_name); -void subst_list_fprintf(const subst_list_type * , FILE * stream); -void subst_list_set_parent( subst_list_type * subst_list , const subst_list_type * parent); -const subst_list_type * subst_list_get_parent( const subst_list_type * subst_list ); -subst_list_type * subst_list_alloc( const void * input_arg ); -subst_list_type * subst_list_alloc_deep_copy(const subst_list_type * ); -void subst_list_free(subst_list_type *); -void subst_list_clear( subst_list_type * subst_list ); -void subst_list_append_copy(subst_list_type * , const char * , const char * , const char * doc_string); -void subst_list_append_ref(subst_list_type * , const char * , const char * , const char * doc_string); -void subst_list_append_owned_ref(subst_list_type * , const char * , const char * , const char * doc_string); -void subst_list_prepend_copy(subst_list_type * , const char * , const char * , const char * doc_string); -void subst_list_prepend_ref(subst_list_type * , const char * , const char * , const char * doc_string); -void subst_list_prepend_owned_ref(subst_list_type * , const char * , const char * , const char * doc_string); - -void subst_list_filter_file(const subst_list_type * , const char * , const char * ); -void subst_list_update_file(const subst_list_type * , const char * ); -void subst_list_update_string(const subst_list_type * , char ** ); -char * subst_list_alloc_filtered_string(const subst_list_type * , const char * ); -void subst_list_filtered_fprintf(const subst_list_type * , const char * , FILE * ); -int subst_list_get_size( const subst_list_type *); -const char * subst_list_iget_value( const subst_list_type * subst_list , int index); -const char * subst_list_iget_key( const subst_list_type * subst_list , int index); -const char * subst_list_iget_doc_string( const subst_list_type * subst_list , int index); -char * subst_list_alloc_string_representation( const subst_list_type * subst_list ); -int subst_list_add_from_string( subst_list_type * subst_list , const char * arg_string, bool append); - + typedef struct subst_list_struct subst_list_type; + void subst_list_update_buffer( const subst_list_type * subst_list , buffer_type * buffer ); + void subst_list_insert_func(subst_list_type * subst_list , const char * func_name , const char * local_func_name); + void subst_list_fprintf(const subst_list_type * , FILE * stream); + void subst_list_set_parent( subst_list_type * subst_list , const subst_list_type * parent); + const subst_list_type * subst_list_get_parent( const subst_list_type * subst_list ); + subst_list_type * subst_list_alloc( const void * input_arg ); + subst_list_type * subst_list_alloc_deep_copy(const subst_list_type * ); + void subst_list_free(subst_list_type *); + void subst_list_clear( subst_list_type * subst_list ); + void subst_list_append_copy(subst_list_type * , const char * , const char * , const char * doc_string); + void subst_list_append_ref(subst_list_type * , const char * , const char * , const char * doc_string); + void subst_list_append_owned_ref(subst_list_type * , const char * , const char * , const char * doc_string); + void subst_list_prepend_copy(subst_list_type * , const char * , const char * , const char * doc_string); + void subst_list_prepend_ref(subst_list_type * , const char * , const char * , const char * doc_string); + void subst_list_prepend_owned_ref(subst_list_type * , const char * , const char * , const char * doc_string); + + void subst_list_filter_file(const subst_list_type * , const char * , const char * ); + void subst_list_update_file(const subst_list_type * , const char * ); + void subst_list_update_string(const subst_list_type * , char ** ); + char * subst_list_alloc_filtered_string(const subst_list_type * , const char * ); + void subst_list_filtered_fprintf(const subst_list_type * , const char * , FILE * ); + int subst_list_get_size( const subst_list_type *); + const char * subst_list_iget_value( const subst_list_type * subst_list , int index); + const char * subst_list_iget_key( const subst_list_type * subst_list , int index); + const char * subst_list_iget_doc_string( const subst_list_type * subst_list , int index); + char * subst_list_alloc_string_representation( const subst_list_type * subst_list ); + int subst_list_add_from_string( subst_list_type * subst_list , const char * arg_string, bool append); + #ifdef __cplusplus } #endif diff --git a/ThirdParty/Ert/util/include/thread_pool_posix.h b/ThirdParty/Ert/util/include/thread_pool_posix.h index a291215010..3f456c39e9 100644 --- a/ThirdParty/Ert/util/include/thread_pool_posix.h +++ b/ThirdParty/Ert/util/include/thread_pool_posix.h @@ -20,16 +20,16 @@ extern "C" { #endif #include -typedef struct thread_pool_struct thread_pool_type; - -void thread_pool_join(thread_pool_type * ); -thread_pool_type * thread_pool_alloc(int , bool start_queue); -void thread_pool_add_job(thread_pool_type * ,void * (*) (void *) , void *); -void thread_pool_free(thread_pool_type *); -void thread_pool_restart( thread_pool_type * tp ); -void * thread_pool_iget_return_value( const thread_pool_type * pool , int queue_index ); -int thread_pool_get_max_running( const thread_pool_type * pool ); + typedef struct thread_pool_struct thread_pool_type; + void thread_pool_join(thread_pool_type * ); + thread_pool_type * thread_pool_alloc(int , bool start_queue); + void thread_pool_add_job(thread_pool_type * ,void * (*) (void *) , void *); + void thread_pool_free(thread_pool_type *); + void thread_pool_restart( thread_pool_type * tp ); + void * thread_pool_iget_return_value( const thread_pool_type * pool , int queue_index ); + int thread_pool_get_max_running( const thread_pool_type * pool ); + #ifdef __cplusplus } #endif diff --git a/ThirdParty/Ert/util/include/time_t_vector.h b/ThirdParty/Ert/util/include/time_t_vector.h index ccc3ab076a..f9847380b7 100644 --- a/ThirdParty/Ert/util/include/time_t_vector.h +++ b/ThirdParty/Ert/util/include/time_t_vector.h @@ -24,7 +24,7 @@ extern "C" { #include #include -#include +#include typedef struct time_t_vector_struct time_t_vector_type; typedef time_t (time_t_ftype) (time_t); diff --git a/ThirdParty/Ert/util/include/type_macros.h b/ThirdParty/Ert/util/include/type_macros.h new file mode 100644 index 0000000000..f20eb37cfd --- /dev/null +++ b/ThirdParty/Ert/util/include/type_macros.h @@ -0,0 +1,98 @@ +#ifndef __TYPE_MACROS_H__ +#define __TYPE_MACROS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/*****************************************************************/ +/** + + The four macros UTIL_IS_INSTANCE_FUNCTION, UTIL_SAFE_CAST_FUNTION, + UTIL_TYPE_ID_DECLARATION and UTIL_TYPE_ID_INIT can be used to + implement a simple system for type checking (void *) at + runtime. The system is based on a unique integer for each class, + this must be provided by the user. + + The motivation for these functions is to be able to to type-check + the arguments to callback functions like pthread_create. + + UTIL_TYPE_ID_DECLARATION: Adds a field "int __type_id;" to the + struct defintion. + + UTIL_TYPE_ID_INIT: Should be added to the allocation routine, + inserts a "->__type_id = magic_int;" code line in the alloc + routine. + + UTIL_IS_INSTANCE_FUNCTION: This macro will generate a function + _is_instance(void *) which will cast the (void *) input to + (type *), and check the value of __type_id. If this is the + correct value true is returned, otherwise the function will + return false. Observe that the function will accept NULL as + input; in which case it will return false. + + UTIL_SAFE_CAST_FUNCTION: This is similar to + UTIL_IS_INSTANCE_FUNCTION, but it will return (type *) if the + cast succeeds, and fail hard if it fails. There is also a _CONST + variety of this function. + +*/ + + + + +#define UTIL_IS_INSTANCE_FUNCTION(type , TYPE_ID) \ +bool type ## _is_instance( const void * __arg ) { \ + if (__arg == NULL) \ + return false; \ + else { \ + const type ## _type * arg = (type ## _type *) __arg; \ + if ( arg->__type_id == TYPE_ID) \ + return true; \ + else \ + return false; \ + } \ +} + + +#define UTIL_IS_INSTANCE_HEADER(type) bool type ## _is_instance( const void * __arg ) + + +#define UTIL_SAFE_CAST_FUNCTION(type , TYPE_ID) \ +type ## _type * type ## _safe_cast( void * __arg ) { \ + if (__arg == NULL) { \ + util_abort("%s: runtime cast failed - tried to dereference NULL\n",__func__); \ + return NULL; \ + } \ + type ## _type * arg = (type ## _type *) __arg; \ + if ( arg->__type_id == TYPE_ID) \ + return arg; \ + else { \ + util_abort("%s: runtime cast failed: File:%s Line:%d. Got:%d Expected:%d \n", __func__ , __FILE__ , __LINE__ , arg->__type_id , TYPE_ID); \ + return NULL; \ + } \ +} +#define UTIL_SAFE_CAST_HEADER( type ) type ## _type * type ## _safe_cast( void * __arg ) + + +#define UTIL_SAFE_CAST_FUNCTION_CONST(type , TYPE_ID) \ +const type ## _type * type ## _safe_cast_const( const void * __arg ) { \ + const type ## _type * arg = (const type ## _type *) __arg; \ + if ( arg->__type_id == TYPE_ID) \ + return arg; \ + else { \ + util_abort("%s: runtime cast failed: File:%s Line:%d. Got:%d Expected:%d \n", __func__ , __FILE__ , __LINE__ , arg->__type_id , TYPE_ID); \ + return NULL; \ + } \ +} +#define UTIL_SAFE_CAST_HEADER_CONST( type ) const type ## _type * type ## _safe_cast_const( const void * __arg ) + +#define UTIL_TYPE_ID_DECLARATION int __type_id +#define UTIL_TYPE_ID_INIT(var , TYPE_ID) var->__type_id = TYPE_ID; + + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert/util/include/util.h b/ThirdParty/Ert/util/include/util.h index 4f17f21909..41215b76ff 100644 --- a/ThirdParty/Ert/util/include/util.h +++ b/ThirdParty/Ert/util/include/util.h @@ -21,120 +21,32 @@ #include #include -#include #include -#include -#include #include +#ifdef HAVE_GETUID +#include +#include +#endif + #define UTIL_PATH_SEP_STRING "/" /* A \0 terminated separator used when we want a (char *) instance. */ #define UTIL_PATH_SEP_CHAR '/' /* A simple character used when we want an actual char instance (i.e. not a pointer). */ #define UTIL_NEWLINE_STRING " \n" #define UTIL_DEFAULT_MKDIR_MODE 0777 /* Directories are by default created with mode a+rwx - and then comes the umask ... */ +//#include "type_macros.h" + #ifdef __cplusplus extern"C" { #endif -/*****************************************************************/ -/** - - The four macros UTIL_IS_INSTANCE_FUNCTION, UTIL_SAFE_CAST_FUNTION, - UTIL_TYPE_ID_DECLARATION and UTIL_TYPE_ID_INIT can be used to - implement a simple system for type checking (void *) at - runtime. The system is based on a unique integer for each class, - this must be provided by the user. - - The motivation for these functions is to be able to to type-check - the arguments to callback functions like pthread_create. - - UTIL_TYPE_ID_DECLARATION: Adds a field "int __type_id;" to the - struct defintion. - - UTIL_TYPE_ID_INIT: Should be added to the allocation routine, - inserts a "->__type_id = magic_int;" code line in the alloc - routine. - - UTIL_IS_INSTANCE_FUNCTION: This macro will generate a function - _is_instance(void *) which will cast the (void *) input to - (type *), and check the value of __type_id. If this is the - correct value true is returned, otherwise the function will - return false. Observe that the function will accept NULL as - input; in which case it will return false. - - UTIL_SAFE_CAST_FUNCTION: This is similar to - UTIL_IS_INSTANCE_FUNCTION, but it will return (type *) if the - cast succeeds, and fail hard if it fails. There is also a _CONST - variety of this function. - -*/ - - - - -#define UTIL_IS_INSTANCE_FUNCTION(type , TYPE_ID) \ -bool type ## _is_instance( const void * __arg ) { \ - if (__arg == NULL) \ - return false; \ - else { \ - const type ## _type * arg = (type ## _type *) __arg; \ - if ( arg->__type_id == TYPE_ID) \ - return true; \ - else \ - return false; \ - } \ -} - - -#define UTIL_IS_INSTANCE_HEADER(type) bool type ## _is_instance( const void * __arg ); - - -#define UTIL_SAFE_CAST_FUNCTION(type , TYPE_ID) \ -type ## _type * type ## _safe_cast( void * __arg ) { \ - if (__arg == NULL) { \ - util_abort("%s: runtime cast failed - tried to dereference NULL\n",__func__); \ - return NULL; \ - } \ - type ## _type * arg = (type ## _type *) __arg; \ - if ( arg->__type_id == TYPE_ID) \ - return arg; \ - else { \ - util_abort("%s: runtime cast failed: File:%s Line:%d. Got:%d Expected:%d \n", __func__ , __FILE__ , __LINE__ , arg->__type_id , TYPE_ID); \ - return NULL; \ - } \ -} -#define UTIL_SAFE_CAST_HEADER( type ) type ## _type * type ## _safe_cast( void * __arg ); - - -#define UTIL_SAFE_CAST_FUNCTION_CONST(type , TYPE_ID) \ -const type ## _type * type ## _safe_cast_const( const void * __arg ) { \ - const type ## _type * arg = (const type ## _type *) __arg; \ - if ( arg->__type_id == TYPE_ID) \ - return arg; \ - else { \ - util_abort("%s: runtime cast failed: File:%s Line:%d. Got:%d Expected:%d \n", __func__ , __FILE__ , __LINE__ , arg->__type_id , TYPE_ID); \ - return NULL; \ - } \ -} -#define UTIL_SAFE_CAST_HEADER_CONST( type ) const type ## _type * type ## _safe_cast_const( const void * __arg ); - -#define UTIL_TYPE_ID_DECLARATION int __type_id; -#define UTIL_TYPE_ID_INIT(var , TYPE_ID) var->__type_id = TYPE_ID; /*****************************************************************/ /* */ -#define LIBRARY_VERSION(libname) \ -const char * libname ## _svn_version() { return SVN_VERSION; } \ -const char * libname ## _build_time() { return NULL; } - - -#define LIBRARY_VERSION_HEADER(libname) \ -const char * libname ## _svn_version(); \ -const char * libname ## _build_time(); /*****************************************************************/ typedef void (walk_file_callback_ftype) (const char * , /* The current directory */ @@ -147,283 +59,263 @@ typedef bool (walk_dir_callback_ftype) (const char * , /* The current director void *); /* Arbitrary argument */ -typedef enum {left_pad = 0, - right_pad = 1, - center = 2} string_alignement_type; +typedef enum {left_pad = 0, + right_pad = 1, + center_pad = 2} string_alignement_type; -LIBRARY_VERSION_HEADER(libutil); + //#define UTIL_CXX_MALLOC(var , num_elm) (typeof (var)) util_malloc( (num_elm) * sizeof var, __func__) -void util_bitmask_on(int * , int ); -time_t util_make_datetime(int , int , int , int , int , int ); -void util_fprintf_datetime(time_t , FILE * ); -void util_fprintf_date(time_t , FILE * ); -time_t util_make_date(int , int , int); -void util_inplace_forward_days(time_t * , double); -double util_difftime(time_t , time_t , int * , int * , int * , int *); -double util_difftime_days(time_t , time_t ); -char * util_alloc_date_string( time_t t ); -char * util_alloc_date_stamp( ); -double util_pow10(double x); -bool util_char_in(char c, int , const char *); -char * util_alloc_sprintf_va(const char * fmt , va_list ap); -char * util_alloc_sprintf(const char * , ...); -char * util_realloc_sprintf(char * , const char * , ...); -void util_fprintf_int(int , int , FILE * ); -void util_fprintf_string(const char * , int , string_alignement_type , FILE * ); -void util_fprintf_double(double , int , int , char , FILE *); -bool util_fscanf_date(FILE * , time_t *); -bool util_sscanf_date(const char * , time_t *); -char * util_blocking_alloc_stdin_line(unsigned long ); -char * util_alloc_stdin_line(); -char * util_realloc_stdin_line(char * ); -bool util_is_executable(const char * ); -bool util_entry_exists( const char * entry ); -bool util_file_exists(const char *); -bool util_is_abs_path(const char * ); -char * util_alloc_abs_path( const char * path ); -bool util_fmt_bit8 (const char *); -bool util_fmt_bit8_stream(FILE * ); -void util_make_path (const char *); -char * util_newest_file(const char *, const char *); -double util_file_difftime(const char * , const char *); -bool util_file_update_required(const char *, const char *); -size_t util_file_size(const char *); -void util_clear_directory(const char *path, bool strict_uid , bool unlink_root); -void util_unlink_existing(const char *filename); -void util_strupr(char *); -bool util_string_equal(const char * s1 , const char * s2 ); -char * util_alloc_strupr_copy(const char * ); -void util_string_tr(char * , char , char); -bool util_copy_stream(FILE *, FILE *, int , void * , bool abort_on_error); + void util_bitmask_on(int * , int ); + time_t util_make_datetime(int , int , int , int , int , int ); + void util_fprintf_datetime(time_t , FILE * ); + void util_fprintf_date(time_t , FILE * ); + time_t util_make_date(int , int , int); + void util_inplace_forward_days(time_t * , double); + double util_difftime(time_t , time_t , int * , int * , int * , int *); + double util_difftime_days(time_t , time_t ); + char * util_alloc_date_string( time_t t ); + char * util_alloc_date_stamp( ); + double util_pow10(double x); + bool util_char_in(char c, int , const char *); + char * util_alloc_sprintf_va(const char * fmt , va_list ap); + char * util_alloc_sprintf(const char * , ...); + char * util_realloc_sprintf(char * , const char * , ...); + void util_fprintf_int(int , int , FILE * ); + void util_fprintf_string(const char * , int , string_alignement_type , FILE * ); + void util_fprintf_double(double , int , int , char , FILE *); + bool util_fscanf_date(FILE * , time_t *); + bool util_sscanf_date(const char * , time_t *); + char * util_blocking_alloc_stdin_line(unsigned long ); + char * util_alloc_stdin_line(); + char * util_realloc_stdin_line(char * ); + bool util_is_executable(const char * ); + bool util_entry_exists( const char * entry ); + bool util_file_exists(const char *); + bool util_is_abs_path(const char * ); + char * util_alloc_abs_path( const char * path ); + bool util_fmt_bit8 (const char *); + bool util_fmt_bit8_stream(FILE * ); + void util_make_path (const char *); + char * util_newest_file(const char *, const char *); + double util_file_difftime(const char * , const char *); + bool util_file_update_required(const char *, const char *); + size_t util_file_size(const char *); + void util_clear_directory(const char *path, bool strict_uid , bool unlink_root); + void util_unlink_existing(const char *filename); + void util_strupr(char *); + bool util_string_equal(const char * s1 , const char * s2 ); + char * util_alloc_strupr_copy(const char * ); + void util_string_tr(char * , char , char); + bool util_copy_stream(FILE *, FILE *, int , void * , bool abort_on_error); void util_move_file(const char * src_file , const char * target_file); void util_move_file4( const char * src_name , const char * target_name , const char *src_path , const char * target_path); -bool util_copy_file(const char * , const char * ); -void util_copy_directory(const char * , const char * , const char *); -void util_walk_directory(const char * root_path , walk_file_callback_ftype * file_callback , void * file_callback_arg , walk_dir_callback_ftype * dir_callback , void * dir_callback_arg); -char * util_alloc_cwd(void); -char * util_alloc_realpath(const char * ); -bool util_string_match(const char * string , const char * pattern); -bool util_string_has_wildcard( const char * s); + bool util_copy_file(const char * , const char * ); + void util_copy_directory(const char * , const char * , const char *); + void util_walk_directory(const char * root_path , walk_file_callback_ftype * file_callback , void * file_callback_arg , walk_dir_callback_ftype * dir_callback , void * dir_callback_arg); + char * util_alloc_cwd(void); + char * util_alloc_realpath(const char * ); + bool util_string_match(const char * string , const char * pattern); + bool util_string_has_wildcard( const char * s); + bool util_entry_readable( const char * entry ); -#ifdef HAVE_UID_T -uid_t util_get_entry_uid( const char * file ); +#ifdef HAVE_GETUID + uid_t util_get_entry_uid( const char * file ); + bool util_addmode_if_owner( const char * filename , mode_t add_mode ); + bool util_delmode_if_owner( const char * filename , mode_t del_mode); + bool util_chmod_if_owner( const char * filename , mode_t new_mode); +#endif + +#ifdef HAVE_PROC + bool util_proc_alive(pid_t pid); #endif -bool util_entry_readable( const char * entry ); -bool util_addmode_if_owner( const char * filename , mode_t add_mode ); -bool util_delmode_if_owner( const char * filename , mode_t del_mode); -bool util_chmod_if_owner( const char * filename , mode_t new_mode); - -int util_forward_line(FILE * , bool * ); -void util_rewind_line(FILE *); -int util_count_content_file_lines(FILE * ); -int util_count_file_lines(FILE * ); -FILE * util_mkdir_fopen( const char * filename , const char * mode ); -FILE * util_fopen(const char * , const char *); -void util_fclose( FILE * stream ); -bool util_fopen_test(const char *, const char *); -void util_alloc_file_components(const char * , char ** , char **, char **); + + int util_forward_line(FILE * , bool * ); + void util_rewind_line(FILE *); + int util_count_content_file_lines(FILE * ); + int util_count_file_lines(FILE * ); + FILE * util_mkdir_fopen( const char * filename , const char * mode ); + int util_fmove( FILE * stream , long offset , long shift); + FILE * util_fopen(const char * , const char *); + void util_fclose( FILE * stream ); + bool util_fopen_test(const char *, const char *); + void util_alloc_file_components(const char * , char ** , char **, char **); //char * util_realloc_full_path(char * , const char *, const char *); -char * util_alloc_tmp_file(const char * , const char * , bool ); -char * util_fscanf_alloc_line(FILE *, bool *); -char * util_fscanf_realloc_line(FILE *, bool * , char *); -char * util_fscanf_alloc_token(FILE * ); -void util_fskip_token(FILE * ); -void util_fskip_space(FILE * , bool *); -void util_fskip_chars(FILE * , const char * , bool *); -void util_fskip_cchars(FILE * , const char * , bool *); -bool util_fscanf_int(FILE * , int * ); -bool util_fscanf_bool(FILE * stream , bool * value); -bool util_sscanf_bool(const char * , bool *); -bool util_sscanf_octal_int(const char * buffer , unsigned int * value); -int util_strcmp_int( const char * s1 , const char * s2); -int util_strcmp_float( const char * s1 , const char * s2); -bool util_sscanf_int(const char * , int * ); -const char * util_parse_int(const char * , int * , bool *); -const char * util_skip_sep(const char * , const char * , bool *); -int util_scanf_int_with_limits(const char * , int , int , int ); -char * util_scanf_int_with_limits_return_char(const char * , int , int , int ); -void util_printf_prompt(const char * , int , char , const char *); -int util_scanf_int(const char * , int); -char * util_scanf_int_return_char(const char * , int); -double util_scanf_double(const char * prompt , int prompt_len); -char * util_scanf_alloc_string(const char * ); -bool util_sscanf_double(const char * , double * ); + char * util_alloc_tmp_file(const char * , const char * , bool ); + char * util_fscanf_alloc_line(FILE *, bool *); + char * util_fscanf_realloc_line(FILE *, bool * , char *); + char * util_fscanf_alloc_token(FILE * ); + void util_fskip_token(FILE * ); + void util_fskip_space(FILE * , bool *); + void util_fskip_chars(FILE * , const char * , bool *); + void util_fskip_cchars(FILE * , const char * , bool *); + bool util_fscanf_int(FILE * , int * ); + bool util_fscanf_bool(FILE * stream , bool * value); + bool util_sscanf_bool(const char * , bool *); + bool util_sscanf_octal_int(const char * buffer , unsigned int * value); + int util_strcmp_int( const char * s1 , const char * s2); + int util_strcmp_float( const char * s1 , const char * s2); + bool util_sscanf_int(const char * , int * ); + const char * util_parse_int(const char * , int * , bool *); + const char * util_skip_sep(const char * , const char * , bool *); + int util_scanf_int_with_limits(const char * , int , int , int ); + char * util_scanf_int_with_limits_return_char(const char * , int , int , int ); + void util_printf_prompt(const char * , int , char , const char *); + int util_scanf_int(const char * , int); + char * util_scanf_int_return_char(const char * , int); + double util_scanf_double(const char * prompt , int prompt_len); + char * util_scanf_alloc_string(const char * ); + bool util_sscanf_double(const char * , double * ); //char * util_alloc_full_path(const char *, const char *); -char * util_alloc_filename(const char * , const char * , const char * ); -char * util_realloc_filename(char * , const char * , const char * , const char * ); -char * util_alloc_strip_copy(const char *); -char * util_realloc_strip_copy(char *); -void util_set_strip_copy(char * , const char *); -char * util_alloc_string_sum(const char ** , int); -char * util_strcat_realloc(char *, const char * ); -char * util_alloc_string_copy(const char *); -char ** util_stringlist_append_copy(char ** , int , const char * ); -char ** util_stringlist_append_ref(char ** , int , const char * ); -char ** util_alloc_stringlist_copy(const char **, int ); -void util_split_string(const char *, const char *, int *, char ***); -void util_path_split(const char * , int *, char ***); -void util_binary_split_string(const char * , const char * , bool , char ** , char ** ); -char * util_alloc_joined_string(const char ** , int , const char * ); -char * util_alloc_multiline_string(const char ** , int ); -char * util_string_replace_alloc(const char *, const char *, const char *); -char * util_string_replacen_alloc(const char *, int , const char ** , const char **); -int util_string_replace_inplace(char ** , const char * , const char *); -char * util_string_strip_chars_alloc(const char *, const char * ); -char * util_realloc_string_copy(char * , const char *); -char * util_realloc_substring_copy(char * , const char *, int ); -char * util_realloc_dequoted_string(char *); -char * util_alloc_dequoted_copy(const char *s); -void util_safe_free(void *); -void util_free_stringlist(char **, int ); -char * util_alloc_substring_copy(const char *, int ); -bool util_is_directory(const char * ); -bool util_is_file(const char * ); -void util_set_datetime_values(time_t , int * , int * , int * , int * , int * , int *); -void util_set_date_values(time_t , int * , int * , int * ); + char * util_alloc_filename(const char * , const char * , const char * ); + char * util_realloc_filename(char * , const char * , const char * , const char * ); + char * util_alloc_strip_copy(const char *); + char * util_realloc_strip_copy(char *); + void util_set_strip_copy(char * , const char *); + char * util_alloc_string_sum(const char ** , int); + char * util_strcat_realloc(char *, const char * ); + char * util_alloc_string_copy(const char *); + char ** util_stringlist_append_copy(char ** , int , const char * ); + char ** util_stringlist_append_ref(char ** , int , const char * ); + char ** util_alloc_stringlist_copy(const char **, int ); + void util_split_string(const char *, const char *, int *, char ***); + void util_path_split(const char * , int *, char ***); + void util_binary_split_string(const char * , const char * , bool , char ** , char ** ); + char * util_alloc_joined_string(const char ** , int , const char * ); + char * util_alloc_multiline_string(const char ** , int ); + char * util_string_replace_alloc(const char *, const char *, const char *); + char * util_string_replacen_alloc(const char *, int , const char ** , const char **); + int util_string_replace_inplace(char ** , const char * , const char *); + char * util_string_strip_chars_alloc(const char *, const char * ); + char * util_realloc_string_copy(char * , const char *); + char * util_realloc_substring_copy(char * , const char *, int ); + char * util_realloc_dequoted_string(char *); + char * util_alloc_dequoted_copy(const char *s); + void util_safe_free(void *); + void util_free_stringlist(char **, int ); + char * util_alloc_substring_copy(const char *, int ); + bool util_is_directory(const char * ); + bool util_is_file(const char * ); + void util_set_datetime_values(time_t , int * , int * , int * , int * , int * , int *); + void util_set_date_values(time_t , int * , int * , int * ); -void util_fread_from_buffer(void * , size_t , size_t , char ** ); - -unsigned int util_clock_seed( ); -void util_fread_dev_random(int , char * ); -void util_fread_dev_urandom(int , char * ); -char * util_alloc_string_copy(const char *); -void util_enkf_unlink_ensfiles(const char *, const char *, int , bool ); -bool util_string_isspace(const char * s); - -void util_exit(const char * fmt , ...); -void util_abort(const char * fmt , ...); -void util_abort_signal(int ); -void util_abort_append_version_info(const char * ); -void util_abort_free_version_info(); -void util_abort_set_executable( const char * executable ); -void * util_realloc(void * , size_t , const char * ); -void * util_malloc(size_t , const char * ); -void * util_realloc_copy(void * org_ptr , const void * src , size_t byte_size , const char * caller); -void * util_alloc_copy(const void * , size_t , const char * ); -void util_double_to_float(float * , const double * , int ); -void util_float_to_double(double * , const float * , int ); - -int util_get_month_nr(const char * ); - -char * util_fread_alloc_file_content(const char * , int *); -void util_fwrite_string(const char * , FILE *); -char * util_fread_realloc_string(char * , FILE *); -char * util_fread_alloc_string(FILE *); -void util_fskip_string(FILE *stream); -void util_endian_flip_vector(void *, int , int ); -bool util_proc_alive(pid_t pid); -int util_proc_mem_free(void); - - -void util_apply_int_limits(int * , int , int ); -void util_apply_float_limits(float * , float , float ); -void util_apply_double_limits(double * , double , double ); -double util_double_vector_mean(int , const double * ); -double util_double_vector_stddev(int , const double * ); -void util_double_vector_max_min(int , const double *, double * , double *); -void util_update_double_max_min(double , double * , double * ); -void util_update_float_max_min(float , float * , float * ); -void util_update_int_max_min(int , int * , int * ); -float util_float_max (float , float ); -long int util_long_max(long int a , long int b); -int util_int_max (int , int); -double util_double_max(double , double ); -float util_float_min (float , float ); -int util_int_min (int , int); -size_t util_size_t_min(size_t a , size_t b); -size_t util_size_t_max(size_t a , size_t b); -time_t util_time_t_min(time_t a , time_t b); -time_t util_time_t_max(time_t a , time_t b); -double util_double_min(double , double ); -void util_fskip_lines(FILE * , int); -bool util_same_file(const char * , const char * ); -void util_read_path(const char * , int , bool , char * ); -char * util_fscanf_alloc_filename(const char * , int , int); -void util_read_string(const char * , int , char * ); -void util_fread (void *, size_t , size_t , FILE * , const char * ); -void util_fwrite(const void *, size_t , size_t , FILE * , const char * ); -time_t util_fread_time_t(FILE * stream); -int util_fread_int(FILE * ); -long util_fread_long(FILE * ); -bool util_fread_bool(FILE * ); -double util_fread_double(FILE * stream); -void util_fwrite_int (int , FILE * ); -void util_fwrite_long (long , FILE * ); -void util_fwrite_bool (bool , FILE * ); -void util_fwrite_time_t (time_t , FILE * ); -void util_fwrite_double(double , FILE * ); -void util_fwrite_int_vector (const int * , int , FILE * , const char * ); -void util_fwrite_double_vector(const double * , int , FILE * , const char * ); -void util_fread_char_vector(char * , int , FILE * , const char * ); - -#define CONTAINS_HEADER(TYPE) int util_sorted_contains_ ## TYPE(const TYPE * data , int size , TYPE value); - CONTAINS_HEADER(int); - CONTAINS_HEADER(time_t); - CONTAINS_HEADER(size_t); -#undef CONTAINS_HEADER - -#ifdef HAVE_ZLIB -void util_compress_buffer(const void * , int , void * , unsigned long * ); -int util_fread_sizeof_compressed(FILE * stream); -void util_fread_compressed(void * , FILE * ); -void * util_fread_alloc_compressed(FILE * ); -void util_fwrite_compressed(const void * , int , FILE * ); -#endif - -void util_block_growing_file(const char * ); -void util_block_growing_directory(const char * ); -char * util_alloc_realpath(const char * ); -bool util_sscanf_bytesize(const char * , size_t *); -void util_sscanf_active_range(const char * , int , bool * ); -int * util_sscanf_alloc_active_list(const char * , int * ); -int util_get_current_linenr(FILE * stream); -const char * util_update_path_var(const char * , const char * , bool ); - - -int util_get_type( void * data ); -void util_fskip_int(FILE * stream); -void util_fskip_long(FILE * stream); -void util_fskip_bool(FILE * stream); -bool util_fseek_string(FILE * stream , const char * string , bool skip_string , bool case_sensitive); -char * util_fscanf_alloc_upto(FILE * stream , const char * stop_string, bool include_stop_string); -bool util_files_equal( const char * file1 , const char * file2 ); -double util_kahan_sum(const double *data, size_t N); -int util_fnmatch( const char * pattern , const char * string ); -void util_localtime( time_t * t , struct tm * ts ); - -char * util_alloc_PATH_executable(const char * executable ); -char * util_isscanf_alloc_envvar( const char * string , int env_index ); -void util_setenv( const char * variable , const char * value); -const char * util_interp_setenv( const char * variable , const char * value); -void util_unsetenv( const char * variable); -char * util_alloc_envvar( const char * value ); - -#ifdef HAVE_SYMLINK - bool util_is_link(const char * ); - void util_make_slink(const char *, const char * ); - char * util_alloc_link_target(const char * link); -#ifdef HAVE_READLINKAT - char * util_alloc_atlink_target(const char * path , const char * link); -#endif -#endif - -#ifdef HAVE_FORK -#include "util_fork.h" -#endif - - -#ifdef HAVE_LOCKF -FILE * util_fopen_lockf(const char * , const char * ); -bool util_try_lockf(const char * , mode_t , int * ); -#endif + void util_fread_from_buffer(void * , size_t , size_t , char ** ); + + unsigned int util_clock_seed( ); + void util_fread_dev_random(int , char * ); + void util_fread_dev_urandom(int , char * ); + char * util_alloc_string_copy(const char *); + void util_enkf_unlink_ensfiles(const char *, const char *, int , bool ); + bool util_string_isspace(const char * s); + + void util_exit(const char * fmt , ...); + void util_abort(const char * fmt , ...); + void util_abort_signal(int ); + void util_abort_append_version_info(const char * ); + void util_abort_free_version_info(); + void util_abort_set_executable( const char * executable ); + void * util_realloc(void * , size_t , const char * ); + void * util_malloc(size_t , const char * ); + void * util_realloc_copy(void * org_ptr , const void * src , size_t byte_size , const char * caller); + void * util_alloc_copy(const void * , size_t , const char * ); + void util_double_to_float(float * , const double * , int ); + void util_float_to_double(double * , const float * , int ); + + int util_get_month_nr(const char * ); + + char * util_fread_alloc_file_content(const char * , int *); + void util_fwrite_string(const char * , FILE *); + char * util_fread_realloc_string(char * , FILE *); + char * util_fread_alloc_string(FILE *); + void util_fskip_string(FILE *stream); + void util_endian_flip_vector(void *, int , int ); + int util_proc_mem_free(void); + + + void util_apply_int_limits(int * , int , int ); + void util_apply_float_limits(float * , float , float ); + void util_apply_double_limits(double * , double , double ); + double util_double_vector_mean(int , const double * ); + double util_double_vector_stddev(int , const double * ); + void util_double_vector_max_min(int , const double *, double * , double *); + void util_update_double_max_min(double , double * , double * ); + void util_update_float_max_min(float , float * , float * ); + void util_update_int_max_min(int , int * , int * ); + float util_float_max (float , float ); + long int util_long_max(long int a , long int b); + int util_int_max (int , int); + double util_double_max(double , double ); + float util_float_min (float , float ); + int util_int_min (int , int); + size_t util_size_t_min(size_t a , size_t b); + size_t util_size_t_max(size_t a , size_t b); + time_t util_time_t_min(time_t a , time_t b); + time_t util_time_t_max(time_t a , time_t b); + double util_double_min(double , double ); + void util_fskip_lines(FILE * , int); + bool util_same_file(const char * , const char * ); + void util_read_path(const char * , int , bool , char * ); + char * util_fscanf_alloc_filename(const char * , int , int); + void util_read_string(const char * , int , char * ); + void util_fread (void *, size_t , size_t , FILE * , const char * ); + void util_fwrite(const void *, size_t , size_t , FILE * , const char * ); + time_t util_fread_time_t(FILE * stream); + int util_fread_int(FILE * ); + long util_fread_long(FILE * ); + bool util_fread_bool(FILE * ); + double util_fread_double(FILE * stream); + void util_fwrite_int (int , FILE * ); + void util_fwrite_long (long , FILE * ); + void util_fwrite_bool (bool , FILE * ); + void util_fwrite_time_t (time_t , FILE * ); + void util_fwrite_double(double , FILE * ); + void util_fwrite_int_vector (const int * , int , FILE * , const char * ); + void util_fwrite_double_vector(const double * , int , FILE * , const char * ); + void util_fread_char_vector(char * , int , FILE * , const char * ); + int util_type_get_id( const void * data ); + + + void util_block_growing_file(const char * ); + void util_block_growing_directory(const char * ); + char * util_alloc_realpath(const char * ); + bool util_sscanf_bytesize(const char * , size_t *); + void util_sscanf_active_range(const char * , int , bool * ); + int * util_sscanf_alloc_active_list(const char * , int * ); + int util_get_current_linenr(FILE * stream); + const char * util_update_path_var(const char * , const char * , bool ); + + + int util_get_type( void * data ); + void util_fskip_int(FILE * stream); + void util_fskip_long(FILE * stream); + void util_fskip_bool(FILE * stream); + bool util_fseek_string(FILE * stream , const char * string , bool skip_string , bool case_sensitive); + char * util_fscanf_alloc_upto(FILE * stream , const char * stop_string, bool include_stop_string); + bool util_files_equal( const char * file1 , const char * file2 ); + double util_kahan_sum(const double *data, size_t N); + int util_fnmatch( const char * pattern , const char * string ); + void util_localtime( time_t * t , struct tm * ts ); + + char * util_alloc_PATH_executable(const char * executable ); + char * util_isscanf_alloc_envvar( const char * string , int env_index ); + void util_setenv( const char * variable , const char * value); + const char * util_interp_setenv( const char * variable , const char * value); + void util_unsetenv( const char * variable); + char * util_alloc_envvar( const char * value ); + bool util_is_link(const char * ); // Will always return false on windows #define UTIL_FWRITE_SCALAR(s,stream) { if (fwrite(&s , sizeof s , 1 , stream) != 1) util_abort("%s: write failed: %s\n",__func__ , strerror(errno)); } #define UTIL_FREAD_SCALAR(s,stream) { if (fread(&s , sizeof s , 1 , stream) != 1) util_abort("%s: read failed: %s\n",__func__ , strerror(errno)); } #define UTIL_FWRITE_VECTOR(s,n,stream) { if (fwrite(s , sizeof s , (n) , stream) != (n)) util_abort("%s: write failed: %s \n",__func__ , strerror(errno)); } #define UTIL_FREAD_VECTOR(s,n,stream) { if (fread(s , sizeof s , (n) , stream) != (n)) util_abort("%s: read failed: %s \n",__func__ , strerror(errno)); } + +#define CONTAINS_HEADER(TYPE) int util_sorted_contains_ ## TYPE(const TYPE * data , int size , TYPE value); + CONTAINS_HEADER(int); + CONTAINS_HEADER(time_t); + CONTAINS_HEADER(size_t); +#undef CONTAINS_HEADER /*****************************************************************/ /* @@ -491,6 +383,35 @@ typedef struct { const char * util_enum_iget( int index , int size , const util_enum_element_type * enum_defs , int * value); +/*****************************************************************/ +/* Conditional section below here */ + +#ifdef HAVE_ZLIB + void util_compress_buffer(const void * , int , void * , unsigned long * ); + int util_fread_sizeof_compressed(FILE * stream); + void util_fread_compressed(void * , FILE * ); + void * util_fread_alloc_compressed(FILE * ); + void util_fwrite_compressed(const void * , int , FILE * ); +#endif + +#ifdef HAVE_SYMLINK + void util_make_slink(const char *, const char * ); + char * util_alloc_link_target(const char * link); + #ifdef HAVE_READLINKAT + char * util_alloc_atlink_target(const char * path , const char * link); + #endif +#endif + +#ifdef HAVE_FORK +#include "util_fork.h" +#endif + + +#ifdef HAVE_LOCKF + FILE * util_fopen_lockf(const char * , const char * ); + bool util_try_lockf(const char * , mode_t , int * ); +#endif + diff --git a/ThirdParty/Ert/util/lib/libutil.a b/ThirdParty/Ert/util/lib/libutil.a index 459364b577..301b7d048e 100644 Binary files a/ThirdParty/Ert/util/lib/libutil.a and b/ThirdParty/Ert/util/lib/libutil.a differ diff --git a/ThirdParty/Ert/util/lib/libutil.so b/ThirdParty/Ert/util/lib/libutil.so new file mode 100644 index 0000000000..214f5ea4a5 Binary files /dev/null and b/ThirdParty/Ert/util/lib/libutil.so differ diff --git a/ThirdParty/Ert/well/include/well_branch.h b/ThirdParty/Ert/well/include/well_branch.h new file mode 100644 index 0000000000..773a68c02d --- /dev/null +++ b/ThirdParty/Ert/well/include/well_branch.h @@ -0,0 +1,42 @@ +/* + Copyright (C) 2012 Statoil ASA, Norway. + + The file 'well_branch.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __WELL_BRANCH_H__ +#define __WELL_BRANCH_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +#include + + typedef struct well_branch_struct well_branch_type; + + well_branch_type * well_branch_alloc(int branch_nr); + void well_branch_free( well_branch_type * branch ); + void well_branch_add_conn( well_branch_type * branch , const well_conn_type * connection ); + int well_branch_get_length( const well_branch_type * branch ); + const well_conn_type ** well_branch_get_connections( const well_branch_type * branch ); + int well_branch_get_nr( const well_branch_type * branch ); + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/ThirdParty/Ert/well/include/well_conn.h b/ThirdParty/Ert/well/include/well_conn.h index bc3c4d53c4..d6321909aa 100644 --- a/ThirdParty/Ert/well/include/well_conn.h +++ b/ThirdParty/Ert/well/include/well_conn.h @@ -26,6 +26,7 @@ extern "C" { #endif #include + #include #include diff --git a/ThirdParty/Ert/well/include/well_path.h b/ThirdParty/Ert/well/include/well_path.h new file mode 100644 index 0000000000..0b10f3322a --- /dev/null +++ b/ThirdParty/Ert/well/include/well_path.h @@ -0,0 +1,47 @@ +/* + Copyright (C) 2012 Statoil ASA, Norway. + + The file 'well_path.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef __WELL_PATH_H__ +#define __WELL_PATH_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + + + typedef struct well_path_struct well_path_type; + + well_path_type * well_path_alloc(const char * grid_name ); + void well_path_free( well_path_type * path ); + void well_path_add_conn( well_path_type * well_path , well_conn_type * conn); + well_branch_type * well_path_iget_branch( const well_path_type * well_path , int branch_nr); + void well_path_free__(void * arg); + int well_path_get_max_branches( const well_path_type * well_path ); + int well_path_get_num_active_branches( const well_path_type * well_path ); + const char * well_path_get_grid_name( const well_path_type * well_path ); + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/ThirdParty/Ert/well/include/well_state.h b/ThirdParty/Ert/well/include/well_state.h index 560795d705..82a936b8af 100644 --- a/ThirdParty/Ert/well/include/well_state.h +++ b/ThirdParty/Ert/well/include/well_state.h @@ -25,8 +25,10 @@ extern "C" { #endif #include + #include #include + #include #include diff --git a/ThirdParty/Ert/well/lib/libwell.a b/ThirdParty/Ert/well/lib/libwell.a index bea4a32aa3..892b519ebf 100644 Binary files a/ThirdParty/Ert/well/lib/libwell.a and b/ThirdParty/Ert/well/lib/libwell.a differ diff --git a/ThirdParty/Ert/well/lib/libwell.so b/ThirdParty/Ert/well/lib/libwell.so new file mode 100644 index 0000000000..0aa12b48cb Binary files /dev/null and b/ThirdParty/Ert/well/lib/libwell.so differ diff --git a/VisualizationModules/LibGeometry/cvfRay.cpp b/VisualizationModules/LibGeometry/cvfRay.cpp index 4f7efb2eed..484f185ea0 100644 --- a/VisualizationModules/LibGeometry/cvfRay.cpp +++ b/VisualizationModules/LibGeometry/cvfRay.cpp @@ -181,13 +181,13 @@ bool Ray::quadIntersect(const Vec3d& v1, const Vec3d& v2, const Vec3d& v3, const Vec3d v12 = v2 - v1; Vec3d v13 = v3 - v1; - Vec3d n = (v12 ^ v13).getNormalized(); + Vec3d n = (v12 ^ v13).getNormalized(); // Quad Average normal - double det = n * direction(); + double det = n * direction(); // Length of projection of Quad normal to ray direction if (det == 0.0f) { - return false; + return false; // Ray parallel to average quad plane. Not quite accurate if origin is close to quad } double t = n * ((v1 - origin()) / det); @@ -203,9 +203,9 @@ bool Ray::quadIntersect(const Vec3d& v1, const Vec3d& v2, const Vec3d& v3, const int i; for(i = 0; i < 4; i++) { - Vec3d bi_norm = -((pts[i+1]-pts[i]) ^ n).getNormalized(); + Vec3d bi_norm = -((pts[i+1] - pts[i]) ^ n).getNormalized(); // - (Edge x Quad normal) : Unit Vector in quad plane from edge into the quad - if (((fp-pts[i]) * bi_norm) < 0) + if (((fp - pts[i]) * bi_norm) < 0) { return false; } diff --git a/VisualizationModules/LibRender/cvfCamera.cpp b/VisualizationModules/LibRender/cvfCamera.cpp index f4794fc9cd..1f2341ba7a 100644 --- a/VisualizationModules/LibRender/cvfCamera.cpp +++ b/VisualizationModules/LibRender/cvfCamera.cpp @@ -684,7 +684,7 @@ void Camera::updateCachedValues() // Update the cached frustum m_cachedViewFrustum = computeViewFrustum(); - m_cachedViewFrustum.isOutside(Vec3d(0,0,0)); + // Update the front plane pixel size (height) CVF_ASSERT(m_viewport.notNull()); uint vpWidth = m_viewport->width(); diff --git a/cafAnimControl/cafAnimationToolBar.cpp b/cafAnimControl/cafAnimationToolBar.cpp index b6ef84e59c..8133354dfa 100644 --- a/cafAnimControl/cafAnimationToolBar.cpp +++ b/cafAnimControl/cafAnimationToolBar.cpp @@ -226,7 +226,9 @@ void AnimationToolBar::setTimeStepStrings(const QStringList& timeStepStrings) //-------------------------------------------------------------------------------------------------- void AnimationToolBar::setCurrentTimeStepIndex(int index) { + m_timestepCombo->blockSignals(true); m_timestepCombo->setCurrentIndex(index); + m_timestepCombo->blockSignals(false); } //-------------------------------------------------------------------------------------------------- diff --git a/cafPdmCvf/CMakeLists.txt b/cafPdmCvf/CMakeLists.txt index 28f1d9632e..e5a0bb326f 100644 --- a/cafPdmCvf/CMakeLists.txt +++ b/cafPdmCvf/CMakeLists.txt @@ -2,6 +2,11 @@ cmake_minimum_required (VERSION 2.8) project (cafPdmCvf) +include_directories( + ${cafProjectDataModel_SOURCE_DIR} + ${cafUserInterface_SOURCE_DIR} +) + add_library( ${PROJECT_NAME} cafPdmFieldCvfColor.cpp diff --git a/cafPdmCvf/cafPdmFieldCvfColor.cpp b/cafPdmCvf/cafPdmFieldCvfColor.cpp index f7622c5c52..50c7531611 100644 --- a/cafPdmCvf/cafPdmFieldCvfColor.cpp +++ b/cafPdmCvf/cafPdmFieldCvfColor.cpp @@ -17,12 +17,20 @@ // //################################################################################################## -#pragma once - #include #include "cvfLibCore.h" +// Includes needed for field editor registration +#include "cvfColor3.h" +#include "cafPdmUiColorEditor.h" +#include "cafFactory.h" +#include "cafPdmField.h" + +#include + +CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(caf::PdmUiColorEditor, cvf::Color3f); + void operator >> (QTextStream& str, cvf::Color3f& value) { QString text; diff --git a/cafProjectDataModel/CMakeLists.txt b/cafProjectDataModel/CMakeLists.txt index c64cea97ac..2c42da1509 100644 --- a/cafProjectDataModel/CMakeLists.txt +++ b/cafProjectDataModel/CMakeLists.txt @@ -6,6 +6,10 @@ add_library( ${PROJECT_NAME} cafPdmObject.cpp cafPdmDocument.cpp cafPdmField.cpp - cafPdmUiItem.cpp cafPdmPointer.cpp + cafPdmUiItem.cpp + cafPdmUiOrdering.cpp + cafPdmUiEditorHandle.cpp + cafPdmUiFieldEditorHandle.cpp + cafPdmUiObjectEditorHandle.cpp ) diff --git a/cafProjectDataModel/cafFactory.h b/cafProjectDataModel/cafFactory.h index 4c6c506cfc..1aa0a969cd 100644 --- a/cafProjectDataModel/cafFactory.h +++ b/cafProjectDataModel/cafFactory.h @@ -28,14 +28,21 @@ namespace caf //================================================================================================== /// A generic Factory class template /// Usage: - /// caf::Factory::instance()->registerCreator(key); + /// Initialization in source file (Initialization : + /// bool TypeToCreate_Factory_initialized = caf::Factory::instance()->registerCreator(key); + /*INIT_FACTORY(BaseType, KeyType,TypeToCreate ) + bool TypeToCreate_Factory_initialized = caf::Factory::instance()->registerCreator(QString("TypeToCreate"));*/ + /// When you need an object: /// BaseType* newObject = caf::Factory::instance()->create(key); //================================================================================================== template class Factory { + class ObjectCreatorBase; public: + typedef typename std::map::iterator iterator_type; + static Factory * instance() { static Factory* fact = new Factory; @@ -43,9 +50,9 @@ namespace caf } template< typename TypeToCreate > - void registerCreator(const KeyType& key) + bool registerCreator(const KeyType& key) { - std::map::iterator entryIt; + iterator_type entryIt; entryIt = m_factoryMap.find(key); if (entryIt == m_factoryMap.end()) @@ -57,12 +64,14 @@ namespace caf { assert(key != entryIt->first); // classNameKeyword has already been used assert(false); // To be sure .. + return false; } } - BaseType* create(const KeyType& key); + BaseType* create(const KeyType& key) { - std::map::iterator entryIt; + iterator_type entryIt; + entryIt = m_factoryMap.find(key); if (entryIt != m_factoryMap.end()) { @@ -74,11 +83,13 @@ namespace caf } } + private: Factory () {} ~Factory() { - std::map::iterator entryIt; + iterator_type entryIt; + for (entryIt = m_factoryMap.begin(); entryIt != m_factoryMap.end(); ++entryIt) { delete(entryIt->second); @@ -107,4 +118,4 @@ namespace caf }; -} //End of namespace caf +}//End of namespace caf diff --git a/cafProjectDataModel/cafPdmDocument.cpp b/cafProjectDataModel/cafPdmDocument.cpp index 7bf3001c09..f813abc9e4 100644 --- a/cafProjectDataModel/cafPdmDocument.cpp +++ b/cafProjectDataModel/cafPdmDocument.cpp @@ -61,7 +61,7 @@ void PdmObjectGroup::deleteObjects() //-------------------------------------------------------------------------------------------------- void PdmObjectGroup::removeNullPtrs() { - objects.removeAll(NULL); + objects.removeChildObject(NULL); } //-------------------------------------------------------------------------------------------------- diff --git a/cafProjectDataModel/cafPdmField.h b/cafProjectDataModel/cafPdmField.h index df689e5b6c..1c0985a029 100644 --- a/cafProjectDataModel/cafPdmField.h +++ b/cafProjectDataModel/cafPdmField.h @@ -22,7 +22,7 @@ #include "cafPdmUiItem.h" #include "cafPdmFieldImpl.h" - +#include #include #include @@ -34,6 +34,7 @@ namespace caf class PdmObject; template class PdmPointer; +class PdmUiFieldEditorHandle; //================================================================================================== /// Base class for all fields, making it possible to handle them generically @@ -42,12 +43,17 @@ template class PdmPointer; class PdmFieldHandle : public PdmUiItem { public: - PdmFieldHandle() { m_ownerObject = NULL; m_keyword = "UNDEFINED"; } + PdmFieldHandle() : m_isIOReadable(true), m_isIOWritable(true) { m_ownerObject = NULL; m_keyword = "UNDEFINED"; } virtual ~PdmFieldHandle() { } virtual void readFieldData(QXmlStreamReader& xmlStream) = 0; virtual void writeFieldData(QXmlStreamWriter& xmlStream) = 0; + bool isIOReadable() { return m_isIOReadable; } + bool isIOWritable() { return m_isIOWritable; } + void setIOWritable(bool isWritable) { m_isIOWritable = isWritable; } + void setIOReadable(bool isReadable) { m_isIOReadable = isReadable; } + void setKeyword(const QString& keyword) { m_keyword = keyword; } QString keyword() const { return m_keyword; } @@ -59,6 +65,7 @@ public: virtual QVariant uiValue() const { return QVariant(); } virtual void setValueFromUi(const QVariant& ) { } virtual void childObjects(std::vector* ) { } + virtual void removeChildObject(PdmObject* ) { } virtual QList valueOptions( bool* useOptionsOnly) { return QList(); } @@ -68,6 +75,9 @@ protected: PdmObject* m_ownerObject; private: QString m_keyword; + bool m_isIOReadable; + bool m_isIOWritable; + }; @@ -86,8 +96,8 @@ public: virtual ~PdmField() {} // Copy and assignment must ignore the default value. - PdmField(const PdmField& other) { assertValid(); m_fieldValue = other.m_fieldValue; } - PdmField(const DataType& fieldValue) { assertValid(); m_fieldValue = fieldValue; } + PdmField(const PdmField& other) : PdmFieldHandle() { assertValid(); m_fieldValue = other.m_fieldValue; } + PdmField(const DataType& fieldValue) : PdmFieldHandle() { assertValid(); m_fieldValue = fieldValue; } PdmField& operator= (const PdmField& other) { assertValid(); m_fieldValue = other.m_fieldValue; return *this; } PdmField& operator= (const DataType& fieldValue) { assertValid(); m_fieldValue = fieldValue; return *this; } @@ -135,7 +145,7 @@ class PdmField : public PdmFieldHandle { typedef DataType* DataTypePtr; public: - PdmField() { m_fieldValue = NULL; } + PdmField() : PdmFieldHandle() { m_fieldValue = NULL; } PdmField(const PdmField& other); PdmField(const DataTypePtr& fieldValue); virtual ~PdmField(); @@ -205,8 +215,7 @@ public: void clear(); void erase(size_t index); - void removeAll(DataType* pointer); - void deleteChildren(); + void deleteAllChildObjects(); // Reimplementation of PdmFieldhandle methods virtual void readFieldData(QXmlStreamReader& xmlStream); @@ -214,6 +223,8 @@ public: // Gui generalized methods virtual void childObjects(std::vector* objects); + virtual void removeChildObject(PdmObject* object); + private: void removeThisAsParentField(); void addThisAsParentField(); diff --git a/cafProjectDataModel/cafPdmField.inl b/cafProjectDataModel/cafPdmField.inl index 9417ae0e28..3338c1acaf 100644 --- a/cafProjectDataModel/cafPdmField.inl +++ b/cafProjectDataModel/cafPdmField.inl @@ -19,6 +19,7 @@ #include "cafPdmObject.h" #include +#include "cafPdmUiFieldEditorHandle.h" namespace caf { @@ -60,6 +61,9 @@ void caf::PdmField::setValueFromUi(const QVariant& uiValue) { assert(m_ownerObject != NULL); m_ownerObject->fieldChangedByUi(this, oldValue, newValue); + + // This assumes that all field editors are updated by an instance of PdmUiObjectEditorHandle + m_ownerObject->updateConnectedEditors(); } } @@ -185,6 +189,7 @@ void caf::PdmField::childObjects(std::vector* objects) //-------------------------------------------------------------------------------------------------- template caf::PdmField::PdmField(const PdmField& other) + : PdmFieldHandle() { if (m_fieldValue) m_fieldValue.rawPtr()->removeParentField(this); m_fieldValue = other.m_fieldValue; @@ -334,7 +339,7 @@ void PdmPointersField::clear() /// //-------------------------------------------------------------------------------------------------- template -void PdmPointersField::deleteChildren() +void PdmPointersField::deleteAllChildObjects() { size_t index; for (index = 0; index < m_pointers.size(); ++index) @@ -355,13 +360,14 @@ void PdmPointersField::erase(size_t index) m_pointers.erase(m_pointers.begin() + index); } - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- template -void PdmPointersField::removeAll(DataType* pointer) +void PdmPointersField::removeChildObject(PdmObject* object) { + DataType* pointer = dynamic_cast(object); + size_t index; std::vector< PdmPointer > tempPointers; tempPointers = m_pointers; @@ -379,6 +385,7 @@ void PdmPointersField::removeAll(DataType* pointer) } } + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -433,7 +440,7 @@ template } currentObject->readFields(xmlStream); - m_pointers.push_back(currentObject); + this->push_back(currentObject); // Skip comments and for some reason: Characters. The last bit should not be correct, // but Qt reports a character token between EndElement and StartElement @@ -490,4 +497,5 @@ void PdmPointersField::addThisAsParentField() } } + } //End of namespace caf diff --git a/cafProjectDataModel/cafPdmObject.cpp b/cafProjectDataModel/cafPdmObject.cpp index 3461285eaf..dfcfd85cf2 100644 --- a/cafProjectDataModel/cafPdmObject.cpp +++ b/cafProjectDataModel/cafPdmObject.cpp @@ -74,16 +74,23 @@ void PdmObject::readFields (QXmlStreamReader& xmlStream ) PdmFieldHandle* currentField = findField(name); if (currentField) { - // readFieldData assumes that the xmlStream points to first token of field content. - // After reading, the xmlStream is supposed to point to the first token after the field content. - // (typically an "endElement") - QXmlStreamReader::TokenType tt; - tt = xmlStream.readNext(); - currentField->readFieldData( xmlStream ); + if (currentField->isIOReadable()) + { + // readFieldData assumes that the xmlStream points to first token of field content. + // After reading, the xmlStream is supposed to point to the first token after the field content. + // (typically an "endElement") + QXmlStreamReader::TokenType tt; + tt = xmlStream.readNext(); + currentField->readFieldData( xmlStream ); + } + else + { + xmlStream.skipCurrentElement(); + } } else { - std::cout << "Warning: Could not find a field with name " << name.toLatin1().data() << " in the current object : " << classKeyword().toLatin1().data() << std::endl; + std::cout << "Line "<< xmlStream.lineNumber() << ": Warning: Could not find a field with name " << name.toLatin1().data() << " in the current object : " << classKeyword().toLatin1().data() << std::endl; xmlStream.skipCurrentElement(); } break; @@ -119,11 +126,14 @@ void PdmObject::writeFields(QXmlStreamWriter& xmlStream) std::vector::iterator it; for (it = m_fields.begin(); it != m_fields.end(); ++it) { - PdmFieldHandle* obj = *it; - QString keyword = obj->keyword(); - xmlStream.writeStartElement("", keyword); - obj->writeFieldData(xmlStream); - xmlStream.writeEndElement(); + PdmFieldHandle* field = *it; + if (field->isIOWritable()) + { + QString keyword = field->keyword(); + xmlStream.writeStartElement("", keyword); + field->writeFieldData(xmlStream); + xmlStream.writeEndElement(); + } } } @@ -198,6 +208,37 @@ void PdmObject::parentFields(std::vector& parentFields) const } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmObject::parentObjects(std::vector& objects) const +{ + std::vector parentFields; + this->parentFields(parentFields); + size_t i; + for (i = 0; i < parentFields.size(); i++) + { + objects.push_back(parentFields[i]->ownerObject()); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmObject::removeFromParentFields() +{ + std::vector parentFields; + this->parentFields(parentFields); + size_t i; + for (i = 0; i < parentFields.size(); i++) + { + parentFields[i]->removeChildObject(this); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- void PdmObject::addFieldNoDefault(PdmFieldHandle* field, const QString& keyword, PdmUiItemInfo * fieldDescription) { field->setUiItemInfo(fieldDescription); @@ -208,4 +249,33 @@ void PdmObject::addFieldNoDefault(PdmFieldHandle* field, const QString& keyword, m_fields.push_back(field); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmObject::uiOrdering(QString uiConfigName, PdmUiOrdering& uiOrdering) const +{ + this->defineUiOrdering(uiConfigName, uiOrdering); + if (!uiOrdering.forgetRemainingFields()) + { + // Add the remaining Fields To UiConfig + + for (size_t i = 0; i < m_fields.size(); ++i) + { + if (!uiOrdering.contains(m_fields[i])) + { + uiOrdering.add( m_fields[i]); + } + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmObject::editorAttribute(const PdmFieldHandle* field, QString uiConfigName, PdmUiEditorAttribute * attribute) +{ + this->defineEditorAttribute(field, uiConfigName, attribute); +} + + } //End of namespace caf diff --git a/cafProjectDataModel/cafPdmObject.h b/cafProjectDataModel/cafPdmObject.h index 4950f95c81..ab8b7954f4 100644 --- a/cafProjectDataModel/cafPdmObject.h +++ b/cafProjectDataModel/cafPdmObject.h @@ -20,6 +20,7 @@ #pragma once #include "cafPdmUiItem.h" +#include "cafPdmUiOrdering.h" #include "cafPdmPointer.h" #include @@ -28,11 +29,27 @@ class QXmlStreamReader; class QXmlStreamWriter; + +// Taken from gtest.h +// +// Due to C++ preprocessor weirdness, we need double indirection to +// concatenate two tokens when one of them is __LINE__. Writing +// +// foo ## __LINE__ +// +// will result in the token foo__LINE__, instead of foo followed by +// the current line number. For more details, see +// http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6 +#define PDM_OBJECT_STRING_CONCATENATE(foo, bar) PDM_OBJECT_STRING_CONCATENATE_IMPL_(foo, bar) +#define PDM_OBJECT_STRING_CONCATENATE_IMPL_(foo, bar) foo ## bar + + namespace caf { class PdmFieldHandle; template < class FieldDataType > class PdmField; +class PdmUiEditorAttribute; //================================================================================================== /// Macros helping in development of PDM objects @@ -51,7 +68,7 @@ public: \ #define CAF_PDM_SOURCE_INIT(ClassName, keyword) \ QString ClassName::classKeywordStatic() { return keyword; } \ - bool ClassName##_initialized = caf::PdmObjectFactory::instance()->registerCreator() + static bool PDM_OBJECT_STRING_CONCATENATE(pdm_object_factory_init_, __LINE__) = caf::PdmObjectFactory::instance()->registerCreator() /// InitObject sets up the user interface related information for the object /// Placed in the constructor of your PdmObject @@ -93,6 +110,9 @@ public: PdmObject() { } virtual ~PdmObject(); + /// The classKeyword method is overridden in subclasses by the CAF_PDM_HEADER_INIT macro + virtual QString classKeyword() = 0; + void readFields (QXmlStreamReader& inputStream ); void writeFields(QXmlStreamWriter& outputStream); @@ -100,9 +120,18 @@ public: void fields(std::vector& fields) const; /// The fields containing pointers to this PdmObject. Use ownerObject() on the fieldHandle to get the PdmObject parent. void parentFields(std::vector& fields) const; + /// Remove pointer to this from all parent fields + void removeFromParentFields(); - /// The classKeyword method is overridden in subclasses by the CAF_PDM_HEADER_INIT macro - virtual QString classKeyword() = 0; + /// + void parentObjects(std::vector& objects) const; + + /// Method to be called from the Ui classes creating Auto Gui to get the group information + /// supplied by the \sa defineUiOrdering method that can be reimplemented + void uiOrdering(QString uiConfigName, PdmUiOrdering& uiOrdering) const; + + /// For a specific field, return editor specific parameters used to customize the editor behavior.. + void editorAttribute(const PdmFieldHandle* field, QString uiConfigName, PdmUiEditorAttribute * attribute); // Virtual interface to override in subclasses to support special behaviour if needed public: // Virtual @@ -112,6 +141,7 @@ public: // Virtual /// Method to re-implement to supply option values for a specific field virtual QList calculateValueOptions(const PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly) { return QList(); } + // For later // virtual void editorAttributeChangedByUI(const PdmFieldHandle* field, QString uiConfigName, const PdmUiAttributeHandle * attributes); protected: // Virtual /// Method gets called from PdmDocument after all objects are read. @@ -120,6 +150,15 @@ protected: // Virtual /// Method gets called from PdmDocument before saving document. /// Re-implement to make sure your fields have correct data before saving virtual void setupBeforeSave() {}; + + /// Override to customize the order and grouping of the Gui. + /// Fill up the uiOrdering object with groups and field references to create the gui structure + /// If the uiOrdering is empty, it is interpreted as meaning all fields w/o grouping. + virtual void defineUiOrdering(QString uiConfigName, PdmUiOrdering& uiOrdering) const {} + + /// Override to provide editor specific data for the field and uiConfigName + virtual void defineEditorAttribute(const PdmFieldHandle* field, QString uiConfigName, PdmUiEditorAttribute * attribute) {} + public: /// operator= implemented to avoid copying the internal m_fields PdmObject& operator=(const PdmObject& ) { return *this; } diff --git a/cafProjectDataModel/cafPdmUIBindingNotes.h b/cafProjectDataModel/cafPdmUIBindingNotes.h index 88bae7a08a..0a9c8c91cc 100644 --- a/cafProjectDataModel/cafPdmUIBindingNotes.h +++ b/cafProjectDataModel/cafPdmUIBindingNotes.h @@ -5,37 +5,12 @@ namespace caf -class PdmFieldHandle -{ - // .... - - void removeFieldView(PdmUiFieldViewHandle* fieldView) { m_fieldViews.erase(fieldView); } - void addFieldView(PdmUiFieldViewHandle* fieldView) { m_fieldViews.insert(fieldView); } -private: - std::set m_fieldViews; - // .... - void setValueFromUI(...) - { - //... - std::set::iterator it; - for (it = m_fieldViews.begin(); it != m_fieldViews.end(); ++it) - { - m_fieldViews[i]->updateUiValue(); - } - - //... - } - -}; - - - class PdmUiItemInfo { // .... - QString m_editorType; // Int, type_info, className or ?? - int m_isHidden; - int m_isReadOnly; + const type_info* m_editorType; + int m_isHidden; + int m_isReadOnly; }; @@ -46,8 +21,8 @@ class PdmUiItem { // ... - QString editorType(const QString& uiConfigName); - void setEditorType(const QString& uiConfigName, const QString& editorKeyword); + const type_info* editorType(const QString& uiConfigName); + void setEditorType(const QString& uiConfigName, const type_info* editorType); bool isHidden(QString uiConfigName); void setHidden(QString uiConfigName, bool isHidden); @@ -67,12 +42,11 @@ private : - -class PdmUiConfiguration +class PdmUiOrdering { public: - PdmUiConfiguration(): m_forgetRemainingFields(false) { }; - virtual ~PdmUiConfiguration() + PdmUiOrdering(): m_forgetRemainingFields(false) { }; + virtual ~PdmUiOrdering() { for (size_t i = 0; i < m_createdGroups.size(); ++i) { @@ -87,21 +61,21 @@ public: group->setUiName(displayName); m_createdGroups.push_back(group); - m_config.push_back(group); + m_ordering.push_back(group); } - void add(PdmUiItem* item) { m_config.push_back(item); } + void add(PdmUiItem* item) { m_ordering.push_back(item); } bool forgetRemainingFields() const { return m_forgetRemainingFields; } void setForgetRemainingFields(bool val) { m_forgetRemainingFields = val; } - const std::vector& uiItems() const { return m_config; } + const std::vector& uiItems() const { return m_ordering; } private: // Private copy constructor and assignment to prevent this. (The vectors below will make trouble) - PdmUiConfiguration(const PdmUiConfiguration& other) { } - PdmUiConfiguration& operator= (const PdmUiConfiguration& other) { } + PdmUiOrdering(const PdmUiOrdering& other) { } + PdmUiOrdering& operator= (const PdmUiOrdering& other) { } - std::vector m_config; + std::vector m_ordering; std::vector m_createdGroups; /// Owned PdmUiGroups, for mem management bool m_forgetRemainingFields; @@ -110,47 +84,184 @@ private: -class PdmUiGroup : public PdmUiItem, PdmUiConfiguration +class PdmUiGroup : public PdmUiItem, PdmUiOrdering { virtual bool isGroup() { return true; } }; - class PdmObject : public PdmUiItem { public: /// For a specific field, return editor specific parameters used to customize the editor behavior.. - virtual void setUpUiAttribute(const PdmFieldHandle* field, QString uiConfigName, PdmUiAttributeHandle * attributes); + void editorAttribute(const PdmFieldHandle* field, QString uiConfigName, PdmUiEditorAttribute * attribute) + { + this->defineEditorAttribute(field, uiConfigName, attribute); + } + // For later // virtual void uiAttributeChangedByUI(const PdmFieldHandle* field, QString uiConfigName, const PdmUiAttributeHandle * attributes); // Method to be called from the Ui classes creating Auto Gui to get the group information - // supplied by the \sa setUpUIConfiguration method that can be reimplemented - - void uiConfiguration(QString uiConfigName, PdmUiConfiguration& uiConfig) + // supplied by the \sa defineUiOrdering method that can be reimplemented + void uiOrdering(QString uiConfigName, PdmUiOrdering& uiOrdering) { - this->setUpUIConfiguration(uiConfigName, uiConfig); - if (!uiConfig.forgetRemainingFields()) + this->defineUiOrdering(uiConfigName, uiOrdering); + if (!uiOrdering.forgetRemainingFields()) { - // Todo: add Remaining Fields To UiConfig - + // Add the remaining Fields To UiConfig + for (size_t i = 0; i < m_fields.size(); ++i) + { + if (!uiOrdering.contains(m_fields[i])) + { + uiOrdering.add( m_fields[i]); + } + } } } protected: - /// Fill up the UiConfig object with groups and field references to create the gui structure - /// If the uiConfig is empty, it is interpreted as meaning all fields w/o grouping. + /// Override to customize the order and grouping of the Gui. + /// Fill up the uiOrdering object with groups and field references to create the gui structure + /// If the uiOrdering is empty, it is interpreted as meaning all fields w/o grouping. + virtual void defineUiOrdering(QString uiConfigName, PdmUiOrdering& uiOrdering) {} - virtual void setUpUIConfiguration(QString uiConfigName, PdmUiConfiguration& uiConfig) ; + /// Override to provide editor specific data for the field and uiConfigName + virtual void defineEditorAttribute(const PdmFieldHandle* field, QString uiConfigName, PdmUiEditorAttribute * attribute) {} }; + + +class PdmUiObjectEditorHandle: public QObject +{ +public: + PdmUiObjectEditorHandle() : m_pdmObject(NULL) {} + ~PdmUiObjectEditorHandle() {} + /// + QWidget* getOrCreateWidget(QWidget* parent) + { + if (m_widget.isNull()) + { + m_widget = this->createWidget(parent); + } + return m_widget; + } + QWidget* widget() { return m_widget; } + + /// Virtual method to be overridden. Needs to set up the supplied widget + /// with all signals etc to make it communicate with this object + void setPdmObject(PdmObject* object, QString uiConfigName) { m_pdmObject = object; } + PdmObject* pdmObject() { return m_pdmObject; } + + virtual void updateUi(QString uiConfigName) = 0; + +protected: + + virtual QWidget* createWidget(QWidget* parent) = 0; + +private: + PdmObject* m_pdmObject; + QPointer m_widget; +}; + + + +class PdmUiFieldEditorHandle : public QObject +{ +public: + PdmUiFieldEditorHandle() : m_field(NULL) {} + ~PdmUiFieldEditorHandle() + { + if (m_field) m_field->removeFieldEditor(this); + + if (!m_combinedWidget.isNull()) delete m_combinedWidget; + if (!m_editorWidget.isNull()) delete m_editorWidget ; + if (!m_labelWidget.isNull()) delete m_labelWidget; + } + + /// + PdmFieldHandle* field() { return m_field; } + void setField(PdmFieldHandle * field) + { + if (m_field) m_field->removeFieldEditor(this); + m_field = field; + if (m_field) m_field->addFieldEditor(this); + } + + + void setValueToField(const QVariant& value) + { + if (m_field) m_field->setUiValue(value); + } + + void createWidgets(QWidget * parent) + { + if (m_combinedWidget.isNull()) m_combinedWidget = createCombinedWidget(parent); + if (m_editorWidget.isNull()) m_editorWidget = createEditorWidget(parent); + if (m_labelWidget.isNull()) m_labelWidget = createLabelWidget(parent); + } + + QWidget* combinedWidget() { return m_combinedWidget; } + QWidget* editorWidget() { return m_editorWidget; } + QWidget* labelWidget() { return m_labelWidget; } + +public: // Virtual interface to override + /// Update only the display of the data value, because some other view has changed it. + virtual void updateUiValue() = 0; + + /// Supposed to update all parts of the widgets, both visibility, sensitivity, decorations and field data + virtual void updateUi(QString uiConfigName) = 0; + + /// Supposed to do all wiring of singals and slots + virtual void connectUi() = 0; + +protected: // Virtual interface to override + /// Implement one of these, or both editor and label. The widgets will be used in the parent layout according to + /// being "Label" Editor" or a single combined widget. + + virtual QWidget* createCombinedWidget(QWidget * parent) { return NULL; } + virtual QWidget* createEditorWidget(QWidget * parent) { return NULL; } + virtual QWidget* createLabelWidget(QWidget * parent) { return NULL; } + +private: + PdmFieldHandle* m_field; + + QPointer m_combinedWidget; + QPointer m_editorWidget; + QPointer m_labelWidget; +}; + + +class PdmFieldHandle +{ + // .... + + void removeFieldEditor(PdmUiFieldEditorHandle* fieldView) { m_fieldEditors.erase(fieldView); } + void addFieldEditor(PdmUiFieldEditorHandle* fieldView) { m_fieldEditors.insert(fieldView); } +private: + std::set m_fieldEditors; + // .... + void setValueFromUI(...) + { + //... + std::set::iterator it; + for (it = m_fieldEditors.begin(); it != m_fieldEditors.end(); ++it) + { + m_fieldEditors[i]->updateUiValue(); + } + + //... + } + +}; + + class PdmPropertyWindow : public QWidget { public: @@ -196,7 +307,7 @@ public: m_currentObjectView = PdmObjViewFactory::instance()->create(object->editorType(m_uiConfigName)); if (!m_currentObjectView) { - m_currentObjectView = new PdmStdObjView(); + m_currentObjectView = new PdmUiDefaultObjectEditor(); } // Create widget to handle this @@ -213,119 +324,27 @@ public: } private: - PdmObjectViewHandle* m_currentObjectView; + PdmUiObjectEditorHandle* m_currentObjectView; QString m_uiConfigName; }; - -class PdmObjectViewHandle: public QObject +class PdmUiEditorAttribute { public: - PdmObjectViewHandle() : m_pdmObject(NULL) {} - ~PdmObjectViewHandle() {} - /// - QWidget* getOrCreateWidget(QWidget* parent) - { - if (m_widget.isNull()) - { - m_widget = this->createWidget(parent); - } - return m_widget; - } - QWidget* widget() { return m_widget; } - - /// Virtual method to be overridden. Needs to set up the supplied widget - /// with all signals etc to make it communicate with this object - void setPdmObject(PdmObject* object, QString uiConfigName) { m_pdmObject = object; } - PdmObject* pdmObject() { return m_pdmObject; } - - virtual void updateUi(QString uiConfigName) = 0; - -protected: - - virtual QWidget* createWidget(QWidget* parent) = 0; - -private: - PdmObject* m_pdmObject; - QPointer m_widget; + PdmUiEditorAttribute() {} + virtual ~PdmUiEditorAttribute() {} }; -class PdmUiFieldViewHandle : public QObject + +class PdmUiDefaultObjectEditor : PdmUiObjectEditorHandle { public: - PdmUiFieldViewHandle() : m_field(NULL) {} - ~PdmUiFieldViewHandle() - { - if (m_field) m_field->removeFieldView(this); - - if (!m_combinedWidget.isNull()) delete m_combinedWidget; - if (!m_editorWidget.isNull()) delete m_editorWidget ; - if (!m_labelWidget.isNull()) delete m_labelWidget; - } - - /// - PdmFieldHandle* field() { return m_field; } - void setField(PdmFieldHandle * field) - { - if (m_field) m_field->removeFieldView(this); - m_field = field; - if (m_field) m_field->addFieldView(this); - } - - - void setValueToField(const QVariant& value) - { - if (m_field) m_field->setUiValue(value); - } - - void createWidgets(QWidget * parent) - { - if (m_combinedWidget.isNull()) m_combinedWidget = createCombinedWidget(parent); - if (m_editorWidget.isNull()) m_editorWidget = createEditorWidget(parent); - if (m_labelWidget.isNull()) m_labelWidget = createLabelWidget(parent); - } - - QWidget* combinedWidget() { return m_combinedWidget; } - QWidget* editorWidget() { return m_editorWidget; } - QWidget* labelWidget() { return m_labelWidget; } - -public: // Virtual interface to override - /// Update only the display of the data value, because some other view has changed it. - virtual void updateUiValue() = 0; - - /// Supposed to update all parts of the widgets, both visibility, sensitivity, decorations and field data - virtual void updateUi(QString uiConfigName) = 0; - - /// Supposed to do all wiring of singals and slots - virtual void connectUi() = 0; - -protected: // Virtual interface to override - /// Implement one of these, or both editor and label. The widgets will be used in the parent layout according to - /// being "Label" Editor" or a single combined widget. - - virtual QWidget* createCombinedWidget(QWidget * parent) { return NULL; } - virtual QWidget* createEditorWidget(QWidget * parent) { return NULL; } - virtual QWidget* createLabelWidget(QWidget * parent) { return NULL; } - -private: - PdmFieldHandle* m_field; - - QPointer m_combinedWidget; - QPointer m_editorWidget; - QPointer m_labelWidget; -}; - - - -class PdmStdObjView : PdmObjectViewHandle -{ -public: - PdmStdObjView() {}; - ~PdmStdObjView() {} + PdmUiDefaultObjectEditor() {}; + ~PdmUiDefaultObjectEditor() {} protected: @@ -339,8 +358,8 @@ protected: virtual void updateUi(QString uiConfigName) { - PdmUiConfiguration config; - m_pdmObject->uiConfiguration(uiConfigName, &config); + PdmUiOrdering config; + m_pdmObject->uiOrdering(uiConfigName, &config); // Set all fieldViews to be unvisited std::map::iterator it; @@ -435,13 +454,13 @@ protected: else { PdmFieldHandle* field = dynamic_cast(uiItems[i]); - PdmUiFieldViewHandle* fvh = NULL; + PdmUiFieldEditorHandle* fvh = NULL; if (!field->isHidden(uiConfName)) { // Find or create FieldView - std::map::iterator it; + std::map::iterator it; it = m_fieldViews.find(field->keyword()); if (it == m_fieldViews.end()) @@ -502,7 +521,7 @@ protected: private: - std::map m_fieldViews; + std::map m_fieldViews; std::map > m_groupBoxes; std::map > m_newGroupBoxes; ///< used temporarily to store the new(complete) set of group boxes @@ -512,30 +531,23 @@ private: -caf::Factory::instance()->registerCreator(typeid(PdmField)); -caf::Factory::instance()->registerCreator(typeid(PdmField)); -caf::Factory::instance()->registerCreator(typeid(PdmField)); -caf::Factory::instance()->registerCreator(typeid(PdmField)); +caf::Factory::instance()->registerCreator(typeid(PdmField)); +caf::Factory::instance()->registerCreator(typeid(PdmField)); +caf::Factory::instance()->registerCreator(typeid(PdmField)); +caf::Factory::instance()->registerCreator(typeid(PdmField)); -caf::Factory::instance()->registerCreator(typeid(PdmUiFileEditor)); +caf::Factory::instance()->registerCreator(typeid(PdmUiFileEditor)); -class PdmUiAttributeHandle -{ -public: - PdmUiAttributeHandle() {} - virtual ~PdmUiAttributeHandle() {} -}; - -class PdmLineEditAttribute : public PdmUiAttributeHandle +class PdmUiLineEditorAttribute : public PdmUiEditorAttribute { }; -class PdmLineEditFieldView : public PdmUiFieldViewHandle +class PdmUiLineEditor : public PdmUiFieldEditorHandle { public: - PdmLineEditFieldView() {} - virtual ~PdmLineEditFieldView() {} + PdmUiLineEditor() {} + virtual ~PdmUiLineEditor() {} virtual void updateUiValue() @@ -563,8 +575,8 @@ public: m_lineEdit->setEnabled(!m_field->readOnly(uiConfigName)); m_label->setEnabled(!m_field->readOnly(uiConfigName)); - PdmLineEditAttribute leab; - m_field->ownerObject()->setUpUiAttribute(m_field, uiConfigName, &leab); + PdmUiLineEditorAttribute leab; + m_field->ownerObject()->defineEditorAttribute(m_field, uiConfigName, &leab); if (dynamic_cast*> (m_field)) { @@ -628,7 +640,7 @@ DemoPdmObj::DemoPdmObj() } -void DemoPdmObj::setUpUIConfiguration(QString uiConfigName, PdmUiConfiguration& uiConfig) +void DemoPdmObj::setUpUIConfiguration(QString uiConfigName, PdmUiOrdering& uiConfig) { if (uiConfigName == "DetailsView") { diff --git a/cafProjectDataModel/cafPdmUiEditorHandle.cpp b/cafProjectDataModel/cafPdmUiEditorHandle.cpp new file mode 100644 index 0000000000..6a01a8e719 --- /dev/null +++ b/cafProjectDataModel/cafPdmUiEditorHandle.cpp @@ -0,0 +1,45 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#include "cafPdmUiEditorHandle.h" +#include "cafPdmUiItem.h" + +namespace caf +{ + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +PdmUiEditorHandle::~PdmUiEditorHandle() +{ + if (m_pdmItem) m_pdmItem->removeFieldEditor(this); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiEditorHandle::bindToPdmItem(PdmUiItem* item) +{ + if (m_pdmItem) m_pdmItem->removeFieldEditor(this); + m_pdmItem = item; + if (m_pdmItem) m_pdmItem->addFieldEditor(this); +} + +} //End of namespace caf + diff --git a/cafProjectDataModel/cafPdmUiEditorHandle.h b/cafProjectDataModel/cafPdmUiEditorHandle.h new file mode 100644 index 0000000000..c0e2f6c345 --- /dev/null +++ b/cafProjectDataModel/cafPdmUiEditorHandle.h @@ -0,0 +1,75 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#pragma once +#include +#include +#include +#include "cafPdmUiItem.h" + +namespace caf +{ + +class PdmUiItem; + +//================================================================================================== +/// Abstract class to handle editors +//================================================================================================== + +class PdmUiEditorHandle: public QObject +{ +public: + PdmUiEditorHandle() : m_pdmItem(NULL) {} + virtual ~PdmUiEditorHandle(); + +public: + /// Virtual method to be overridden. Needs to set up the supplied widget + /// with all signals etc to make it communicate with this object + + void updateUi(const QString& uiConfigName) + { + m_currentConfigName = uiConfigName; + this->configureAndUpdateUi(uiConfigName); + }; + + void updateUi() + { + this->configureAndUpdateUi(m_currentConfigName); + }; + +protected: // Interface to override: + + /// Supposed to update all parts of the widgets, both visibility, sensitivity, decorations and field data + virtual void configureAndUpdateUi(const QString& uiConfigName) = 0; + +protected: + /// This needs to be called from subclass when connecting to a PdmField or Object + void bindToPdmItem(PdmUiItem* item); + PdmUiItem* pdmItem() { return m_pdmItem; } + +private: + friend PdmUiItem::~PdmUiItem(); + PdmUiItem* m_pdmItem; + QString m_currentConfigName; +}; + + + +} // End of namespace caf + diff --git a/cafProjectDataModel/cafPdmUiFieldEditorHandle.cpp b/cafProjectDataModel/cafPdmUiFieldEditorHandle.cpp new file mode 100644 index 0000000000..a820555fe2 --- /dev/null +++ b/cafProjectDataModel/cafPdmUiFieldEditorHandle.cpp @@ -0,0 +1,83 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#include "cafPdmUiFieldEditorHandle.h" +#include "cafPdmField.h" + +namespace caf +{ + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +PdmUiFieldEditorHandle::PdmUiFieldEditorHandle() +{ + m_combinedWidget = QPointer(); + m_editorWidget = QPointer(); + m_labelWidget = QPointer(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +PdmUiFieldEditorHandle::~PdmUiFieldEditorHandle() +{ + if (!m_combinedWidget.isNull()) delete m_combinedWidget; + if (!m_editorWidget.isNull()) delete m_editorWidget ; + if (!m_labelWidget.isNull()) delete m_labelWidget; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiFieldEditorHandle::setField(PdmFieldHandle * field) +{ + this->bindToPdmItem(field); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +PdmFieldHandle* PdmUiFieldEditorHandle::field() +{ + return dynamic_cast(pdmItem()); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiFieldEditorHandle::createWidgets(QWidget * parent) +{ + if (m_combinedWidget.isNull()) m_combinedWidget = createCombinedWidget(parent); + if (m_editorWidget.isNull()) m_editorWidget = createEditorWidget(parent); + if (m_labelWidget.isNull()) m_labelWidget = createLabelWidget(parent); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiFieldEditorHandle::setValueToField(const QVariant& value) +{ + if (field()) field()->setValueFromUi(value); +} + + +} //End of namespace caf + diff --git a/cafProjectDataModel/cafPdmUiFieldEditorHandle.h b/cafProjectDataModel/cafPdmUiFieldEditorHandle.h new file mode 100644 index 0000000000..87559c3f91 --- /dev/null +++ b/cafProjectDataModel/cafPdmUiFieldEditorHandle.h @@ -0,0 +1,123 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#pragma once +#include +#include + +#include "cafPdmUiItem.h" +#include +#include + +#include "cafFactory.h" + +#include "cafPdmUiEditorHandle.h" + +// Taken from gtest.h +// +// Due to C++ preprocessor weirdness, we need double indirection to +// concatenate two tokens when one of them is __LINE__. Writing +// +// foo ## __LINE__ +// +// will result in the token foo__LINE__, instead of foo followed by +// the current line number. For more details, see +// http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6 +#define PDM_FIELD_EDITOR_STRING_CONCATENATE(foo, bar) PDM_FIELD_EDITOR_STRING_CONCATENATE_IMPL_(foo, bar) +#define PDM_FIELD_EDITOR_STRING_CONCATENATE_IMPL_(foo, bar) foo ## bar + +namespace caf +{ + +//================================================================================================== +/// Macros helping in development of PDM UI editors +//================================================================================================== + +/// Create a QString based on a typename +#define qStringTypeName(TypeName) QString(typeid(TypeName).name()) + +/// CAF_PDM_UI_EDITOR_HEADER_INIT assists the factory used when creating editors +/// Place this in the header file inside the class definition of your PdmUiEditor + +#define CAF_PDM_UI_FIELD_EDITOR_HEADER_INIT \ +public: \ + static QString uiEditorTypeName() + + /// CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT implements editorTypeName() and registers the field editor in the field editor factory + /// Place this in the cpp file, preferably above the constructor + +#define CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT(EditorClassName) \ + QString EditorClassName::uiEditorTypeName() { return #EditorClassName; } \ + static bool PDM_FIELD_EDITOR_STRING_CONCATENATE(pdm_field_editor_registrate_, __LINE__) = caf::Factory::instance()->registerCreator(EditorClassName::uiEditorTypeName()) + +#define CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(EditorClassName, TypeName) \ + static bool PDM_FIELD_EDITOR_STRING_CONCATENATE(pdm_field_register_default_editor_, __LINE__) = caf::Factory::instance()->registerCreator(qStringTypeName(caf::PdmField)) + +class PdmUiGroup; +class PdmFieldHandle; + +//================================================================================================== +/// Abstract class to handle editors of PdmFields +//================================================================================================== + +class PdmUiFieldEditorHandle : public PdmUiEditorHandle +{ +public: + + PdmUiFieldEditorHandle(); + ~PdmUiFieldEditorHandle(); + + PdmFieldHandle* field(); + void setField(PdmFieldHandle * field); + + void createWidgets(QWidget * parent); + QWidget* combinedWidget() { return m_combinedWidget; } + QWidget* editorWidget() { return m_editorWidget; } + QWidget* labelWidget() { return m_labelWidget; } + +protected: // Virtual interface to override + /// Implement one of these, or both editor and label. The widgets will be used in the parent layout according to + /// being "Label" Editor" or a single combined widget. + + virtual QWidget* createCombinedWidget(QWidget * parent) { return NULL; } + virtual QWidget* createEditorWidget(QWidget * parent) { return NULL; } + virtual QWidget* createLabelWidget(QWidget * parent) { return NULL; } + + void setValueToField(const QVariant& value); + +private: + QPointer m_combinedWidget; + QPointer m_editorWidget; + QPointer m_labelWidget; +}; + +//================================================================================================== +/// Abstract base class to handle special editor dependent attributes +//================================================================================================== + +class PdmUiEditorAttribute +{ +public: + PdmUiEditorAttribute() {} + virtual ~PdmUiEditorAttribute() {} +}; + + +} // End of namespace caf + diff --git a/cafProjectDataModel/cafPdmUiItem.cpp b/cafProjectDataModel/cafPdmUiItem.cpp index 0777011dec..a544e10349 100644 --- a/cafProjectDataModel/cafPdmUiItem.cpp +++ b/cafProjectDataModel/cafPdmUiItem.cpp @@ -18,7 +18,7 @@ //################################################################################################## #include "cafPdmUiItem.h" - +#include "cafPdmUiEditorHandle.h" namespace caf { @@ -62,64 +62,168 @@ bool PdmOptionItemInfo::findValue(const QList& optionList , Q //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -const QString PdmUiItem::uiName() const +const QString PdmUiItem::uiName(QString uiConfigName) const { - if(m_dynamicItemInfo.m_uiName.isNull()) + const PdmUiItemInfo* conInfo = configInfo(uiConfigName); + const PdmUiItemInfo* defInfo = defaultInfo(); + const PdmUiItemInfo* sttInfo = m_staticItemInfo; + + if (conInfo && !(conInfo->m_uiName.isNull())) return conInfo->m_uiName; + if (defInfo && !(defInfo->m_uiName.isNull())) return defInfo->m_uiName; + if (sttInfo && !(sttInfo->m_uiName.isNull())) return sttInfo->m_uiName; + + return QString(""); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +const QIcon PdmUiItem::uiIcon(QString uiConfigName) const +{ + const PdmUiItemInfo* conInfo = configInfo(uiConfigName); + const PdmUiItemInfo* defInfo = defaultInfo(); + const PdmUiItemInfo* sttInfo = m_staticItemInfo; + + if (conInfo && !(conInfo->m_icon.isNull())) return conInfo->m_icon; + if (defInfo && !(defInfo->m_icon.isNull())) return defInfo->m_icon; + if (sttInfo && !(sttInfo->m_icon.isNull())) return sttInfo->m_icon; + + return QIcon(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +const QString PdmUiItem::uiToolTip(QString uiConfigName) const +{ + const PdmUiItemInfo* conInfo = configInfo(uiConfigName); + const PdmUiItemInfo* defInfo = defaultInfo(); + const PdmUiItemInfo* sttInfo = m_staticItemInfo; + + if (conInfo && !(conInfo->m_toolTip.isNull())) return conInfo->m_toolTip; + if (defInfo && !(defInfo->m_toolTip.isNull())) return defInfo->m_toolTip; + if (sttInfo && !(sttInfo->m_toolTip.isNull())) return sttInfo->m_toolTip; + + return QString(""); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +const QString PdmUiItem::uiWhatsThis(QString uiConfigName) const +{ + const PdmUiItemInfo* conInfo = configInfo(uiConfigName); + const PdmUiItemInfo* defInfo = defaultInfo(); + const PdmUiItemInfo* sttInfo = m_staticItemInfo; + + if (conInfo && !(conInfo->m_whatsThis.isNull())) return conInfo->m_whatsThis; + if (defInfo && !(defInfo->m_whatsThis.isNull())) return defInfo->m_whatsThis; + if (sttInfo && !(sttInfo->m_whatsThis.isNull())) return sttInfo->m_whatsThis; + + return QString(""); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool PdmUiItem::isUiHidden(QString uiConfigName) const +{ + const PdmUiItemInfo* conInfo = configInfo(uiConfigName); + const PdmUiItemInfo* defInfo = defaultInfo(); + const PdmUiItemInfo* sttInfo = m_staticItemInfo; + + if (conInfo && !(conInfo->m_isHidden == -1)) return conInfo->m_isHidden; + if (defInfo && !(defInfo->m_isHidden == -1)) return defInfo->m_isHidden; + if (sttInfo && !(sttInfo->m_isHidden == -1)) return sttInfo->m_isHidden; + + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool PdmUiItem::isUiReadOnly(QString uiConfigName /*= ""*/) +{ + const PdmUiItemInfo* conInfo = configInfo(uiConfigName); + const PdmUiItemInfo* defInfo = defaultInfo(); + const PdmUiItemInfo* sttInfo = m_staticItemInfo; + + if (conInfo && !(conInfo->m_isReadOnly == -1)) return conInfo->m_isReadOnly; + if (defInfo && !(defInfo->m_isReadOnly == -1)) return defInfo->m_isReadOnly; + if (sttInfo && !(sttInfo->m_isReadOnly == -1)) return sttInfo->m_isReadOnly; + + return false; +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString PdmUiItem::uiEditorTypeName(const QString& uiConfigName) const +{ + const PdmUiItemInfo* conInfo = configInfo(uiConfigName); + const PdmUiItemInfo* defInfo = defaultInfo(); + const PdmUiItemInfo* sttInfo = m_staticItemInfo; + + if (conInfo && !(conInfo->m_editorTypeName.isEmpty())) return conInfo->m_editorTypeName; + if (defInfo && !(defInfo->m_editorTypeName.isEmpty())) return defInfo->m_editorTypeName; + if (sttInfo && !(sttInfo->m_editorTypeName.isEmpty())) return sttInfo->m_editorTypeName; + + return QString(); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- + +const PdmUiItemInfo* PdmUiItem::configInfo(QString uiConfigName) const +{ + if (uiConfigName == "" || uiConfigName.isNull()) return NULL; + + std::map::const_iterator it; + it = m_configItemInfos.find(uiConfigName); + + if (it != m_configItemInfos.end()) return &(it->second); + + return NULL; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- + +const PdmUiItemInfo* PdmUiItem::defaultInfo() const +{ + std::map::const_iterator it; + it = m_configItemInfos.find(""); + + if (it != m_configItemInfos.end()) return &(it->second); + + return NULL; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiItem::updateConnectedEditors() +{ + std::set::iterator it; + for (it = m_editors.begin(); it != m_editors.end(); ++it) { - if(m_staticItemInfo) return m_staticItemInfo->m_uiName; - else return QString(""); - } - else - { - return m_dynamicItemInfo.m_uiName; + (*it)->updateUi(); } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -const QIcon PdmUiItem::uiIcon() const +PdmUiItem::~PdmUiItem() { - if(m_dynamicItemInfo.m_icon.isNull()) + std::set::iterator it; + for (it = m_editors.begin(); it != m_editors.end(); ++it) { - if(m_staticItemInfo) return m_staticItemInfo->m_icon; - else return QIcon(); - } - else - { - return m_dynamicItemInfo.m_icon; - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -const QString PdmUiItem::uiToolTip() const -{ - if(m_dynamicItemInfo.m_toolTip.isNull()) - { - if(m_staticItemInfo) return m_staticItemInfo->m_toolTip; - else return QString(""); - } - else - { - return m_dynamicItemInfo.m_toolTip; - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -const QString PdmUiItem::uiWhatsThis() const -{ - if(m_dynamicItemInfo.m_whatsThis.isNull()) - { - if(m_staticItemInfo) return m_staticItemInfo->m_whatsThis; - else return QString(""); - } - else - { - return m_dynamicItemInfo.m_whatsThis; + (*it)->m_pdmItem = NULL; } } diff --git a/cafProjectDataModel/cafPdmUiItem.h b/cafProjectDataModel/cafPdmUiItem.h index a623bc3b6b..7a22eb3ed1 100644 --- a/cafProjectDataModel/cafPdmUiItem.h +++ b/cafProjectDataModel/cafPdmUiItem.h @@ -21,6 +21,7 @@ #include #include #include +#include namespace caf { @@ -33,16 +34,24 @@ namespace caf class PdmUiItemInfo { public: - PdmUiItemInfo() {} + PdmUiItemInfo() + : m_editorTypeName(""), m_isHidden(-1) , m_isReadOnly(-1) + {} PdmUiItemInfo( QString uiName, QIcon icon = QIcon(), QString toolTip = "", QString whatsThis = "") - : m_uiName(uiName), m_icon(icon), m_toolTip(toolTip), m_whatsThis(whatsThis) + : m_uiName(uiName), m_icon(icon), m_toolTip(toolTip), m_whatsThis(whatsThis), + m_editorTypeName(""), m_isHidden(false) , m_isReadOnly(false) { } - QString m_uiName; - QString m_toolTip; - QString m_whatsThis; - QIcon m_icon; +private: + friend class PdmUiItem; + QString m_uiName; + QString m_toolTip; + QString m_whatsThis; + QIcon m_icon; + QString m_editorTypeName; ///< Use this exact type of editor to edit this UiItem + int m_isHidden; ///< UiItem should be hidden. -1 means not set + int m_isReadOnly; ///< UiItem should be insensitive, or read only. -1 means not set. }; //================================================================================================== @@ -68,6 +77,8 @@ public: unsigned int* indexToValue = NULL); }; +class PdmUiEditorHandle; + //================================================================================================== /// Base class for all datastructure items (fields or objects) to make them have information on /// how to display them in the GUI. All the information can have a static variant valid for all @@ -78,39 +89,59 @@ public: class PdmUiItem { public: - PdmUiItem() : m_staticItemInfo(NULL), m_isHidden(false) { } - virtual ~PdmUiItem() { } + PdmUiItem() : m_staticItemInfo(NULL) { } + virtual ~PdmUiItem(); // Copy and assignment to avoid hampering our internal pointer. - PdmUiItem(const PdmUiItem& ) : m_staticItemInfo(NULL) , m_isHidden(false) { } - PdmUiItem& operator=(const PdmUiItem& ) { return *this; } + PdmUiItem(const PdmUiItem& ) : m_staticItemInfo(NULL) { } + PdmUiItem& operator=(const PdmUiItem& ) { return *this; } - const QString uiName() const; - void setUiName(const QString& uiName) { m_dynamicItemInfo.m_uiName = uiName; } + const QString uiName(QString uiConfigName = "") const; + void setUiName(const QString& uiName, QString uiConfigName = "") { m_configItemInfos[uiConfigName].m_uiName = uiName; } - const QIcon uiIcon() const; - void setUiIcon(const QIcon& uiIcon) { m_dynamicItemInfo.m_icon = uiIcon; } + const QIcon uiIcon(QString uiConfigName = "") const; + void setUiIcon(const QIcon& uiIcon, QString uiConfigName = "") { m_configItemInfos[uiConfigName].m_icon = uiIcon; } - const QString uiToolTip() const; - void setUiToolTip(const QString& uiToolTip) { m_dynamicItemInfo.m_toolTip = uiToolTip; } + const QString uiToolTip(QString uiConfigName = "") const; + void setUiToolTip(const QString& uiToolTip, QString uiConfigName = "") { m_configItemInfos[uiConfigName].m_toolTip = uiToolTip; } - const QString uiWhatsThis() const; - void setUiWhatsThis(const QString& uiWhatsThis) { m_dynamicItemInfo.m_whatsThis = uiWhatsThis; } + const QString uiWhatsThis(QString uiConfigName = "") const; + void setUiWhatsThis(const QString& uiWhatsThis, QString uiConfigName = "") { m_configItemInfos[uiConfigName].m_whatsThis = uiWhatsThis; } - bool isHidden() const { return m_isHidden; } - void setHidden(bool isHidden) { m_isHidden = isHidden; } + bool isUiHidden(QString uiConfigName = "") const; + void setUiHidden(bool isHidden, QString uiConfigName = "") { m_configItemInfos[uiConfigName].m_isHidden = isHidden; } + bool isUiReadOnly(QString uiConfigName = ""); + void setUiReadOnly(bool isReadOnly, QString uiConfigName = "") { m_configItemInfos[uiConfigName].m_isReadOnly = isReadOnly; } + + QString uiEditorTypeName(const QString& uiConfigName) const; + void setUiEditorTypeName(const QString& editorTypeName, QString uiConfigName = "") { m_configItemInfos[uiConfigName].m_editorTypeName = editorTypeName; } + + virtual bool isUiGroup() { return false; } + + void updateConnectedEditors(); + +public: // Pdm-Private only //================================================================================================== /// This method sets the GUI description pointer, which is supposed to be statically allocated /// somewhere. the PdmGuiEntry class will not delete it in any way, and always trust it to be present. + /// Consider as PRIVATE to the PdmSystem //================================================================================================== - void setUiItemInfo(PdmUiItemInfo* itemInfo) { m_staticItemInfo = itemInfo; } + void setUiItemInfo(PdmUiItemInfo* itemInfo) { m_staticItemInfo = itemInfo; } + + void removeFieldEditor(PdmUiEditorHandle* fieldView) { m_editors.erase(fieldView); } + void addFieldEditor(PdmUiEditorHandle* fieldView) { m_editors.insert(fieldView); } + +protected: + std::set m_editors; private: - PdmUiItemInfo* m_staticItemInfo; - PdmUiItemInfo m_dynamicItemInfo; - bool m_isHidden; + const PdmUiItemInfo* defaultInfo() const; + const PdmUiItemInfo* configInfo(QString uiConfigName) const; + + PdmUiItemInfo* m_staticItemInfo; + std::map< QString, PdmUiItemInfo > m_configItemInfos; }; diff --git a/cafProjectDataModel/cafPdmUiObjectEditorHandle.cpp b/cafProjectDataModel/cafPdmUiObjectEditorHandle.cpp new file mode 100644 index 0000000000..d1892e5291 --- /dev/null +++ b/cafProjectDataModel/cafPdmUiObjectEditorHandle.cpp @@ -0,0 +1,56 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#include "cafPdmUiObjectEditorHandle.h" +#include "cafPdmObject.h" + +namespace caf +{ + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QWidget* PdmUiObjectEditorHandle::getOrCreateWidget(QWidget* parent) +{ + if (m_widget.isNull()) + { + m_widget = this->createWidget(parent); + } + return m_widget; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiObjectEditorHandle::setPdmObject(PdmObject* object) +{ + this->bindToPdmItem(object); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +PdmObject* PdmUiObjectEditorHandle::pdmObject() +{ + return dynamic_cast(pdmItem()); +} + +} //End of namespace caf + diff --git a/cafProjectDataModel/cafPdmUiObjectEditorHandle.h b/cafProjectDataModel/cafPdmUiObjectEditorHandle.h new file mode 100644 index 0000000000..954880b170 --- /dev/null +++ b/cafProjectDataModel/cafPdmUiObjectEditorHandle.h @@ -0,0 +1,59 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#pragma once +#include +#include +#include +#include +#include "cafPdmUiEditorHandle.h" +#include "cafPdmPointer.h" + +namespace caf +{ + +class PdmObject; + +//================================================================================================== +/// Abstract class to handle editors for complete PdmObjects +//================================================================================================== + +class PdmUiObjectEditorHandle: public PdmUiEditorHandle +{ +public: + PdmUiObjectEditorHandle() {} + ~PdmUiObjectEditorHandle() {} + + QWidget* getOrCreateWidget(QWidget* parent); + QWidget* widget() { return m_widget; } + + void setPdmObject(PdmObject* object); + PdmObject* pdmObject(); + +protected: + virtual QWidget* createWidget(QWidget* parent) = 0; + +protected: + QPointer m_widget; +}; + + + +} // End of namespace caf + diff --git a/cafProjectDataModel/cafPdmUiOrdering.cpp b/cafProjectDataModel/cafPdmUiOrdering.cpp new file mode 100644 index 0000000000..73447dd78e --- /dev/null +++ b/cafProjectDataModel/cafPdmUiOrdering.cpp @@ -0,0 +1,70 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#include "cafPdmUiOrdering.h" + + +namespace caf +{ + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +PdmUiOrdering::~PdmUiOrdering() +{ + for (size_t i = 0; i < m_createdGroups.size(); ++i) + { + delete m_createdGroups[i]; + m_createdGroups[i] = NULL; + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +PdmUiGroup* PdmUiOrdering::addNewGroup(QString displayName) +{ + PdmUiGroup* group = new PdmUiGroup; + group->setUiName(displayName); + + m_createdGroups.push_back(group); + m_ordering.push_back(group); + + return group; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool PdmUiOrdering::contains(const PdmUiItem* item) +{ + for (size_t i = 0; i < m_ordering.size(); ++i) + { + if (m_ordering[i] == item) return true; + if (m_ordering[i] && m_ordering[i]->isUiGroup()) + { + if (static_cast(m_ordering[i])->contains(item)) return true; + } + } + return false; +} + +} //End of namespace caf + diff --git a/cafProjectDataModel/cafPdmUiOrdering.h b/cafProjectDataModel/cafPdmUiOrdering.h new file mode 100644 index 0000000000..9ef651ba4f --- /dev/null +++ b/cafProjectDataModel/cafPdmUiOrdering.h @@ -0,0 +1,75 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#pragma once +#include +#include + +#include "cafPdmUiItem.h" + +namespace caf +{ + +class PdmUiGroup; + +//================================================================================================== +/// Class storing the order and grouping of fields and groups of fields etc. to be used in the Gui +//================================================================================================== + +class PdmUiOrdering +{ +public: + PdmUiOrdering(): m_forgetRemainingFields(false) { }; + virtual ~PdmUiOrdering(); + + PdmUiGroup* addNewGroup(QString displayName); + void add(PdmUiItem* item) { m_ordering.push_back(item); } + + /// HACK constness of this class and functions must be revisited + void add(const PdmUiItem* item) { m_ordering.push_back(const_cast(item)); } + + bool forgetRemainingFields() const { return m_forgetRemainingFields; } + void setForgetRemainingFields(bool val) { m_forgetRemainingFields = val; } + + const std::vector& uiItems() const { return m_ordering; } + bool contains(const PdmUiItem* item); + +private: + // Private copy constructor and assignment to prevent this. (The vectors below will make trouble) + PdmUiOrdering(const PdmUiOrdering& other) { } + PdmUiOrdering& operator= (const PdmUiOrdering& other) { } + + std::vector m_ordering; ///< The order of groups and fields + std::vector m_createdGroups; ///< Owned PdmUiGroups, for mem management + bool m_forgetRemainingFields; +}; + +//================================================================================================== +/// Class representing a group of fields +//================================================================================================== + +class PdmUiGroup : public PdmUiItem, public PdmUiOrdering +{ + virtual bool isUiGroup() { return true; } +}; + + + +} // End of namespace caf + diff --git a/cafUserInterface/CMakeLists.txt b/cafUserInterface/CMakeLists.txt index 7f10a829fd..d7a7769f3e 100644 --- a/cafUserInterface/CMakeLists.txt +++ b/cafUserInterface/CMakeLists.txt @@ -4,15 +4,23 @@ project (cafUserInterface) include_directories( ${cafProjectDataModel_SOURCE_DIR} - ${QtPropertyBrowser_SOURCE_DIR} ) # These headers need to go through Qt's MOC compiler set( QOBJECT_HEADERS cafBasicAboutDialog.h cafUiTreeModelPdm.h - cafUiPropertyCreatorPdm.h cafUiProcess.h + + cafPdmUiLineEditor.h + cafPdmUiCheckBoxEditor.h + cafPdmUiComboBoxEditor.h + cafPdmUiFilePathEditor.h + cafPdmUiListEditor.h + cafPdmUiSliderEditor.h + cafPdmUiColorEditor.h + + cafPdmUiPropertyView.h ) qt4_wrap_cpp( MOC_FILES_CPP ${QOBJECT_HEADERS} ) @@ -21,7 +29,18 @@ qt4_wrap_cpp( MOC_FILES_CPP ${QOBJECT_HEADERS} ) add_library( ${PROJECT_NAME} cafBasicAboutDialog.cpp cafUiTreeModelPdm.cpp - cafUiPropertyCreatorPdm.cpp cafUiProcess.cpp + cafPdmUiDefaultObjectEditor.cpp + cafProgressInfo.cpp + + cafPdmUiLineEditor.cpp + cafPdmUiCheckBoxEditor.cpp + cafPdmUiComboBoxEditor.cpp + cafPdmUiFilePathEditor.cpp + cafPdmUiListEditor.cpp + cafPdmUiSliderEditor.cpp + cafPdmUiColorEditor.cpp + + cafPdmUiPropertyView.cpp ${MOC_FILES_CPP} ) diff --git a/cafUserInterface/cafPdmUiCheckBoxEditor.cpp b/cafUserInterface/cafPdmUiCheckBoxEditor.cpp new file mode 100644 index 0000000000..755ec4842b --- /dev/null +++ b/cafUserInterface/cafPdmUiCheckBoxEditor.cpp @@ -0,0 +1,100 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#include "cafPdmUiCheckBoxEditor.h" + +#include "cafPdmUiDefaultObjectEditor.h" + +#include "cafPdmObject.h" +#include "cafPdmUiFieldEditorHandle.h" +#include "cafPdmUiOrdering.h" +#include "cafPdmField.h" + +#include "cafFactory.h" + +#include + + +namespace caf +{ + +CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT(PdmUiCheckBoxEditor); + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiCheckBoxEditor::configureAndUpdateUi(const QString& uiConfigName) +{ + assert(!m_checkBox.isNull()); + assert(!m_label.isNull()); + + QIcon ic = field()->uiIcon(uiConfigName); + if (!ic.isNull()) + { + m_label->setPixmap(ic.pixmap(ic.actualSize(QSize(64, 64)))); + } + else + { + m_label->setText(field()->uiName(uiConfigName)); + } + + m_label->setVisible(!field()->isUiHidden(uiConfigName)); + m_label->setEnabled(!field()->isUiReadOnly(uiConfigName)); + + m_checkBox->setEnabled(!field()->isUiReadOnly(uiConfigName)); + + PdmUiCheckBoxEditorAttribute attributes; + field()->ownerObject()->editorAttribute(field(), uiConfigName, &attributes); + + m_checkBox->setChecked(field()->uiValue().toBool()); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QWidget* PdmUiCheckBoxEditor::createEditorWidget(QWidget * parent) +{ + m_checkBox = new QCheckBox(parent); + connect(m_checkBox, SIGNAL(clicked(bool)), this, SLOT(slotClicked(bool))); + return m_checkBox; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QWidget* PdmUiCheckBoxEditor::createLabelWidget(QWidget * parent) +{ + m_label = new QLabel(parent); + return m_label; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiCheckBoxEditor::slotClicked(bool checked) +{ + QVariant v; + v = checked; + this->setValueToField(v); +} + + +} // end namespace caf diff --git a/cafUserInterface/cafPdmUiCheckBoxEditor.h b/cafUserInterface/cafPdmUiCheckBoxEditor.h new file mode 100644 index 0000000000..68bb512e28 --- /dev/null +++ b/cafUserInterface/cafPdmUiCheckBoxEditor.h @@ -0,0 +1,64 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#pragma once +#include "cafPdmUiFieldEditorHandle.h" + +#include +#include +#include +#include + +namespace caf +{ + +//================================================================================================== +/// The default editor for several PdmFields. +//================================================================================================== + +class PdmUiCheckBoxEditorAttribute : public PdmUiEditorAttribute +{ + +}; + + +class PdmUiCheckBoxEditor : public PdmUiFieldEditorHandle +{ + Q_OBJECT + CAF_PDM_UI_FIELD_EDITOR_HEADER_INIT; + +public: + PdmUiCheckBoxEditor() {} + virtual ~PdmUiCheckBoxEditor() {} + +protected: + virtual QWidget* createEditorWidget(QWidget * parent); + virtual QWidget* createLabelWidget(QWidget * parent); + virtual void configureAndUpdateUi(const QString& uiConfigName); + +protected slots: + void slotClicked(bool checked); + +private: + QPointer m_checkBox; + QPointer m_label; +}; + + +} // end namespace caf diff --git a/cafUserInterface/cafPdmUiColorEditor.cpp b/cafUserInterface/cafPdmUiColorEditor.cpp new file mode 100644 index 0000000000..640326c0ef --- /dev/null +++ b/cafUserInterface/cafPdmUiColorEditor.cpp @@ -0,0 +1,178 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#include "cafPdmUiColorEditor.h" + +#include "cafPdmUiDefaultObjectEditor.h" + +#include "cafPdmObject.h" +#include "cafPdmUiFieldEditorHandle.h" +#include "cafPdmUiOrdering.h" +#include "cafPdmField.h" + +#include "cafFactory.h" + +#include +#include +#include +#include +#include +#include + +#include + + +namespace caf +{ + +CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT(PdmUiColorEditor); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +PdmUiColorEditor::PdmUiColorEditor() +{ + m_color = QColor::Invalid; +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiColorEditor::configureAndUpdateUi(const QString& uiConfigName) +{ + assert(!m_label.isNull()); + + QIcon ic = field()->uiIcon(uiConfigName); + if (!ic.isNull()) + { + m_label->setPixmap(ic.pixmap(ic.actualSize(QSize(64, 64)))); + } + else + { + m_label->setText(field()->uiName(uiConfigName)); + } + + m_label->setVisible(!field()->isUiHidden(uiConfigName)); + m_label->setEnabled(!field()->isUiReadOnly(uiConfigName)); + + field()->ownerObject()->editorAttribute(field(), uiConfigName, &m_attributes); + + QColor col = field()->uiValue().value(); + setColor(col); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QWidget* PdmUiColorEditor::createEditorWidget(QWidget * parent) +{ + QWidget* placeholder = new QWidget(parent); + + QHBoxLayout* layout = new QHBoxLayout(placeholder); + layout->setMargin(0); + layout->setSpacing(0); + + m_colorPixmapLabel = new QLabel(parent); + m_colorTextLabel = new QLabel(parent); + + QToolButton* button = new QToolButton(parent); + button->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred)); + button->setText(QLatin1String("...")); + + layout->addWidget(m_colorPixmapLabel); + layout->addWidget(m_colorTextLabel); + layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Ignored)); + layout->addWidget(button); + + connect(button, SIGNAL(clicked()), this, SLOT(colorSelectionClicked())); + + return placeholder; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QWidget* PdmUiColorEditor::createLabelWidget(QWidget * parent) +{ + m_label = new QLabel(parent); + return m_label; +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiColorEditor::colorSelectionClicked() +{ + bool ok = false; + + QColorDialog::ColorDialogOptions flags; + if (m_attributes.showAlpha) + { + flags |= QColorDialog::ShowAlphaChannel; + } + + QColor newColor = QColorDialog::getColor(m_color, m_colorPixmapLabel, "Select color", flags); + if (newColor.isValid() && newColor != m_color) + { + setColor(newColor); + } +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiColorEditor::setColor(const QColor& color) +{ + if (m_color != color) + { + m_color = color; + + QPixmap tmp(16, 16); + tmp.fill(m_color); + m_colorPixmapLabel->setPixmap(tmp); + + QString colorString; + if (!color.isValid()) + { + colorString = "Undefined"; + } + else + { + colorString = QString("[%1, %2, %3]").arg(QString::number(color.red())).arg(QString::number(color.green())).arg(QString::number(color.blue())); + + if (m_attributes.showAlpha) + { + colorString += QString(" (%4)").arg(QString::number(color.alpha())); + } + } + + m_colorTextLabel->setText(colorString); + } + + QVariant v; + v = m_color; + this->setValueToField(v); +} + + +} // end namespace caf diff --git a/cafUserInterface/cafPdmUiColorEditor.h b/cafUserInterface/cafPdmUiColorEditor.h new file mode 100644 index 0000000000..367f09b8b6 --- /dev/null +++ b/cafUserInterface/cafPdmUiColorEditor.h @@ -0,0 +1,84 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#pragma once + +#include "cafPdmUiFieldEditorHandle.h" + +#include +#include +#include +#include +#include + + +namespace caf +{ + +//================================================================================================== +/// +//================================================================================================== +class PdmUiColorEditorAttribute : public PdmUiEditorAttribute +{ +public: + bool showAlpha; + +public: + PdmUiColorEditorAttribute() + { + showAlpha = false; + } +}; + + +//================================================================================================== +/// See cafPdmFieldCvfColor for conversion between cvf::Color3f and QColor +//================================================================================================== +class PdmUiColorEditor : public PdmUiFieldEditorHandle +{ + Q_OBJECT + CAF_PDM_UI_FIELD_EDITOR_HEADER_INIT; + +public: + PdmUiColorEditor(); + virtual ~PdmUiColorEditor() {} + +protected: + virtual QWidget* createEditorWidget(QWidget * parent); + virtual QWidget* createLabelWidget(QWidget * parent); + virtual void configureAndUpdateUi(const QString& uiConfigName); + +protected slots: + void colorSelectionClicked(); + +private: + void setColor(const QColor& c); + +private: + QPointer m_label; + + QColor m_color; + QPointer m_colorPixmapLabel; + QPointer m_colorTextLabel; + + PdmUiColorEditorAttribute m_attributes; +}; + + +} // end namespace caf diff --git a/cafUserInterface/cafPdmUiComboBoxEditor.cpp b/cafUserInterface/cafPdmUiComboBoxEditor.cpp new file mode 100644 index 0000000000..0f163faf8a --- /dev/null +++ b/cafUserInterface/cafPdmUiComboBoxEditor.cpp @@ -0,0 +1,112 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#include "cafPdmUiComboBoxEditor.h" + +#include "cafPdmObject.h" +#include "cafPdmUiFieldEditorHandle.h" +#include "cafPdmField.h" + +#include "cafFactory.h" + +#include +#include + +#include + + +namespace caf +{ + +CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT(PdmUiComboBoxEditor); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiComboBoxEditor::configureAndUpdateUi(const QString& uiConfigName) +{ + assert(!m_comboBox.isNull()); + assert(!m_label.isNull()); + + QIcon ic = field()->uiIcon(uiConfigName); + if (!ic.isNull()) + { + m_label->setPixmap(ic.pixmap(ic.actualSize(QSize(64, 64)))); + } + else + { + m_label->setText(field()->uiName(uiConfigName)); + } + + m_label->setVisible(!field()->isUiHidden(uiConfigName)); + m_label->setEnabled(!field()->isUiReadOnly(uiConfigName)); + + m_comboBox->setEnabled(!field()->isUiReadOnly(uiConfigName)); + + bool fromMenuOnly = false; + QList enumNames = field()->valueOptions(&fromMenuOnly); + if (!enumNames.isEmpty() && fromMenuOnly == true) + { + m_comboBox->blockSignals(true); + m_comboBox->clear(); + m_comboBox->addItems(PdmOptionItemInfo::extractUiTexts(enumNames)); + m_comboBox->blockSignals(false); + } + + PdmUiComboBoxEditorAttribute attributes; + field()->ownerObject()->editorAttribute(field(), uiConfigName, &attributes); + + m_comboBox->setCurrentIndex(field()->uiValue().toInt()); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QWidget* PdmUiComboBoxEditor::createEditorWidget(QWidget * parent) +{ + m_comboBox = new QComboBox(parent); + connect(m_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentIndexChanged(int))); + return m_comboBox; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QWidget* PdmUiComboBoxEditor::createLabelWidget(QWidget * parent) +{ + m_label = new QLabel(parent); + return m_label; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiComboBoxEditor::slotCurrentIndexChanged(int index) +{ + QVariant v; + v = index; + + QVariant uintValue(v.toUInt()); + this->setValueToField(uintValue); +} + + + +} // end namespace caf diff --git a/cafUserInterface/cafPdmUiComboBoxEditor.h b/cafUserInterface/cafPdmUiComboBoxEditor.h new file mode 100644 index 0000000000..8e4b3d4c71 --- /dev/null +++ b/cafUserInterface/cafPdmUiComboBoxEditor.h @@ -0,0 +1,67 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#pragma once + +#include "cafPdmUiFieldEditorHandle.h" + +#include +#include +#include +#include +#include + + +namespace caf +{ + +//================================================================================================== +/// The default editor for several PdmFields. +//================================================================================================== + +class PdmUiComboBoxEditorAttribute : public PdmUiEditorAttribute +{ + +}; + + +class PdmUiComboBoxEditor : public PdmUiFieldEditorHandle +{ + Q_OBJECT + CAF_PDM_UI_FIELD_EDITOR_HEADER_INIT; + +public: + PdmUiComboBoxEditor() {} + virtual ~PdmUiComboBoxEditor() {} + +protected: + virtual QWidget* createEditorWidget(QWidget * parent); + virtual QWidget* createLabelWidget(QWidget * parent); + virtual void configureAndUpdateUi(const QString& uiConfigName); + +protected slots: + void slotCurrentIndexChanged(int index); + +private: + QPointer m_comboBox; + QPointer m_label; +}; + + +} // end namespace caf diff --git a/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp b/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp new file mode 100644 index 0000000000..38c4d3f98f --- /dev/null +++ b/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp @@ -0,0 +1,251 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#include "cafPdmUiDefaultObjectEditor.h" + +#include "cafPdmObject.h" +#include "cafPdmUiFieldEditorHandle.h" +#include "cafPdmUiOrdering.h" +#include "cafPdmField.h" +#include "cafPdmUiComboBoxEditor.h" +#include "cafPdmUiLineEditor.h" +#include "cafPdmUiCheckBoxEditor.h" + +#include +#include + +#include +#include + + + +namespace caf +{ + +// Register default field editor for selected types +CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiCheckBoxEditor, bool); + +CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiLineEditor, QString); +CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiLineEditor, int); +CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiLineEditor, double); +CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiLineEditor, float); + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QWidget* PdmUiDefaultObjectEditor::createWidget(QWidget* parent) +{ + m_mainWidget = new QWidget(parent); + m_layout = new QGridLayout(); + m_mainWidget->setLayout(m_layout); + return m_mainWidget; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiDefaultObjectEditor::configureAndUpdateUi(const QString& uiConfigName) +{ + PdmUiOrdering config; + if (pdmObject()) + { + pdmObject()->uiOrdering(uiConfigName, config); + } + + // Set all fieldViews to be unvisited + std::map::iterator it; + for (it = m_fieldViews.begin(); it != m_fieldViews.end(); ++it) + { + it->second->setField(NULL); + } + + // Set all group Boxes to be unvisited + m_newGroupBoxes.clear(); + + const std::vector& uiItems = config.uiItems(); + + recursiveSetupFieldsAndGroups(uiItems, m_mainWidget, m_layout, uiConfigName); + + // Remove all fieldViews not mentioned by the configuration from the layout + + std::vector< QString > fvhToRemoveFromMap; + for (it = m_fieldViews.begin(); it != m_fieldViews.end(); ++it) + { + if (it->second->field() == 0) + { + PdmUiFieldEditorHandle* fvh = it->second; + delete fvh; + fvhToRemoveFromMap.push_back(it->first); + } + } + + for (size_t i = 0; i < fvhToRemoveFromMap.size(); ++i) + { + m_fieldViews.erase(fvhToRemoveFromMap[i]); + } + + // Remove all unmentioned group boxes + + std::map >::iterator itOld; + std::map >::iterator itNew; + + for (itOld = m_groupBoxes.begin(); itOld != m_groupBoxes.end(); ++itOld ) + { + itNew = m_newGroupBoxes.find(itOld->first); + if (itNew == m_newGroupBoxes.end()) + { + // The old groupBox is not present anymore, get rid of it + if (!itOld->second.isNull()) delete itOld->second; + } + } + m_groupBoxes = m_newGroupBoxes; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiDefaultObjectEditor::recursiveSetupFieldsAndGroups(const std::vector& uiItems, QWidget* parent, QGridLayout* parentLayout, const QString& uiConfigName) +{ + int currentRowIndex = 0; + for (size_t i = 0; i < uiItems.size(); ++i) + { + if (uiItems[i]->isUiGroup()) + { + PdmUiGroup* group = static_cast(uiItems[i]); + const std::vector& groupChildren = group->uiItems(); + + QString groupBoxKey = uiItems[i]->uiName(); + QGroupBox* groupBox = NULL; + QGridLayout* groupBoxLayout = NULL; + + // Find or create groupBox + std::map >::iterator it; + it = m_groupBoxes.find(groupBoxKey); + + if (it == m_groupBoxes.end()) + { + groupBox = new QGroupBox( parent ); + groupBox->setTitle(uiItems[i]->uiName()); + groupBoxLayout = new QGridLayout(); + groupBox->setLayout(groupBoxLayout); + + m_newGroupBoxes[groupBoxKey] = groupBox; + } + else + { + groupBox = it->second; + assert(groupBox); + + groupBoxLayout = dynamic_cast(groupBox->layout()); + assert(groupBoxLayout); + + m_newGroupBoxes[groupBoxKey] = groupBox; + } + + /// Insert the group box at the correct position of the parent layout + + parentLayout->addWidget(groupBox, currentRowIndex, 0, 1, 2); + recursiveSetupFieldsAndGroups(groupChildren, groupBox, groupBoxLayout, uiConfigName); + currentRowIndex++; + } + else + { + PdmFieldHandle* field = dynamic_cast(uiItems[i]); + PdmUiFieldEditorHandle* fieldEditor = NULL; + + if (!field->isUiHidden(uiConfigName)) + { + + // Find or create FieldView + std::map::iterator it; + it = m_fieldViews.find(field->keyword()); + + if (it == m_fieldViews.end()) + { + if ( !uiItems[i]->uiEditorTypeName(uiConfigName).isEmpty() ) + { + fieldEditor = caf::Factory::instance()->create(field->uiEditorTypeName(uiConfigName)); + } + else + { + QString editorTypeName = qStringTypeName(*field); + + bool useOptionsOnly = true; + QList options = field->valueOptions( &useOptionsOnly); + if (!options.empty()) + { + editorTypeName = caf::PdmUiComboBoxEditor::uiEditorTypeName(); + } + + fieldEditor = caf::Factory::instance()->create(editorTypeName); + } + + if (fieldEditor) + { + m_fieldViews[field->keyword()] = fieldEditor; + fieldEditor->createWidgets(parent); + } + } + else + { + fieldEditor = it->second; + } + + if (fieldEditor) + { + fieldEditor->setField(field); + + // Place the widget(s) into the correct parent and layout + QWidget* fieldCombinedWidget = fieldEditor->combinedWidget(); + + if (fieldCombinedWidget) + { + fieldCombinedWidget->setParent(parent); + parentLayout->addWidget(fieldCombinedWidget, currentRowIndex, 0, 1, 2); + } + else + { + QWidget* fieldEditorWidget = fieldEditor->editorWidget(); + QWidget* fieldLabelWidget = fieldEditor->labelWidget(); + + if (fieldEditorWidget) + { + fieldEditorWidget->setParent(parent); // To make sure this widget has the current group box as parent. + parentLayout->addWidget(fieldEditorWidget, currentRowIndex, 1, Qt::AlignTop); + } + + if (fieldLabelWidget) + { + fieldLabelWidget->setParent(parent); + parentLayout->addWidget(fieldLabelWidget, currentRowIndex, 0, Qt::AlignTop); + } + } + + fieldEditor->updateUi(uiConfigName); + + currentRowIndex++; + } + } + } + } +} + + +} // end namespace caf diff --git a/cafUserInterface/cafPdmUiDefaultObjectEditor.h b/cafUserInterface/cafPdmUiDefaultObjectEditor.h new file mode 100644 index 0000000000..903745b465 --- /dev/null +++ b/cafUserInterface/cafPdmUiDefaultObjectEditor.h @@ -0,0 +1,62 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#pragma once +#include "cafPdmUiObjectEditorHandle.h" +#include +#include +#include +#include +#include + +class QGridLayout; + +namespace caf +{ +class PdmUiFieldEditorHandle; +class PdmUiItem; + +//================================================================================================== +/// The default editor for PdmObjects. Manages the field editors in a gridlayout vertically +//================================================================================================== + +class PdmUiDefaultObjectEditor : public PdmUiObjectEditorHandle +{ +public: + PdmUiDefaultObjectEditor() {} + ~PdmUiDefaultObjectEditor() {} + +protected: + virtual QWidget* createWidget(QWidget* parent); + virtual void configureAndUpdateUi(const QString& uiConfigName); + +private: + void recursiveSetupFieldsAndGroups(const std::vector& uiItems, QWidget* parent, QGridLayout* parentLayout, const QString& uiConfigName ); + + std::map m_fieldViews; + std::map > m_groupBoxes; + std::map > m_newGroupBoxes; ///< used temporarily to store the new(complete) set of group boxes + + QPointer m_mainWidget; + QGridLayout* m_layout; +}; + + + +} // end namespace caf diff --git a/cafUserInterface/cafPdmUiFilePathEditor.cpp b/cafUserInterface/cafPdmUiFilePathEditor.cpp new file mode 100644 index 0000000000..db1c75b7f1 --- /dev/null +++ b/cafUserInterface/cafPdmUiFilePathEditor.cpp @@ -0,0 +1,159 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#include "cafPdmUiFilePathEditor.h" + +#include "cafPdmUiDefaultObjectEditor.h" + +#include "cafPdmObject.h" +#include "cafPdmUiFieldEditorHandle.h" +#include "cafPdmUiOrdering.h" + +#include "cafPdmField.h" + +#include +#include +#include + +#include +#include "cafFactory.h" +#include "qboxlayout.h" +#include "qtoolbutton.h" +#include "qfiledialog.h" + + + +namespace caf +{ + +CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT(PdmUiFilePathEditor); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiFilePathEditor::configureAndUpdateUi(const QString& uiConfigName) +{ + assert(!m_lineEdit.isNull()); + assert(!m_label.isNull()); + + QIcon ic = field()->uiIcon(uiConfigName); + if (!ic.isNull()) + { + m_label->setPixmap(ic.pixmap(ic.actualSize(QSize(64, 64)))); + } + else + { + m_label->setText(field()->uiName(uiConfigName)); + } + + m_label->setVisible(!field()->isUiHidden(uiConfigName)); + m_label->setEnabled(!field()->isUiReadOnly(uiConfigName)); + + m_lineEdit->setEnabled(!field()->isUiReadOnly(uiConfigName)); + + field()->ownerObject()->editorAttribute(field(), uiConfigName, &m_attributes); + + m_lineEdit->setText(field()->uiValue().toString()); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QWidget* PdmUiFilePathEditor::createEditorWidget(QWidget * parent) +{ + QWidget* placeholder = new QWidget(parent); + + QHBoxLayout* layout = new QHBoxLayout(placeholder); + layout->setMargin(0); + layout->setSpacing(0); + + m_lineEdit = new QLineEdit(parent); + QToolButton* button = new QToolButton(parent); + button->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred)); + button->setText(QLatin1String("...")); + layout->addWidget(m_lineEdit); + layout->addWidget(button); + + connect(button, SIGNAL(clicked()), this, SLOT(fileSelectionClicked())); + connect(m_lineEdit, SIGNAL(editingFinished()), this, SLOT(slotEditingFinished())); + + return placeholder; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QWidget* PdmUiFilePathEditor::createLabelWidget(QWidget * parent) +{ + m_label = new QLabel(parent); + return m_label; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiFilePathEditor::slotEditingFinished() +{ + QVariant v; + QString textValue = m_lineEdit->text(); + v = textValue; + this->setValueToField(v); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiFilePathEditor::fileSelectionClicked() +{ + if (m_attributes.m_selectDirectory) + { + QString directoryPath = QFileDialog::getExistingDirectory(m_lineEdit, + tr("Get existing directory"), + m_lineEdit->text(), + QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + + if (!directoryPath.isEmpty()) + { + m_lineEdit->setText(directoryPath); + slotEditingFinished(); + } + } + else + { + QString filePath; + if (m_attributes.m_selectSaveFileName) + { + filePath = QFileDialog::getSaveFileName(m_lineEdit, tr("Save File"), m_lineEdit->text(), m_attributes.m_fileSelectionFilter); + } + else + { + filePath = QFileDialog::getOpenFileName(m_lineEdit, tr("Choose a file"), m_lineEdit->text(), m_attributes.m_fileSelectionFilter); + } + + if (!filePath.isEmpty()) + { + m_lineEdit->setText(filePath); + slotEditingFinished(); + } + } +} + + +} // end namespace caf diff --git a/cafUserInterface/cafPdmUiFilePathEditor.h b/cafUserInterface/cafPdmUiFilePathEditor.h new file mode 100644 index 0000000000..4f83e9d84c --- /dev/null +++ b/cafUserInterface/cafPdmUiFilePathEditor.h @@ -0,0 +1,79 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#pragma once +#include "cafPdmUiFieldEditorHandle.h" +#include +#include +#include +#include +#include + +class QGridLayout; + +namespace caf +{ + +//================================================================================================== +/// +//================================================================================================== + +class PdmUiFilePathEditorAttribute : public PdmUiEditorAttribute +{ +public: + PdmUiFilePathEditorAttribute() + { + m_selectSaveFileName = false; + m_selectDirectory = false; + m_fileSelectionFilter = "All files (*.* *)"; + } +public: + bool m_selectSaveFileName; + bool m_selectDirectory; + QString m_fileSelectionFilter; +}; + + +class PdmUiFilePathEditor : public PdmUiFieldEditorHandle +{ + Q_OBJECT + CAF_PDM_UI_FIELD_EDITOR_HEADER_INIT; + +public: + PdmUiFilePathEditor() {} + virtual ~PdmUiFilePathEditor() {} + +protected: + virtual QWidget* createEditorWidget(QWidget * parent); + virtual QWidget* createLabelWidget(QWidget * parent); + virtual void configureAndUpdateUi(const QString& uiConfigName); + +protected slots: + void slotEditingFinished(); + void fileSelectionClicked(); + +private: + QPointer m_lineEdit; + QPointer m_label; + + PdmUiFilePathEditorAttribute m_attributes; +}; + + +} // end namespace caf diff --git a/cafUserInterface/cafPdmUiLineEditor.cpp b/cafUserInterface/cafPdmUiLineEditor.cpp new file mode 100644 index 0000000000..78c23ee291 --- /dev/null +++ b/cafUserInterface/cafPdmUiLineEditor.cpp @@ -0,0 +1,121 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#include "cafPdmUiLineEditor.h" + +#include "cafPdmUiDefaultObjectEditor.h" + +#include "cafPdmObject.h" +#include "cafPdmUiFieldEditorHandle.h" +#include "cafPdmUiOrdering.h" + +#include "cafPdmField.h" + +#include +#include +#include + +#include +#include "cafFactory.h" + + + +namespace caf +{ + +CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT(PdmUiLineEditor); + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiLineEditor::configureAndUpdateUi(const QString& uiConfigName) +{ + assert(!m_lineEdit.isNull()); + assert(!m_label.isNull()); + + QIcon ic = field()->uiIcon(uiConfigName); + if (!ic.isNull()) + { + m_label->setPixmap(ic.pixmap(ic.actualSize(QSize(64, 64)))); + } + else + { + m_label->setText(field()->uiName(uiConfigName)); + } + + m_label->setVisible(!field()->isUiHidden(uiConfigName)); + m_label->setEnabled(!field()->isUiReadOnly(uiConfigName)); + + m_lineEdit->setEnabled(!field()->isUiReadOnly(uiConfigName)); + + PdmUiLineEditorAttribute leab; + field()->ownerObject()->editorAttribute(field(), uiConfigName, &leab); + if (leab.useRangeValidator) + { + m_lineEdit->setValidator(new QIntValidator(leab.minValue, leab.maxValue, this)); + } + + bool fromMenuOnly = false; + QList enumNames = field()->valueOptions(&fromMenuOnly); + if (!enumNames.isEmpty() && fromMenuOnly == true) + { + QStringList uiTexts = PdmOptionItemInfo::extractUiTexts(enumNames); + int enumValue = field()->uiValue().toInt(); + m_lineEdit->setText(uiTexts.at(enumValue)); + } + else + { + m_lineEdit->setText(field()->uiValue().toString()); + } +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QWidget* PdmUiLineEditor::createEditorWidget(QWidget * parent) +{ + m_lineEdit = new QLineEdit(parent); + connect(m_lineEdit, SIGNAL(editingFinished()), this, SLOT(slotEditingFinished())); + return m_lineEdit; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QWidget* PdmUiLineEditor::createLabelWidget(QWidget * parent) +{ + m_label = new QLabel(parent); + return m_label; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiLineEditor::slotEditingFinished() +{ + QVariant v; + QString textValue = m_lineEdit->text(); + v = textValue; + this->setValueToField(v); +} + + +} // end namespace caf diff --git a/cafUserInterface/cafPdmUiLineEditor.h b/cafUserInterface/cafPdmUiLineEditor.h new file mode 100644 index 0000000000..d6dbed42ee --- /dev/null +++ b/cafUserInterface/cafPdmUiLineEditor.h @@ -0,0 +1,78 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#pragma once +#include "cafPdmUiFieldEditorHandle.h" +#include +#include +#include +#include +#include + +class QGridLayout; + +namespace caf +{ + +//================================================================================================== +/// The default editor for several PdmFields. +//================================================================================================== + +class PdmUiLineEditorAttribute : public PdmUiEditorAttribute +{ +public: + PdmUiLineEditorAttribute() + { + useRangeValidator = false; + minValue = 0; + maxValue = 0; + } + +public: + bool useRangeValidator; + int minValue; + int maxValue; +}; + + +class PdmUiLineEditor : public PdmUiFieldEditorHandle +{ + Q_OBJECT + CAF_PDM_UI_FIELD_EDITOR_HEADER_INIT; + +public: + PdmUiLineEditor() {} + virtual ~PdmUiLineEditor() {} + +protected: + virtual QWidget* createEditorWidget(QWidget * parent); + virtual QWidget* createLabelWidget(QWidget * parent); + virtual void configureAndUpdateUi(const QString& uiConfigName); + +protected slots: + void slotEditingFinished(); + +private: + QPointer m_lineEdit; + QPointer m_label; + +}; + + +} // end namespace caf diff --git a/cafUserInterface/cafPdmUiListEditor.cpp b/cafUserInterface/cafPdmUiListEditor.cpp new file mode 100644 index 0000000000..b3fc5b1409 --- /dev/null +++ b/cafUserInterface/cafPdmUiListEditor.cpp @@ -0,0 +1,173 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#include "cafPdmUiListEditor.h" + +#include "cafPdmUiDefaultObjectEditor.h" +#include "cafPdmObject.h" +#include "cafPdmUiFieldEditorHandle.h" +#include "cafPdmField.h" + +#include "cafFactory.h" + +#include +#include +#include +#include +#include +#include +#include + + +#include + +//================================================================================================== +/// Helper class used to override flags to disable editable items +//================================================================================================== +class MyStringListModel : public QStringListModel +{ +public: + MyStringListModel(QObject *parent = 0) : QStringListModel(parent) { } + + virtual Qt::ItemFlags flags (const QModelIndex& index) const + { + return Qt::ItemIsSelectable | Qt::ItemIsEnabled; + } +}; + + + +namespace caf +{ + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT(PdmUiListEditor); + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +PdmUiListEditor::PdmUiListEditor() +{ +} + + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +PdmUiListEditor::~PdmUiListEditor() +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiListEditor::configureAndUpdateUi(const QString& uiConfigName) +{ + assert(!m_listView.isNull()); + assert(!m_label.isNull()); + assert(m_listView->selectionModel()); + + QIcon ic = field()->uiIcon(uiConfigName); + if (!ic.isNull()) + { + m_label->setPixmap(ic.pixmap(ic.actualSize(QSize(64, 64)))); + } + else + { + m_label->setText(field()->uiName(uiConfigName)); + } + + m_label->setVisible(!field()->isUiHidden(uiConfigName)); + m_label->setEnabled(!field()->isUiReadOnly(uiConfigName)); + + m_listView->setEnabled(!field()->isUiReadOnly(uiConfigName)); + + PdmUiListEditorAttribute attributes; + field()->ownerObject()->editorAttribute(field(), uiConfigName, &attributes); + + bool fromMenuOnly = false; + QList enumNames = field()->valueOptions(&fromMenuOnly); + if (!enumNames.isEmpty() && fromMenuOnly == true) + { + QStringList texts = PdmOptionItemInfo::extractUiTexts(enumNames); + m_model->setStringList(texts); + + int col = 0; + int row = field()->uiValue().toInt(); + QModelIndex mi = m_model->index(row, col); + + m_listView->selectionModel()->blockSignals(true); + + m_listView->selectionModel()->select(mi, QItemSelectionModel::SelectCurrent); + m_listView->selectionModel()->setCurrentIndex(mi, QItemSelectionModel::SelectCurrent); + + m_listView->selectionModel()->blockSignals(false); + } +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QWidget* PdmUiListEditor::createEditorWidget(QWidget * parent) +{ + m_listView = new QListView(parent); + + m_model = new MyStringListModel(m_listView); + m_listView->setModel(m_model); + + connect(m_listView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection& )), this, SLOT(slotSelectionChanged(const QItemSelection&, const QItemSelection& ))); + + return m_listView; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QWidget* PdmUiListEditor::createLabelWidget(QWidget * parent) +{ + m_label = new QLabel(parent); + return m_label; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiListEditor::slotSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected) +{ + if (selected.indexes().size() == 1) + { + QModelIndex mi = selected.indexes()[0]; + int col = mi.column(); + int row = mi.row(); + + QVariant v; + v = row; + QVariant uintValue(v.toUInt()); + + this->setValueToField(uintValue); + } +} + + +} // end namespace caf diff --git a/cafUserInterface/cafPdmUiListEditor.h b/cafUserInterface/cafPdmUiListEditor.h new file mode 100644 index 0000000000..be77b9495c --- /dev/null +++ b/cafUserInterface/cafPdmUiListEditor.h @@ -0,0 +1,68 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#pragma once + +#include "cafPdmUiFieldEditorHandle.h" + +class QGridLayout; +class QStringListModel; +class QItemSelection; +class QListView; +class QLabel; + +namespace caf +{ + +//================================================================================================== +/// +//================================================================================================== +class PdmUiListEditorAttribute : public PdmUiEditorAttribute +{ +}; + + +//================================================================================================== +/// +//================================================================================================== +class PdmUiListEditor : public PdmUiFieldEditorHandle +{ + Q_OBJECT + CAF_PDM_UI_FIELD_EDITOR_HEADER_INIT; + +public: + PdmUiListEditor(); + virtual ~PdmUiListEditor(); + +protected: + virtual QWidget* createEditorWidget(QWidget * parent); + virtual QWidget* createLabelWidget(QWidget * parent); + virtual void configureAndUpdateUi(const QString& uiConfigName); + +protected slots: + void slotSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected ); + +private: + QPointer m_listView; + QPointer m_label; + QPointer m_model; +}; + + +} // end namespace caf diff --git a/cafUserInterface/cafPdmUiPropertyView.cpp b/cafUserInterface/cafPdmUiPropertyView.cpp new file mode 100644 index 0000000000..47513e4d95 --- /dev/null +++ b/cafUserInterface/cafPdmUiPropertyView.cpp @@ -0,0 +1,131 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#include "cafPdmUiPropertyView.h" + +#include "cafPdmObject.h" +#include "cafPdmUiDefaultObjectEditor.h" + +#include + + +namespace caf +{ + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +PdmUiPropertyView::PdmUiPropertyView(QWidget* parent, Qt::WindowFlags f) + : QWidget (parent, f) +{ + m_layout = new QVBoxLayout(this); + m_layout->insertStretch(1, 1); + m_layout->setMargin(0); + m_layout->setSpacing(0); + + setLayout(m_layout); + + m_currentObjectView = NULL; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +PdmUiPropertyView::~PdmUiPropertyView() +{ + if (m_currentObjectView) delete m_currentObjectView; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiPropertyView::setUiConfigurationName(QString uiConfigName) +{ + // Reset everything, and possibly create widgets etc afresh + if (m_uiConfigName != uiConfigName) + { + m_uiConfigName = uiConfigName; + + if (m_currentObjectView) + { + PdmObject* object = m_currentObjectView->pdmObject(); + delete m_currentObjectView; + m_currentObjectView = NULL; + this->showProperties(object); + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiPropertyView::showProperties(caf::PdmObject* object) +{ + // Find specialized object view handle + + // If the current ObjectView has the same type as the one to view, reuse, with Widget etc. + + bool rebuildWidget = false; + + if (!m_currentObjectView) rebuildWidget = true; + + if (m_currentObjectView && m_currentObjectView->pdmObject()) + { + if (object) + { + if (m_currentObjectView->pdmObject()->uiEditorTypeName(m_uiConfigName) != object->uiEditorTypeName(m_uiConfigName)) + { + rebuildWidget = true; + } + } + } + + if (rebuildWidget) + { + // Remove Widget from layout + if (m_currentObjectView) + { + layout()->removeWidget(m_currentObjectView->widget()); + delete m_currentObjectView; + m_currentObjectView = NULL; + } + + //m_currentObjectView = PdmObjViewFactory::instance()->create(object->editorType(m_uiConfigName)); + if (!m_currentObjectView) + { + m_currentObjectView = new PdmUiDefaultObjectEditor(); + } + + // Create widget to handle this + QWidget * page = NULL; + page = m_currentObjectView->getOrCreateWidget(this); + + assert(page); + + this->m_layout->insertWidget(0, page); + } + + m_currentObjectView->setPdmObject(object); + m_currentObjectView->updateUi(m_uiConfigName); +} + + +} //End of namespace caf + diff --git a/cafUserInterface/cafPdmUiPropertyView.h b/cafUserInterface/cafPdmUiPropertyView.h new file mode 100644 index 0000000000..8f2dc4a06d --- /dev/null +++ b/cafUserInterface/cafPdmUiPropertyView.h @@ -0,0 +1,57 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#pragma once +#include +#include + +class QVBoxLayout; + +namespace caf +{ + +class PdmObject; +class PdmUiObjectEditorHandle; + +//================================================================================================== +/// +//================================================================================================== + +class PdmUiPropertyView : public QWidget +{ + Q_OBJECT +public: + PdmUiPropertyView(QWidget* parent = 0, Qt::WindowFlags f = 0); + ~PdmUiPropertyView(); + + void setUiConfigurationName(QString uiConfigName); + +public slots: + void showProperties(caf::PdmObject* object); + +private: + PdmUiObjectEditorHandle* m_currentObjectView; + QString m_uiConfigName; + QVBoxLayout* m_layout; +}; + + + +} // End of namespace caf + diff --git a/cafUserInterface/cafPdmUiSliderEditor.cpp b/cafUserInterface/cafPdmUiSliderEditor.cpp new file mode 100644 index 0000000000..decf836b65 --- /dev/null +++ b/cafUserInterface/cafPdmUiSliderEditor.cpp @@ -0,0 +1,125 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#include "cafPdmUiSliderEditor.h" + +#include "cafPdmUiDefaultObjectEditor.h" +#include "cafPdmObject.h" +#include "cafPdmUiFieldEditorHandle.h" +#include "cafPdmField.h" + +#include "cafFactory.h" + +#include +#include +#include +#include + +#include + + +namespace caf +{ + +CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT(PdmUiSliderEditor); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiSliderEditor::configureAndUpdateUi(const QString& uiConfigName) +{ + assert(!m_lineEdit.isNull()); + + m_groupBox->setTitle(field()->uiName(uiConfigName)); + + m_lineEdit->setEnabled(!field()->isUiReadOnly(uiConfigName)); + m_slider->setEnabled(!field()->isUiReadOnly(uiConfigName)); + + field()->ownerObject()->editorAttribute(field(), uiConfigName, &m_attributes); + + m_lineEdit->setText(field()->uiValue().toString()); + updateSliderPosition(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QWidget* PdmUiSliderEditor::createEditorWidget(QWidget * parent) +{ + m_groupBox = new QGroupBox(parent); + + QVBoxLayout* layout = new QVBoxLayout(parent); + m_groupBox->setLayout(layout); + + m_lineEdit = new QLineEdit(m_groupBox); + m_lineEdit->setValidator(new QIntValidator(m_attributes.m_minimum, m_attributes.m_maximum, m_groupBox)); + connect(m_lineEdit, SIGNAL(editingFinished()), this, SLOT(slotEditingFinished())); + + m_slider = new QSlider(Qt::Horizontal, m_groupBox); + m_slider->setRange(m_attributes.m_minimum, m_attributes.m_maximum); + + layout->addWidget(m_lineEdit); + layout->addWidget(m_slider); + + + connect(m_slider, SIGNAL(valueChanged(int)), this, SLOT(slotSliderValueChanged(int))); + + return m_groupBox; +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiSliderEditor::slotEditingFinished() +{ + updateSliderPosition(); + + QString textValue = m_lineEdit->text(); + QVariant v; + v = textValue; + this->setValueToField(v); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiSliderEditor::slotSliderValueChanged(int position) +{ + m_lineEdit->setText(QString::number(position)); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiSliderEditor::updateSliderPosition() +{ + QString textValue = m_lineEdit->text(); + + bool convertOk = false; + int newSliderValue = textValue.toInt(&convertOk); + if (convertOk) + { + newSliderValue = qBound(m_attributes.m_minimum, newSliderValue, m_attributes.m_maximum); + m_slider->setValue(newSliderValue); + } +} + + +} // end namespace caf diff --git a/cafUserInterface/cafPdmUiSliderEditor.h b/cafUserInterface/cafPdmUiSliderEditor.h new file mode 100644 index 0000000000..b3e6259142 --- /dev/null +++ b/cafUserInterface/cafPdmUiSliderEditor.h @@ -0,0 +1,80 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#pragma once +#include "cafPdmUiFieldEditorHandle.h" +#include +#include +#include +#include +#include +#include + + +namespace caf +{ + +//================================================================================================== +/// +//================================================================================================== + +class PdmUiSliderEditorAttribute : public PdmUiEditorAttribute +{ +public: + PdmUiSliderEditorAttribute() + { + m_minimum = 0; + m_maximum = 10; + } +public: + int m_minimum; + int m_maximum; +}; + + +class PdmUiSliderEditor : public PdmUiFieldEditorHandle +{ + Q_OBJECT + CAF_PDM_UI_FIELD_EDITOR_HEADER_INIT; + +public: + PdmUiSliderEditor() {} + virtual ~PdmUiSliderEditor() {} + +protected: + virtual void configureAndUpdateUi(const QString& uiConfigName); + virtual QWidget* createEditorWidget(QWidget * parent); + +protected slots: + void slotEditingFinished(); + void slotSliderValueChanged(int position); + +private: + void updateSliderPosition(); + +private: + QPointer m_groupBox; + QPointer m_lineEdit; + QPointer m_slider; + + PdmUiSliderEditorAttribute m_attributes; +}; + + +} // end namespace caf diff --git a/cafUserInterface/cafProgressInfo.cpp b/cafUserInterface/cafProgressInfo.cpp new file mode 100644 index 0000000000..ed1f424d26 --- /dev/null +++ b/cafUserInterface/cafProgressInfo.cpp @@ -0,0 +1,308 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#include "cafProgressInfo.h" +#include +#include +#include +#include +#include + +namespace caf { + +//================================================================================================== +/// +/// \class caf::ProgressInfo +/// +/// +/// +//================================================================================================== + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +ProgressInfo::ProgressInfo(int maxProgressValue, const QString& title) +{ + ProgressInfoStatic::start(maxProgressValue, title); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +ProgressInfo::~ProgressInfo() +{ + ProgressInfoStatic::finished(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void ProgressInfo::setProgressDescription(const QString& description) +{ + ProgressInfoStatic::setProgressDescription(description); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void ProgressInfo::setProgress(int progressValue) +{ + ProgressInfoStatic::setProgress(progressValue); +} + + + + + + + + +//================================================================================================== +/// +/// Internal file-scope private functions to implement the progress dialog +/// +/// +/// +//================================================================================================== + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +static QProgressDialog* progressDialog() +{ + static QPointer progDialog; + if (progDialog.isNull()) + { + progDialog = new QProgressDialog(); + + progDialog->hide(); + } + return progDialog; +} + +//-------------------------------------------------------------------------------------------------- +/// A static vector containing the maximum values for the progress on each sublevel +//-------------------------------------------------------------------------------------------------- +static std::vector& maxProgressStack() +{ + static std::vector m_maxProgressStack; + + return m_maxProgressStack; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +static std::vector& titleStack() +{ + static std::vector m_titleStack; + + return m_titleStack; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +static std::vector& descriptionStack() +{ + static std::vector m_descriptionStack; + + return m_descriptionStack; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +static std::vector& progressStack() +{ + static std::vector m_progressStack; + + return m_progressStack; +} + +//-------------------------------------------------------------------------------------------------- +/// Calculate the total number of progress values we would need if we only look at the levels from +/// \a levelDepth and below (increasing subdivision) +//-------------------------------------------------------------------------------------------------- +static int subLevelsMaxProgressValue(size_t levelDepth) +{ + int levCount = 1; + for (; levelDepth < maxProgressStack().size(); ++levelDepth) + { + levCount *= maxProgressStack()[levelDepth]; + } + return levCount; +} + +//-------------------------------------------------------------------------------------------------- +/// Calculate the total progress value based on the current level subdivision and progress +//-------------------------------------------------------------------------------------------------- +static int currentTotalProgress() +{ + int progress = 0; + for (size_t i = 0; i < progressStack().size(); ++i) + { + progress = progress + progressStack()[i]* subLevelsMaxProgressValue(i+1); + } + return progress; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +static int currentTotalMaxProgressValue() +{ + return subLevelsMaxProgressValue(0); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +static QString currentComposedLabel() +{ + QString labelText; + + for (size_t i = 0; i < titleStack().size(); ++i) + { + if (!titleStack()[i].isEmpty()) labelText += titleStack()[i]; + if (!titleStack()[i].isEmpty() && !descriptionStack()[i].isEmpty()) labelText +=": "; + if (!descriptionStack()[i].isEmpty()) labelText += descriptionStack()[i] ; + if (!(titleStack()[i].isEmpty() && descriptionStack()[i].isEmpty())) labelText += "\n"; + } + return labelText; + +} + +static bool isWrongThread() +{ + return !(progressDialog()->thread() == QThread::currentThread()); +} +//================================================================================================== +/// +/// \class caf::ProgressInfoStatic +/// +/// +/// +//================================================================================================== + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void ProgressInfoStatic::start(int maxProgressValue, const QString& title) +{ + if (isWrongThread()) return; + + if (!maxProgressStack().size()) + { + progressDialog()->setWindowModality(Qt::WindowModal); + progressDialog()->setMinimum(0); + progressDialog()->setWindowTitle(title); + progressDialog()->setCancelButton(NULL); + progressDialog()->show(); + } + + maxProgressStack().push_back(maxProgressValue); + progressStack().push_back(0); + titleStack().push_back(title); + descriptionStack().push_back(""); + + progressDialog()->setMaximum(currentTotalMaxProgressValue()); + progressDialog()->setValue(currentTotalProgress()); + progressDialog()->setLabelText(currentComposedLabel()); + + QCoreApplication::processEvents(); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void ProgressInfoStatic::setProgressDescription(const QString& description) +{ + if (isWrongThread()) return; + + descriptionStack().back() = description; + + progressDialog()->setLabelText(currentComposedLabel()); + QCoreApplication::processEvents(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void ProgressInfoStatic::setProgress(int progressValue) +{ + if (isWrongThread()) return; + + // Guard against the max value set for theis level + if (progressValue < 0 ) progressValue = 0; + if (progressValue > maxProgressStack().back() ) progressValue = maxProgressStack().back(); + + progressStack().back() = progressValue; + + assert(currentTotalProgress() <= progressDialog()->maximum()); + int totProg = currentTotalProgress(); + + progressDialog()->setMaximum(currentTotalMaxProgressValue()); + progressDialog()->setValue(currentTotalProgress()); + QCoreApplication::processEvents(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void ProgressInfoStatic::finished() +{ + if (isWrongThread()) return; + + assert(maxProgressStack().size() && progressStack().size() && titleStack().size() && descriptionStack().size()); + + // Set progress to max value, and leave it there until somebody touches the progress again + + progressStack().back() = maxProgressStack().back(); + progressDialog()->setValue(currentTotalProgress()); + + // Pop all the stacks + maxProgressStack().pop_back(); + progressStack().pop_back(); + titleStack().pop_back(); + descriptionStack().pop_back(); + + // Update the text to reflect the "previous level" + progressDialog()->setLabelText(currentComposedLabel()); + + // If we are finishing the last level, clean up + if (!maxProgressStack().size()) + { + if (progressDialog() != NULL) + { + progressDialog()->hide(); + delete progressDialog(); + } + } + + // Make sure the Gui is repainted + QCoreApplication::processEvents(); +} + + + + +} // namespace caf diff --git a/cafUserInterface/cafProgressInfo.h b/cafUserInterface/cafProgressInfo.h new file mode 100644 index 0000000000..f27cb53eec --- /dev/null +++ b/cafUserInterface/cafProgressInfo.h @@ -0,0 +1,48 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +//################################################################################################## + +#pragma once + +class QString; + +namespace caf { + +class ProgressInfo +{ +public: + ProgressInfo(int maxProgressValue, const QString& title); + + ~ProgressInfo(); + void setProgressDescription(const QString& description); + void setProgress(int progressValue); +}; + + +class ProgressInfoStatic +{ +public: + static void start(int maxProgressValue, const QString& title); + + static void setProgressDescription(const QString& description); + static void setProgress(int progressValue); + + static void finished(); +}; + +} diff --git a/cafUserInterface/cafUiPropertyCreatorPdm.cpp b/cafUserInterface/cafUiPropertyCreatorPdm.cpp index 23c95068a8..05fbed4792 100644 --- a/cafUserInterface/cafUiPropertyCreatorPdm.cpp +++ b/cafUserInterface/cafUiPropertyCreatorPdm.cpp @@ -109,7 +109,14 @@ void UiPropertyCreatorPdm::createAndShowPropertiesForIndex(const QModelIndex& in caf::PdmUiTreeItem* treeItem = caf::UiTreeModelPdm::getTreeItemFromIndex(index); assert(treeItem); - createAndShowPropertiesForObject(treeItem->dataObject()); + caf::PdmObject* pdmObj = treeItem->dataObject(); + + if (m_propertyBrowser) + { + createAndShowPropertiesForObject(pdmObj); + } + + emit selectedObjectChanged(pdmObj); } } @@ -191,7 +198,7 @@ void UiPropertyCreatorPdm::createAndShowPropertiesForObject(caf::PdmObject* obje qtProperty->setWhatsThis(field->uiWhatsThis()); m_properties[qtProperty] = field; - if (!field->isHidden()) + if (!field->isUiHidden()) { m_propertyBrowser->addProperty(qtProperty); } @@ -215,9 +222,11 @@ void UiPropertyCreatorPdm::createAndShowPropertiesForObject(caf::PdmObject* obje //-------------------------------------------------------------------------------------------------- void UiPropertyCreatorPdm::clearWidgetsAndProperties() { - assert(m_propertyBrowser); + if (m_propertyBrowser) + { + m_propertyBrowser->clear(); + } - m_propertyBrowser->clear(); m_properties.clear(); } @@ -230,7 +239,7 @@ void UiPropertyCreatorPdm::setAllPropertyValuesFromDataSource() for (it = m_properties.begin(); it != m_properties.end(); it++) { #if 1 - if (it->second->isHidden()) + if (it->second->isUiHidden()) { QtProperty* prop = it->first; #if 0 @@ -361,4 +370,5 @@ void UiPropertyCreatorPdm::uiFields(const caf::PdmObject* object, std::vectorfields(fields); } + } // end namespace caf diff --git a/cafUserInterface/cafUiPropertyCreatorPdm.h b/cafUserInterface/cafUiPropertyCreatorPdm.h index d46de32ae4..421dbb3333 100644 --- a/cafUserInterface/cafUiPropertyCreatorPdm.h +++ b/cafUserInterface/cafUiPropertyCreatorPdm.h @@ -55,6 +55,9 @@ public: void createAndShowPropertiesForObject(caf::PdmObject* dataSource); +signals: + void selectedObjectChanged(caf::PdmObject* object); + private: void createAndShowPropertiesForIndex(const QModelIndex& index); diff --git a/cafUserInterface/cafUiTreeModelPdm.cpp b/cafUserInterface/cafUiTreeModelPdm.cpp index ebc1e0f496..a5b50632d0 100644 --- a/cafUserInterface/cafUiTreeModelPdm.cpp +++ b/cafUserInterface/cafUiTreeModelPdm.cpp @@ -157,6 +157,8 @@ QVariant UiTreeModelPdm::data(const QModelIndex &index, int role /*= Qt::Display PdmObject* obj = treeItem->dataObject(); + if (obj == NULL) return QVariant(); + // We try to find the context of the object first: The parent field // If found, use its data to describe the thing // Note: This code will only find first field pointing at the current object. Its valid for now, @@ -267,14 +269,27 @@ bool UiTreeModelPdm::setData(const QModelIndex &index, const QVariant &value, in } //-------------------------------------------------------------------------------------------------- -/// +/// Enable edit of this item if we have a editable user description field for a pdmObject +/// Disable edit for other items //-------------------------------------------------------------------------------------------------- Qt::ItemFlags UiTreeModelPdm::flags(const QModelIndex &index) const { if (!index.isValid()) return Qt::ItemIsEnabled; - return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; + PdmUiTreeItem* treeItem = getTreeItemFromIndex(index); + if (treeItem) + { + PdmObject* pdmObject = treeItem->dataObject(); + if (pdmObject && pdmObject->userDescriptionField() && !pdmObject->userDescriptionField()->isUiReadOnly()) + { + Qt::ItemFlags flagMask = QAbstractItemModel::flags(index) | Qt::ItemIsEditable; + return flagMask; + } + } + + Qt::ItemFlags flagMask = QAbstractItemModel::flags(index) & (~Qt::ItemIsEditable); + return flagMask; } //-------------------------------------------------------------------------------------------------- @@ -410,7 +425,7 @@ PdmUiTreeItem* UiTreeItemBuilderPdm::buildViewItems(PdmUiTreeItem* parentTreeIte for (it = fields.begin(); it != fields.end(); it++) { caf::PdmFieldHandle* field = *it; - if (field->isHidden()) continue; + if (field->isUiHidden()) continue; std::vector children; field->childObjects(&children); diff --git a/cafViewer/cafViewer.cpp b/cafViewer/cafViewer.cpp index 7efa7a4efb..64217ad40c 100644 --- a/cafViewer/cafViewer.cpp +++ b/cafViewer/cafViewer.cpp @@ -39,6 +39,7 @@ #include "cvfDebugTimer.h" #include "cvfqtPerformanceInfoHud.h" +#include "cvfqtUtils.h" #include "cafNavigationPolicy.h" #include "cafCadNavigation.h" @@ -46,6 +47,7 @@ #include #include +#include std::list caf::Viewer::sm_viewers; cvf::ref caf::Viewer::sm_openGLContextGroup; @@ -59,7 +61,8 @@ caf::Viewer::Viewer(const QGLFormat& format, QWidget* parent) m_minNearPlaneDistance(0.05), m_maxFarPlaneDistance(cvf::UNDEFINED_DOUBLE), m_releaseOGLResourcesEachFrame(false), - m_paintCounter(0) + m_paintCounter(0), + m_navigationPolicyEnabled(true) { m_layoutWidget = parentWidget(); @@ -269,7 +272,7 @@ void caf::Viewer::optimizeClippingPlanes() //-------------------------------------------------------------------------------------------------- bool caf::Viewer::event(QEvent* e) { - if (e && m_navigationPolicy.notNull()) + if (e && m_navigationPolicy.notNull() && m_navigationPolicyEnabled) { switch (e->type()) { @@ -610,3 +613,39 @@ cvf::Scene* caf::Viewer::frame(size_t frameIndex) return NULL; } +//-------------------------------------------------------------------------------------------------- +/// Helper function used to write out the name of all parts in a rendering sequence +//-------------------------------------------------------------------------------------------------- +void caf::Viewer::debugShowRenderingSequencePartNames() +{ + qDebug() << "\n\n"; + size_t globalPartCount = 0; + + cvf::uint rIdx = m_renderingSequence->renderingCount(); + for (rIdx = 0; rIdx < m_renderingSequence->renderingCount(); rIdx++) + { + cvf::Rendering* rendering = m_renderingSequence->rendering(rIdx); + if (rendering && rendering->scene()) + { + cvf::uint mIdx; + for (mIdx = 0; mIdx < rendering->scene()->modelCount(); mIdx++) + { + cvf::Model* model = rendering->scene()->model(mIdx); + if (model) + { + cvf::Collection parts; + model->allParts(&parts); + + size_t pIdx; + for (pIdx = 0; pIdx < parts.size(); pIdx++) + { + cvf::Part* part = parts.at(pIdx); + + qDebug() << QString("%1").arg(globalPartCount++) << cvfqt::Utils::toQString(part->name()); + } + } + } + } + } +} + diff --git a/cafViewer/cafViewer.h b/cafViewer/cafViewer.h index 405e949235..8c89023a13 100644 --- a/cafViewer/cafViewer.h +++ b/cafViewer/cafViewer.h @@ -88,6 +88,7 @@ public: // Set the navigation policy void setNavigationPolicy(caf::NavigationPolicy* navigationPolicy); + void enableNavigationPolicy(bool enable) { m_navigationPolicyEnabled = enable; } void setView( const cvf::Vec3d& alongDirection, const cvf::Vec3d& upDirection ); void zoomAll(); @@ -118,6 +119,7 @@ protected: virtual bool event( QEvent* e ); cvf::ref m_navigationPolicy; + bool m_navigationPolicyEnabled; // Overridable methods to setup the render system virtual void setupMainRendering(); @@ -137,6 +139,7 @@ protected: private: void releaseOGlResourcesForCurrentFrame(); + void debugShowRenderingSequencePartNames(); bool m_showPerfInfoHud; size_t m_paintCounter;