Support PDF-export from Python

This commit is contained in:
Gaute Lindkvist 2020-01-21 12:36:22 +01:00
parent 1133816471
commit e1c1981830
9 changed files with 59 additions and 20 deletions

View File

@ -35,6 +35,14 @@ CAF_PDM_SOURCE_INIT( RicfExportSnapshots, "exportSnapshots" );
namespace caf
{
template <>
void RicfExportSnapshots::PreferredOutputFormatEnum::setUp()
{
addItem( RicfExportSnapshots::PlotOutputFormat::PNG, "PNG", "PNG" );
addItem( RicfExportSnapshots::PlotOutputFormat::PDF, "PDF", "PDF" );
setDefault( RicfExportSnapshots::PlotOutputFormat::PNG );
}
template <>
void RicfExportSnapshots::SnapshotsTypeEnum::setUp()
{
@ -55,6 +63,7 @@ RicfExportSnapshots::RicfExportSnapshots()
RICF_InitField( &m_caseId, "caseId", -1, "Case Id", "", "", "" );
RICF_InitField( &m_viewId, "viewId", -1, "View Id", "", "", "" );
RICF_InitField( &m_exportFolder, "exportFolder", QString(), "Export Folder", "", "", "" );
RICF_InitFieldNoDefault( &m_plotOutputFormat, "plotOutputFormat", "Output Format", "", "", "" );
}
//--------------------------------------------------------------------------------------------------
@ -109,9 +118,12 @@ RicfCommandResponse RicfExportSnapshots::execute()
QApplication::processEvents();
}
QString fileSuffix = ".png";
if ( m_plotOutputFormat == PlotOutputFormat::PDF ) fileSuffix = ".pdf";
RicSnapshotAllPlotsToFileFeature::exportSnapshotOfPlotsIntoFolder( absolutePathToSnapshotDir,
m_prefix,
m_viewId() );
m_viewId(),
fileSuffix );
}
mainWnd->loadWinGeoAndDockToolBarLayout();

View File

@ -34,6 +34,14 @@ class RicfExportSnapshots : public RicfCommandObject
public:
// Values are exposed in gRPC .proto. Do not change without also changing .proto
enum class PlotOutputFormat
{
PNG,
PDF
};
typedef caf::AppEnum<PlotOutputFormat> PreferredOutputFormatEnum;
enum SnapshotsType
{
VIEWS,
@ -48,9 +56,10 @@ public:
RicfCommandResponse execute() override;
private:
caf::PdmField<SnapshotsTypeEnum> m_type;
caf::PdmField<QString> m_prefix;
caf::PdmField<int> m_caseId;
caf::PdmField<int> m_viewId;
caf::PdmField<QString> m_exportFolder;
caf::PdmField<SnapshotsTypeEnum> m_type;
caf::PdmField<QString> m_prefix;
caf::PdmField<int> m_caseId;
caf::PdmField<int> m_viewId;
caf::PdmField<QString> m_exportFolder;
caf::PdmField<PreferredOutputFormatEnum> m_plotOutputFormat;
};

View File

@ -68,7 +68,8 @@ void RicSnapshotAllPlotsToFileFeature::saveAllPlots()
//--------------------------------------------------------------------------------------------------
void RicSnapshotAllPlotsToFileFeature::exportSnapshotOfPlotsIntoFolder( const QString& snapshotFolderName,
const QString& prefix,
int viewId )
int viewId,
const QString& preferredFileSuffix /*=".png"*/ )
{
RiaApplication* app = RiaApplication::instance();
@ -98,7 +99,7 @@ void RicSnapshotAllPlotsToFileFeature::exportSnapshotOfPlotsIntoFolder( const QS
fileName.replace( " ", "_" );
QString absoluteFileName = caf::Utils::constructFullFileName( absSnapshotPath, fileName, ".png" );
QString absoluteFileName = caf::Utils::constructFullFileName( absSnapshotPath, fileName, preferredFileSuffix );
RicSnapshotViewToFileFeature::saveSnapshotAs( absoluteFileName, viewWindow );
}

View File

@ -33,8 +33,9 @@ public:
static void saveAllPlots();
static void exportSnapshotOfPlotsIntoFolder( const QString& snapshotFolderName,
const QString& prefix = "",
int viewId = -1 );
const QString& prefix = "",
int viewId = -1,
const QString& preferredFileSuffix = ".png" );
protected:
// Overrides

View File

@ -50,7 +50,12 @@ CAF_CMD_SOURCE_INIT( RicSnapshotViewToFileFeature, "RicSnapshotViewToFileFeature
//--------------------------------------------------------------------------------------------------
void RicSnapshotViewToFileFeature::saveSnapshotAs( const QString& fileName, RimViewWindow* viewWindow )
{
if ( viewWindow )
RimPlotWindow* plotWindow = dynamic_cast<RimPlotWindow*>( viewWindow );
if ( plotWindow && fileName.endsWith( ".pdf" ) )
{
savePlotPDFReportAs( fileName, plotWindow );
}
else if ( viewWindow )
{
QImage image = viewWindow->snapshotWindowContent();
saveSnapshotAs( fileName, image );

View File

@ -45,6 +45,12 @@ message ExportMultiCaseRequest
string gridListFile = 1;
}
enum PlotOutputFormat
{
PNG = 0;
PDF = 1;
}
enum SnapshotType
{
VIEWS = 0;
@ -54,11 +60,12 @@ enum SnapshotType
message ExportSnapshotsRequest
{
SnapshotType type = 1;
string prefix = 2;
int32 caseId = 3;
int32 viewId = 4;
string exportFolder = 5;
SnapshotType type = 1;
string prefix = 2;
int32 caseId = 3;
int32 viewId = 4;
string exportFolder = 5;
PlotOutputFormat plotOutputFormat = 6;
}
message ExportPropertyRequest

View File

@ -14,6 +14,7 @@ print("Exporting to: " + export_folder)
for plot in plots:
plot.export_snapshot(export_folder=export_folder)
plot.export_snapshot(export_folder=export_folder, output_format='PDF')
well_log_plot = rips.WellLogPlot.from_pdm_object(plot)
if well_log_plot is not None:
well_log_plot.export_data_as_las(export_folder=export_folder)

View File

@ -16,18 +16,20 @@ class Plot(PdmObject):
PdmObject.__init__(self, pdm_object.pb2_object(), pdm_object.channel(), pdm_object.project())
self.view_id = pdm_object.get_value("ViewId")
def export_snapshot(self, export_folder='', file_prefix='', ):
def export_snapshot(self, export_folder='', file_prefix='', output_format='PNG'):
""" Export snapshot for the current plot
Arguments:
export_folder(str): The path to export to. By default will use the global export folder
prefix (str): Exported file name prefix
output_format(str): Enum string. Can be 'PNG' or 'PDF'.
"""
return self._execute_command(
exportSnapshots=Cmd.ExportSnapshotsRequest(type='PLOTS',
prefix=file_prefix,
viewId=self.view_id,
exportFolder=export_folder))
exportFolder=export_folder,
plotOutputFormat=output_format))

View File

@ -224,16 +224,17 @@ class Project(PdmObject):
exportMultiCaseSnapshot=Cmd.ExportMultiCaseRequest(
gridListFile=grid_list_file))
def export_snapshots(self, snapshot_type='ALL', prefix=''):
def export_snapshots(self, snapshot_type='ALL', prefix='', plot_format='PNG'):
""" Export all snapshots of a given type
Arguments:
snapshot_type (str): Enum string ('ALL', 'VIEWS' or 'PLOTS')
prefix (str): Exported file name prefix
plot_format(str): Enum string, 'PNG' or 'PDF'
"""
return self._execute_command(
exportSnapshots=Cmd.ExportSnapshotsRequest(
type=snapshot_type, prefix=prefix, caseId=-1, viewId=-1))
type=snapshot_type, prefix=prefix, caseId=-1, viewId=-1, plotOutputFormat=plot_format))
def export_well_paths(self, well_paths=None, md_step_size=5.0):
""" Export a set of well paths