示例#1
0
void
ImageViewController::requestImageAndGridUpdate()
{
    // erase current grid
//    m_gridVG = Nullable < Carta::Lib::VectorGraphics::VGList > ();

    auto renderSize = m_renderService-> outputSize();
    m_wcsGridRenderer-> setOutputSize( renderSize );

    int leftMargin = 50;
    int rightMargin = 10;
    int bottomMargin = 50;
    int topMargin = 10;

    QRectF outputRect( leftMargin, topMargin,
                       renderSize.width() - leftMargin - rightMargin,
                       renderSize.height() - topMargin - bottomMargin );
    QRectF inputRect(
        m_renderService-> screen2img( outputRect.topLeft() ),
        m_renderService-> screen2img( outputRect.bottomRight() ) );

    m_wcsGridRenderer-> setImageRect( inputRect );
    m_wcsGridRenderer-> setOutputRect( outputRect );

//    m_igSync-> startAll();
    m_syncSvc-> startImage();
    m_syncSvc-> startGrid();
} // updateGridAfterPanZoom
//////////////////////////////////////////////////////////////////////////////
//
//	void ExportGraphicImage( RBitmapImage* pImage, RMBCString *pInitialDir ) 
//
//	export a graphic to file from a bitmap image
//
//////////////////////////////////////////////////////////////////////////////
void ExportGraphicImage( RBitmapImage* pImage, RMBCString *pInitialDir /*=NULL*/) 
{
	RImageLibrary rLibrary ;
	CArray<int, int> arrFileFormats ;

	//
	// Build the export file filter list...
	//
	CString strFilter, str ;

	for (int i = 0; i < kNumFormats - 1; i++)
	{
		if (rLibrary.IsFormatSupported( (EImageFormat) kImageExportFilters[i][0] ))
		{
			str.LoadString( kImageExportFilters[i][1] ) ;
			strFilter += str ;

			arrFileFormats.Add( kImageExportFilters[i][0] ) ;
		}
	}

	TpsAssert( kImageExportFilters[i][0] == kImageFormatXRX, "Invalid export format!" ) ;
	str.LoadString( kImageExportFilters[i][1] ) ;  
	strFilter += str ;
	strFilter += "|" ;

	arrFileFormats.Add( kImageExportFilters[i][0] ) ;

	//
	// Create and execute the dialog...
	//
	RExportGraphicDlg dlg( pImage, strFilter ) ;

	// Load in the dialog title string
	CString strTitle ;
	strTitle.LoadString( STRING_EXPORT_IMAGE_DIALOG_TITLE ) ;
	dlg.m_ofn.lpstrTitle = (LPCTSTR) strTitle ;
	if( pInitialDir )
	{
		dlg.m_ofn.lpstrInitialDir = (LPCTSTR)*pInitialDir;
	}

	if (IDOK == dlg.DoModal())
	{
		RMBCString   strPathName = dlg.GetPathName() ;
		EImageFormat eFormat = (EImageFormat) arrFileFormats[dlg.m_ofn.nFilterIndex - 1] ;

		try
		{
			if (kImageFormatXRX == eFormat)		// exporting as WMF
			{
				// get our output image size
				RRealSize rRealOutputSize( dlg.GetSize() );
				RRealSize screenDPI = ::GetScreenDPI();

				// create a vector image
				RVectorImage vectorImage;
 				vectorImage.SetSuggestedWidthInInches( ::PixelsToInches( rRealOutputSize.m_dx, (uLONG) screenDPI.m_dx ) );
				vectorImage.SetSuggestedHeightInInches( ::PixelsToInches( rRealOutputSize.m_dy, (uLONG) screenDPI.m_dy ) );

				// Create an offscreen drawing surface and set the picture
				ROffscreenDrawingSurface rODS;
				rODS.SetImage( &vectorImage );

		  		// Scale to the device DPI
				RRealSize rRealImageSize = pImage->GetSizeInLogicalUnits();
				R2dTransform transform ;
				RRealSize deviceDPI = rODS.GetDPI();

				transform.PreScale( (YFloatType) deviceDPI.m_dx / screenDPI.m_dy, 
									(YFloatType) deviceDPI.m_dy / screenDPI.m_dy );

				transform.PreScale( rRealOutputSize.m_dx / rRealImageSize.m_dx,
									rRealOutputSize.m_dy / rRealImageSize.m_dy ) ;

				// calculate the output rect
				RRealRect outputRect( rRealOutputSize ) ;
				::ScreenUnitsToLogicalUnits( outputRect );
				outputRect *= transform;

				// render to the offscreen
				pImage->Render( rODS, outputRect ) ;

				// clean up
				rODS.ReleaseImage();

				// export
				rLibrary.ExportImage( vectorImage, strPathName, kImageFormatXRX ) ;
				if (rLibrary.GetLastException() != kNoError)
				{
					throw rLibrary.GetLastException() ;
				}
			}
			else					// all other formats
			{
				_nFilterIndex = dlg.m_ofn.nFilterIndex ;
				
				EImageFormat eFormat = (EImageFormat) arrFileFormats[dlg.m_ofn.nFilterIndex - 1] ;
				rLibrary.ExportImage( *pImage, strPathName, eFormat );
				if (rLibrary.GetLastException() != kNoError)
				{
					throw rLibrary.GetLastException() ;
				}
	
			}
		}
		catch( YException e)
		{
			ReportException( e ) ;
		}
	}
}
//////////////////////////////////////////////////////////////////////////////
//
//	void ExportGraphicComponent( RComponentView* pComponentView, RMBCString *pInitialDir ) 
//
//	export a graphic to file from a component view
//
//////////////////////////////////////////////////////////////////////////////
void ExportGraphicComponent( RComponentView* pComponentView, RMBCString *pInitialDir /*=NULL*/) 
{
	RImageLibrary rLibrary ;
	CArray<int, int> arrFileFormats ;

	//
	// Build the export file filter list...
	//
	CString strFilter, str ;

	for (int i = 0; i < kNumFormats - 1; i++)
	{
		if (rLibrary.IsFormatSupported( (EImageFormat) kImageExportFilters[i][0] ))
		{
			str.LoadString( kImageExportFilters[i][1] ) ;
			strFilter += str ;

			arrFileFormats.Add( kImageExportFilters[i][0] ) ;
		}
	}

	TpsAssert( kImageExportFilters[i][0] == kImageFormatXRX, "Invalid export format!" ) ;
	str.LoadString( kImageExportFilters[i][1] ) ;  
	strFilter += str ;
	strFilter += "|" ;

	arrFileFormats.Add( kImageExportFilters[i][0] ) ;

	//
	// Create and execute the dialog...
	//
	RExportGraphicDlg dlg( pComponentView, strFilter ) ;

	// Load in the dialog title string
	CString strTitle ;
	strTitle.LoadString( STRING_EXPORT_IMAGE_DIALOG_TITLE ) ;
	dlg.m_ofn.lpstrTitle = (LPCTSTR) strTitle ;
	if( pInitialDir )
	{
		dlg.m_ofn.lpstrInitialDir = (LPCTSTR)*pInitialDir;
	}

	if (IDOK == dlg.DoModal())
	{
		RMBCString   strPathName = dlg.GetPathName() ;
		RIntSize     szImageSize = dlg.GetSize() ;

		_nFilterIndex = dlg.m_ofn.nFilterIndex ;
		EImageFormat eFormat = (EImageFormat) arrFileFormats[dlg.m_ofn.nFilterIndex - 1] ;
		RRealSize pictureSize  = pComponentView->GetReferenceSize() ;

		try
		{
			if (kImageFormatXRX == eFormat)
			{
				RRealSize outputSize( szImageSize.m_dx, szImageSize.m_dy ) ; //   = pictureSize ;
				RRealSize screenDPI    = ::GetScreenDPI() ;

				RVectorImage vectorImage ;
				vectorImage.SetSuggestedWidthInInches( ::PixelsToInches( outputSize.m_dx, (uLONG) screenDPI.m_dx ) ) ;
				vectorImage.SetSuggestedHeightInInches( ::PixelsToInches( outputSize.m_dy, (uLONG) screenDPI.m_dy ) ) ;

				// Create an offscreen drawing surface and set the picture
				ROffscreenDrawingSurface drawingSurface;
				drawingSurface.SetImage( &vectorImage );

				R2dTransform transform ;

				// Scale to the device DPI
				RRealSize deviceDPI = drawingSurface.GetDPI( );
				transform.PreScale( (YFloatType) deviceDPI.m_dx / screenDPI.m_dy, 
					(YFloatType) deviceDPI.m_dy / screenDPI.m_dy );

				transform.PreScale( 
					outputSize.m_dx / pictureSize.m_dx,
					outputSize.m_dy / pictureSize.m_dy ) ;

				// Render the component
				RRealRect outputRect( pictureSize ) ;
				pComponentView->Render( drawingSurface, transform, outputRect ) ;

				drawingSurface.ReleaseImage( );

				rLibrary.ExportImage( vectorImage, strPathName, kImageFormatXRX ) ;
				if (rLibrary.GetLastException() != kNoError)
				{
					throw rLibrary.GetLastException() ;
				}
			} // if (XRX)
			else
			{
				// Check for a image interface
				RImageInterface* pInterface = (RImageInterface *) 
					pComponentView->GetInterface( kImageInterfaceId ) ;

				if (pInterface)
				{
					pInterface->Export( strPathName, eFormat ) ;
					delete pInterface ;
				}
				else
				{
					// Initialize the new bitmap at a bit depth of 24
					RBitmapImage image ;
					image.Initialize( szImageSize.m_dx, szImageSize.m_dy, 24 ) ;

					ROffscreenDrawingSurface dsMem ; 
					dsMem.SetImage( &image ) ;

					R2dTransform transform ;
					transform.PreScale( 
						szImageSize.m_dx / pictureSize.m_dx,
						szImageSize.m_dy / pictureSize.m_dy ) ;

					// Render the component
					dsMem.SetFillColor( RSolidColor( kWhite ) ) ;
					dsMem.FillRectangle( RRealRect( pictureSize ), transform ) ;
					pComponentView->Render( dsMem, transform, RIntRect( 
						RIntSize( pictureSize.m_dx, pictureSize.m_dy ) ) ) ;

					dsMem.ReleaseImage() ;
					
					rLibrary.ExportImage( image, strPathName, eFormat ) ;
				}

				if (rLibrary.GetLastException() != kNoError)
				{
					throw rLibrary.GetLastException() ;
				}
			
			} // else

		} // try

		catch( YException e)
		{
			ReportException( e ) ;
		}

	} // if (IDOK)
}