2013-08-09 06:57:18 +02:00
# include "lc_global.h"
# include <stdio.h>
# include "lc_application.h"
# include "lc_library.h"
# include "lc_profile.h"
# include "project.h"
2013-08-16 03:25:51 +02:00
# include "lc_mainwindow.h"
2013-08-09 06:57:18 +02:00
# include "lc_shortcuts.h"
2017-06-20 05:03:49 +02:00
# include "view.h"
2013-08-09 06:57:18 +02:00
lcApplication * g_App ;
2014-02-10 01:13:41 +01:00
void lcPreferences : : LoadDefaults ( )
{
2014-10-05 07:21:51 +02:00
mFixedAxes = lcGetProfileInt ( LC_PROFILE_FIXED_AXES ) ;
2014-02-10 01:13:41 +01:00
mMouseSensitivity = lcGetProfileInt ( LC_PROFILE_MOUSE_SENSITIVITY ) ;
2017-08-25 21:57:14 +02:00
mShadingMode = ( lcShadingMode ) lcGetProfileInt ( LC_PROFILE_SHADING_MODE ) ;
2014-02-10 01:13:41 +01:00
mDrawAxes = lcGetProfileInt ( LC_PROFILE_DRAW_AXES ) ;
mDrawEdgeLines = lcGetProfileInt ( LC_PROFILE_DRAW_EDGE_LINES ) ;
mLineWidth = lcGetProfileFloat ( LC_PROFILE_LINE_WIDTH ) ;
mDrawGridStuds = lcGetProfileInt ( LC_PROFILE_GRID_STUDS ) ;
mGridStudColor = lcGetProfileInt ( LC_PROFILE_GRID_STUD_COLOR ) ;
mDrawGridLines = lcGetProfileInt ( LC_PROFILE_GRID_LINES ) ;
mGridLineSpacing = lcGetProfileInt ( LC_PROFILE_GRID_LINE_SPACING ) ;
mGridLineColor = lcGetProfileInt ( LC_PROFILE_GRID_LINE_COLOR ) ;
}
void lcPreferences : : SaveDefaults ( )
{
2014-10-05 07:21:51 +02:00
lcSetProfileInt ( LC_PROFILE_FIXED_AXES , mFixedAxes ) ;
2014-02-10 01:13:41 +01:00
lcSetProfileInt ( LC_PROFILE_MOUSE_SENSITIVITY , mMouseSensitivity ) ;
2017-08-25 21:57:14 +02:00
lcSetProfileInt ( LC_PROFILE_SHADING_MODE , mShadingMode ) ;
2014-02-10 01:13:41 +01:00
lcSetProfileInt ( LC_PROFILE_DRAW_AXES , mDrawAxes ) ;
lcSetProfileInt ( LC_PROFILE_DRAW_EDGE_LINES , mDrawEdgeLines ) ;
lcSetProfileFloat ( LC_PROFILE_LINE_WIDTH , mLineWidth ) ;
lcSetProfileInt ( LC_PROFILE_GRID_STUDS , mDrawGridStuds ) ;
lcSetProfileInt ( LC_PROFILE_GRID_STUD_COLOR , mGridStudColor ) ;
lcSetProfileInt ( LC_PROFILE_GRID_LINES , mDrawGridLines ) ;
lcSetProfileInt ( LC_PROFILE_GRID_LINE_SPACING , mGridLineSpacing ) ;
lcSetProfileInt ( LC_PROFILE_GRID_LINE_COLOR , mGridLineColor ) ;
}
2013-08-09 06:57:18 +02:00
lcApplication : : lcApplication ( )
{
2017-04-14 02:26:40 +02:00
mProject = nullptr ;
mLibrary = nullptr ;
mClipboard = nullptr ;
2014-02-10 01:13:41 +01:00
mPreferences . LoadDefaults ( ) ;
2013-08-09 06:57:18 +02:00
}
lcApplication : : ~ lcApplication ( )
{
2015-01-08 06:40:22 +01:00
delete mProject ;
delete mLibrary ;
2013-08-09 06:57:18 +02:00
}
2014-12-04 02:47:28 +01:00
void lcApplication : : SetProject ( Project * Project )
{
delete mProject ;
mProject = Project ;
2016-03-06 02:47:00 +01:00
gMainWindow - > RemoveAllModelTabs ( ) ;
2014-12-04 02:47:28 +01:00
2015-03-14 20:07:07 +01:00
Project - > SetActiveModel ( 0 ) ;
2015-01-07 17:52:42 +01:00
lcGetPiecesLibrary ( ) - > RemoveTemporaryPieces ( ) ;
2014-12-04 02:47:28 +01:00
}
2014-12-16 00:55:17 +01:00
void lcApplication : : SetClipboard ( const QByteArray & Clipboard )
2013-08-09 06:57:18 +02:00
{
mClipboard = Clipboard ;
2014-12-16 00:55:17 +01:00
gMainWindow - > UpdatePaste ( ! mClipboard . isEmpty ( ) ) ;
2013-08-09 06:57:18 +02:00
}
2015-01-31 21:38:53 +01:00
void lcApplication : : ExportClipboard ( const QByteArray & Clipboard )
{
QMimeData * MimeData = new QMimeData ( ) ;
MimeData - > setData ( " application/vnd.leocad-clipboard " , Clipboard ) ;
QApplication : : clipboard ( ) - > setMimeData ( MimeData ) ;
SetClipboard ( Clipboard ) ;
}
2015-07-22 06:00:47 +02:00
bool lcApplication : : LoadPiecesLibrary ( const char * LibPath , const char * LibraryInstallPath , const char * LDrawPath )
2013-08-09 06:57:18 +02:00
{
2017-04-14 02:26:40 +02:00
if ( mLibrary = = nullptr )
2014-02-10 01:13:41 +01:00
mLibrary = new lcPiecesLibrary ( ) ;
2013-08-09 06:57:18 +02:00
if ( LibPath & & LibPath [ 0 ] )
2015-07-22 06:00:47 +02:00
return mLibrary - > Load ( LibPath ) ;
2014-09-13 00:47:08 +02:00
char * EnvPath = getenv ( " LEOCAD_LIB " ) ;
if ( EnvPath & & EnvPath [ 0 ] )
2013-08-09 06:57:18 +02:00
{
2015-07-22 06:00:47 +02:00
return mLibrary - > Load ( EnvPath ) ;
2013-08-09 06:57:18 +02:00
}
2015-01-31 22:44:57 +01:00
QString CustomPath = lcGetProfileString ( LC_PROFILE_PARTS_LIBRARY ) ;
2013-08-09 06:57:18 +02:00
2015-01-31 22:44:57 +01:00
if ( ! CustomPath . isEmpty ( ) )
2017-05-29 22:31:24 +02:00
return mLibrary - > Load ( CustomPath ) ;
2013-08-09 06:57:18 +02:00
2014-09-13 00:47:08 +02:00
if ( LibraryInstallPath & & LibraryInstallPath [ 0 ] )
{
char LibraryPath [ LC_MAXPATH ] ;
2013-08-09 06:57:18 +02:00
2014-09-13 00:47:08 +02:00
strcpy ( LibraryPath , LibraryInstallPath ) ;
2013-08-09 06:57:18 +02:00
2016-02-17 00:11:52 +01:00
size_t i = strlen ( LibraryPath ) - 1 ;
2014-09-13 00:47:08 +02:00
if ( ( LibraryPath [ i ] ! = ' \\ ' ) & & ( LibraryPath [ i ] ! = ' / ' ) )
strcat ( LibraryPath , " / " ) ;
2013-08-09 06:57:18 +02:00
2014-09-13 00:47:08 +02:00
strcat ( LibraryPath , " library.bin " ) ;
2013-08-09 06:57:18 +02:00
2015-07-22 06:00:47 +02:00
if ( mLibrary - > Load ( LibraryPath ) )
2014-09-13 00:47:08 +02:00
{
mLibrary - > SetOfficialPieces ( ) ;
return true ;
2013-08-09 06:57:18 +02:00
}
}
2014-09-13 00:47:08 +02:00
if ( LDrawPath & & LDrawPath [ 0 ] )
{
char LibraryPath [ LC_MAXPATH ] ;
strcpy ( LibraryPath , LDrawPath ) ;
2016-02-17 00:11:52 +01:00
size_t i = strlen ( LibraryPath ) - 1 ;
2014-09-13 00:47:08 +02:00
if ( ( LibraryPath [ i ] ! = ' \\ ' ) & & ( LibraryPath [ i ] ! = ' / ' ) )
strcat ( LibraryPath , " / " ) ;
2015-07-22 06:00:47 +02:00
if ( mLibrary - > Load ( LibraryPath ) )
2014-09-13 00:47:08 +02:00
return true ;
}
2013-08-09 06:57:18 +02:00
return false ;
}
void lcApplication : : ParseIntegerArgument ( int * CurArg , int argc , char * argv [ ] , int * Value )
{
if ( argc > ( * CurArg + 1 ) )
{
( * CurArg ) + + ;
int val ;
if ( ( sscanf ( argv [ ( * CurArg ) ] , " %d " , & val ) = = 1 ) & & ( val > 0 ) )
* Value = val ;
else
2017-02-13 03:05:20 +01:00
{
* Value = 0 ;
2013-08-16 03:31:30 +02:00
printf ( " Invalid value specified for the %s argument. " , argv [ ( * CurArg ) - 1 ] ) ;
2017-02-13 03:05:20 +01:00
}
2013-08-09 06:57:18 +02:00
}
else
{
2014-07-06 08:04:09 +02:00
* Value = 0 ;
2013-08-16 03:31:30 +02:00
printf ( " Not enough parameters for the %s argument. " , argv [ ( * CurArg ) - 1 ] ) ;
2013-08-09 06:57:18 +02:00
}
}
void lcApplication : : ParseStringArgument ( int * CurArg , int argc , char * argv [ ] , char * * Value )
{
if ( argc > ( * CurArg + 1 ) )
{
( * CurArg ) + + ;
* Value = argv [ ( * CurArg ) ] ;
}
else
{
2013-08-16 03:31:30 +02:00
printf ( " No path specified after the %s argument. " , argv [ ( * CurArg ) - 1 ] ) ;
2013-08-09 06:57:18 +02:00
}
}
2016-12-07 18:24:47 +01:00
bool lcApplication : : Initialize ( int argc , char * argv [ ] , const char * LibraryInstallPath , const char * LDrawPath , bool & ShowWindow )
2013-08-09 06:57:18 +02:00
{
2017-05-29 22:31:24 +02:00
// todo: parse command line using Qt to handle multibyte strings.
2017-04-14 02:26:40 +02:00
char * LibPath = nullptr ;
2013-08-09 06:57:18 +02:00
// Image output options.
bool SaveImage = false ;
2015-01-23 02:58:33 +01:00
bool SaveWavefront = false ;
2015-03-27 21:20:12 +01:00
bool Save3DS = false ;
2017-06-21 07:46:52 +02:00
bool Orthographic = false ;
2017-06-20 20:32:48 +02:00
bool ImageHighlight = false ;
2013-08-09 06:57:18 +02:00
int ImageWidth = lcGetProfileInt ( LC_PROFILE_IMAGE_WIDTH ) ;
int ImageHeight = lcGetProfileInt ( LC_PROFILE_IMAGE_HEIGHT ) ;
2014-07-06 08:04:09 +02:00
lcStep ImageStart = 0 ;
lcStep ImageEnd = 0 ;
2017-04-14 02:26:40 +02:00
char * ImageName = nullptr ;
2017-06-20 05:03:49 +02:00
char * ModelName = nullptr ;
char * CameraName = nullptr ;
2017-06-21 07:46:52 +02:00
char * Viewpoint = nullptr ;
2017-04-14 02:26:40 +02:00
char * ProjectName = nullptr ;
char * SaveWavefrontName = nullptr ;
char * Save3DSName = nullptr ;
2013-08-09 06:57:18 +02:00
// Parse the command line arguments.
for ( int i = 1 ; i < argc ; i + + )
{
char * Param = argv [ i ] ;
if ( Param [ 0 ] = = ' - ' )
{
2013-08-11 22:35:04 +02:00
if ( ( strcmp ( Param , " -l " ) = = 0 ) | | ( strcmp ( Param , " --libpath " ) = = 0 ) )
2013-08-09 06:57:18 +02:00
{
ParseStringArgument ( & i , argc , argv , & LibPath ) ;
}
else if ( ( strcmp ( Param , " -i " ) = = 0 ) | | ( strcmp ( Param , " --image " ) = = 0 ) )
{
SaveImage = true ;
if ( ( argc > ( i + 1 ) ) & & ( argv [ i + 1 ] [ 0 ] ! = ' - ' ) )
{
i + + ;
ImageName = argv [ i ] ;
}
}
else if ( ( strcmp ( Param , " -w " ) = = 0 ) | | ( strcmp ( Param , " --width " ) = = 0 ) )
{
ParseIntegerArgument ( & i , argc , argv , & ImageWidth ) ;
}
else if ( ( strcmp ( Param , " -h " ) = = 0 ) | | ( strcmp ( Param , " --height " ) = = 0 ) )
{
ParseIntegerArgument ( & i , argc , argv , & ImageHeight ) ;
}
else if ( ( strcmp ( Param , " -f " ) = = 0 ) | | ( strcmp ( Param , " --from " ) = = 0 ) )
{
2014-07-06 08:04:09 +02:00
int Step ;
ParseIntegerArgument ( & i , argc , argv , & Step ) ;
ImageStart = Step ;
2013-08-09 06:57:18 +02:00
}
else if ( ( strcmp ( Param , " -t " ) = = 0 ) | | ( strcmp ( Param , " --to " ) = = 0 ) )
{
2014-07-06 08:04:09 +02:00
int Step ;
ParseIntegerArgument ( & i , argc , argv , & Step ) ;
ImageEnd = Step ;
2013-08-09 06:57:18 +02:00
}
2017-06-20 05:03:49 +02:00
else if ( ( strcmp ( Param , " -m " ) = = 0 ) | | ( strcmp ( Param , " --model " ) = = 0 ) )
{
if ( ( argc > ( i + 1 ) ) & & ( argv [ i + 1 ] [ 0 ] ! = ' - ' ) )
{
i + + ;
ModelName = argv [ i ] ;
}
}
else if ( ( strcmp ( Param , " -c " ) = = 0 ) | | ( strcmp ( Param , " --camera " ) = = 0 ) )
{
if ( ( argc > ( i + 1 ) ) & & ( argv [ i + 1 ] [ 0 ] ! = ' - ' ) )
{
i + + ;
CameraName = argv [ i ] ;
}
}
2017-06-21 07:46:52 +02:00
else if ( strcmp ( Param , " --viewpoint " ) = = 0 )
{
if ( ( argc > ( i + 1 ) ) & & ( argv [ i + 1 ] [ 0 ] ! = ' - ' ) )
{
i + + ;
Viewpoint = argv [ i ] ;
}
}
else if ( strcmp ( Param , " --orthographic " ) = = 0 )
Orthographic = true ;
2017-06-20 20:32:48 +02:00
else if ( strcmp ( Param , " --highlight " ) = = 0 )
ImageHighlight = true ;
2015-03-27 21:20:12 +01:00
else if ( ( strcmp ( Param , " -wf " ) = = 0 ) | | ( strcmp ( Param , " --export-wavefront " ) = = 0 ) )
2015-01-23 02:58:33 +01:00
{
SaveWavefront = true ;
if ( ( argc > ( i + 1 ) ) & & ( argv [ i + 1 ] [ 0 ] ! = ' - ' ) )
{
i + + ;
2015-03-27 21:20:12 +01:00
SaveWavefrontName = argv [ i ] ;
}
}
else if ( ( strcmp ( Param , " -3ds " ) = = 0 ) | | ( strcmp ( Param , " --export-3ds " ) = = 0 ) )
{
Save3DS = true ;
if ( ( argc > ( i + 1 ) ) & & ( argv [ i + 1 ] [ 0 ] ! = ' - ' ) )
{
i + + ;
Save3DSName = argv [ i ] ;
2015-01-23 02:58:33 +01:00
}
}
2013-08-09 06:57:18 +02:00
else if ( ( strcmp ( Param , " -v " ) = = 0 ) | | ( strcmp ( Param , " --version " ) = = 0 ) )
{
printf ( " LeoCAD Version " LC_VERSION_TEXT " \n " ) ;
2014-09-09 00:01:24 +02:00
printf ( " Compiled " __DATE__ " \n " ) ;
2013-08-09 06:57:18 +02:00
2016-12-07 18:24:47 +01:00
ShowWindow = false ;
return true ;
2013-08-09 06:57:18 +02:00
}
else if ( ( strcmp ( Param , " -? " ) = = 0 ) | | ( strcmp ( Param , " --help " ) = = 0 ) )
{
printf ( " Usage: leocad [options] [file] \n " ) ;
printf ( " [options] can be: \n " ) ;
printf ( " -l, --libpath <path>: Loads the Pieces Library from path. \n " ) ;
printf ( " -i, --image <outfile.ext>: Saves a picture in the format specified by ext. \n " ) ;
printf ( " -w, --width <width>: Sets the picture width. \n " ) ;
printf ( " -h, --height <height>: Sets the picture height. \n " ) ;
printf ( " -f, --from <time>: Sets the first frame or step to save pictures. \n " ) ;
printf ( " -t, --to <time>: Sets the last frame or step to save pictures. \n " ) ;
2017-06-20 05:07:59 +02:00
printf ( " -m, --model <model>: Sets the active submodel. \n " ) ;
printf ( " -c, --camera <camera>: Sets the active camera. \n " ) ;
2017-06-21 07:46:52 +02:00
printf ( " --viewpoint (front|back|left|right|top|bottom|home): Sets the viewpoint. \n " ) ;
printf ( " --orthographic: Make the view orthographic. \n " ) ;
2017-06-20 20:32:48 +02:00
printf ( " --highlight: Highlight pieces in the steps they appear. \n " ) ;
2015-03-27 21:20:12 +01:00
printf ( " -wf, --export-wavefront <outfile.obj>: Exports the model to Wavefront format. \n " ) ;
printf ( " -3ds, --export-3ds <outfile.3ds>: Exports the model to 3DS format. \n " ) ;
2017-06-21 07:47:32 +02:00
printf ( " -v, --version: Output version information and exit. \n " ) ;
printf ( " -?, --help: Display this help and exit. \n " ) ;
2013-08-09 06:57:18 +02:00
printf ( " \n " ) ;
2016-12-07 18:24:47 +01:00
ShowWindow = false ;
return true ;
2013-08-09 06:57:18 +02:00
}
else
2013-08-11 22:35:04 +02:00
printf ( " Unknown parameter: %s \n " , Param ) ;
2013-08-09 06:57:18 +02:00
}
else
{
ProjectName = Param ;
}
}
2015-01-24 00:18:32 +01:00
gMainWindow = new lcMainWindow ( ) ;
2015-01-24 03:12:24 +01:00
lcLoadDefaultKeyboardShortcuts ( ) ;
2016-04-23 02:17:33 +02:00
lcLoadDefaultMouseShortcuts ( ) ;
2015-01-24 00:18:32 +01:00
2016-12-07 18:24:47 +01:00
ShowWindow = ! SaveImage & & ! SaveWavefront & & ! Save3DS ;
2015-07-22 06:00:47 +02:00
if ( ! LoadPiecesLibrary ( LibPath , LibraryInstallPath , LDrawPath ) )
2013-08-09 06:57:18 +02:00
{
2016-12-07 18:24:47 +01:00
QString Message ;
2013-08-09 06:57:18 +02:00
2014-09-11 21:55:34 +02:00
if ( mLibrary - > LoadBuiltinPieces ( ) )
2016-12-07 18:24:47 +01:00
Message = tr ( " LeoCAD could not find a compatible Parts Library so only a small number of parts will be available. \n \n Please visit http://www.leocad.org for information on how to download and install a library. " ) ;
2014-09-11 21:55:34 +02:00
else
2016-12-07 18:24:47 +01:00
Message = tr ( " LeoCAD could not load Parts Library. \n \n Please visit http://www.leocad.org for information on how to download and install a library. " ) ;
if ( ShowWindow )
QMessageBox : : information ( gMainWindow , tr ( " LeoCAD " ) , Message ) ;
else
2016-12-16 21:52:36 +01:00
fprintf ( stderr , " %s " , Message . toLatin1 ( ) . constData ( ) ) ;
2013-08-09 06:57:18 +02:00
}
2015-01-26 00:04:39 +01:00
gMainWindow - > CreateWidgets ( ) ;
2015-01-24 00:18:32 +01:00
2013-08-09 06:57:18 +02:00
// Create a new project.
2015-01-23 19:45:58 +01:00
Project * NewProject = new Project ( ) ;
SetProject ( NewProject ) ;
2013-08-09 06:57:18 +02:00
// Load project.
2014-12-31 17:38:30 +01:00
if ( ProjectName & & gMainWindow - > OpenProject ( ProjectName ) )
2013-08-09 06:57:18 +02:00
{
2017-06-21 06:43:39 +02:00
if ( ModelName )
2017-06-20 05:03:49 +02:00
lcGetActiveProject ( ) - > SetActiveModel ( QString : : fromUtf8 ( ModelName ) ) ;
2017-06-21 06:43:39 +02:00
if ( CameraName )
2017-06-21 07:46:52 +02:00
{
2017-06-21 06:43:39 +02:00
gMainWindow - > GetActiveView ( ) - > SetCamera ( CameraName ) ;
2017-06-21 07:46:52 +02:00
if ( Viewpoint | | Orthographic )
printf ( " Warning: --viewpoint and --orthographic are ignored when --camera is set. \n " ) ;
}
else
{
if ( Viewpoint )
{
if ( strcmp ( Viewpoint , " front " ) = = 0 )
gMainWindow - > GetActiveView ( ) - > SetViewpoint ( LC_VIEWPOINT_FRONT ) ;
else if ( strcmp ( Viewpoint , " back " ) = = 0 )
gMainWindow - > GetActiveView ( ) - > SetViewpoint ( LC_VIEWPOINT_BACK ) ;
else if ( strcmp ( Viewpoint , " top " ) = = 0 )
gMainWindow - > GetActiveView ( ) - > SetViewpoint ( LC_VIEWPOINT_TOP ) ;
else if ( strcmp ( Viewpoint , " bottom " ) = = 0 )
gMainWindow - > GetActiveView ( ) - > SetViewpoint ( LC_VIEWPOINT_BOTTOM ) ;
else if ( strcmp ( Viewpoint , " left " ) = = 0 )
gMainWindow - > GetActiveView ( ) - > SetViewpoint ( LC_VIEWPOINT_LEFT ) ;
else if ( strcmp ( Viewpoint , " right " ) = = 0 )
gMainWindow - > GetActiveView ( ) - > SetViewpoint ( LC_VIEWPOINT_RIGHT ) ;
else if ( strcmp ( Viewpoint , " home " ) = = 0 )
gMainWindow - > GetActiveView ( ) - > SetViewpoint ( LC_VIEWPOINT_HOME ) ;
else
printf ( " Unknown viewpoint: %s \n " , Viewpoint ) ;
}
gMainWindow - > GetActiveView ( ) - > SetProjection ( Orthographic ) ;
}
2017-06-20 05:03:49 +02:00
2015-01-23 02:58:33 +01:00
if ( SaveImage )
{
QString FileName ;
2013-08-09 06:57:18 +02:00
2015-01-23 02:58:33 +01:00
if ( ImageName )
FileName = ImageName ;
else
FileName = ProjectName ;
2013-08-09 06:57:18 +02:00
2015-01-23 02:58:33 +01:00
QString Extension = QFileInfo ( FileName ) . suffix ( ) . toLower ( ) ;
2013-08-09 06:57:18 +02:00
2015-01-23 02:58:33 +01:00
if ( Extension . isEmpty ( ) )
{
FileName + = lcGetProfileString ( LC_PROFILE_IMAGE_EXTENSION ) ;
}
else if ( Extension ! = " bmp " & & Extension ! = " jpg " & & Extension ! = " jpeg " & & Extension ! = " png " )
{
FileName = FileName . left ( FileName . length ( ) - Extension . length ( ) - 1 ) ;
FileName + = lcGetProfileString ( LC_PROFILE_IMAGE_EXTENSION ) ;
}
2013-08-09 06:57:18 +02:00
2015-01-23 02:58:33 +01:00
if ( ImageEnd < ImageStart )
ImageEnd = ImageStart ;
else if ( ImageStart > ImageEnd )
ImageStart = ImageEnd ;
if ( ( ImageStart = = 0 ) & & ( ImageEnd = = 0 ) )
{
ImageStart = ImageEnd = mProject - > GetActiveModel ( ) - > GetCurrentStep ( ) ;
}
else if ( ( ImageStart = = 0 ) & & ( ImageEnd ! = 0 ) )
{
ImageStart = ImageEnd ;
}
else if ( ( ImageStart ! = 0 ) & & ( ImageEnd = = 0 ) )
{
ImageEnd = ImageStart ;
}
2013-08-09 06:57:18 +02:00
2015-01-23 02:58:33 +01:00
if ( ImageStart > 255 )
ImageStart = 255 ;
2013-08-09 06:57:18 +02:00
2015-01-23 02:58:33 +01:00
if ( ImageEnd > 255 )
ImageEnd = 255 ;
2013-08-09 06:57:18 +02:00
2015-01-23 02:58:33 +01:00
QString Frame ;
2013-08-09 06:57:18 +02:00
2015-01-23 02:58:33 +01:00
if ( ImageStart ! = ImageEnd )
{
QString Extension = QFileInfo ( FileName ) . suffix ( ) ;
Frame = FileName . left ( FileName . length ( ) - Extension . length ( ) - 1 ) + QLatin1String ( " %1. " ) + Extension ;
}
else
Frame = FileName ;
2013-08-09 06:57:18 +02:00
2017-06-20 06:56:14 +02:00
lcGetActiveModel ( ) - > SaveStepImages ( Frame , ImageStart ! = ImageEnd , CameraName = = nullptr , ImageHighlight , ImageWidth , ImageHeight , ImageStart , ImageEnd ) ;
2015-01-23 02:58:33 +01:00
}
2013-08-09 06:57:18 +02:00
2015-01-23 02:58:33 +01:00
if ( SaveWavefront )
2013-08-09 06:57:18 +02:00
{
2015-01-23 02:58:33 +01:00
QString FileName ;
2015-03-27 21:20:12 +01:00
if ( SaveWavefrontName )
FileName = SaveWavefrontName ;
2015-01-23 02:58:33 +01:00
else
FileName = ProjectName ;
2013-08-09 06:57:18 +02:00
2015-01-23 02:58:33 +01:00
QString Extension = QFileInfo ( FileName ) . suffix ( ) . toLower ( ) ;
2013-08-09 06:57:18 +02:00
2015-01-23 02:58:33 +01:00
if ( Extension . isEmpty ( ) )
{
FileName + = " .obj " ;
}
else if ( Extension ! = " obj " )
{
FileName = FileName . left ( FileName . length ( ) - Extension . length ( ) - 1 ) ;
FileName + = " .obj " ;
}
mProject - > ExportWavefront ( FileName ) ;
}
2015-03-27 21:20:12 +01:00
if ( Save3DS )
{
QString FileName ;
if ( Save3DSName )
FileName = Save3DSName ;
else
FileName = ProjectName ;
QString Extension = QFileInfo ( FileName ) . suffix ( ) . toLower ( ) ;
if ( Extension . isEmpty ( ) )
{
FileName + = " .3ds " ;
}
else if ( Extension ! = " 3ds " )
{
FileName = FileName . left ( FileName . length ( ) - Extension . length ( ) - 1 ) ;
FileName + = " .3ds " ;
}
mProject - > Export3DStudio ( FileName ) ;
}
2013-08-09 06:57:18 +02:00
}
2015-01-23 02:58:33 +01:00
2013-08-09 06:57:18 +02:00
return true ;
}
void lcApplication : : Shutdown ( )
{
2014-02-10 01:13:41 +01:00
delete mLibrary ;
2017-04-14 02:26:40 +02:00
mLibrary = nullptr ;
2013-08-09 06:57:18 +02:00
}
2014-02-10 01:13:41 +01:00
void lcApplication : : ShowPreferencesDialog ( )
{
lcPreferencesDialogOptions Options ;
int CurrentAASamples = lcGetProfileInt ( LC_PROFILE_ANTIALIASING_SAMPLES ) ;
Options . Preferences = mPreferences ;
2015-01-31 22:44:57 +01:00
Options . DefaultAuthor = lcGetProfileString ( LC_PROFILE_DEFAULT_AUTHOR_NAME ) ;
Options . LibraryPath = lcGetProfileString ( LC_PROFILE_PARTS_LIBRARY ) ;
Options . POVRayPath = lcGetProfileString ( LC_PROFILE_POVRAY_PATH ) ;
Options . LGEOPath = lcGetProfileString ( LC_PROFILE_POVRAY_LGEO_PATH ) ;
2014-02-10 01:13:41 +01:00
Options . CheckForUpdates = lcGetProfileInt ( LC_PROFILE_CHECK_UPDATES ) ;
Options . AASamples = CurrentAASamples ;
Options . Categories = gCategories ;
Options . CategoriesModified = false ;
Options . CategoriesDefault = false ;
Options . KeyboardShortcuts = gKeyboardShortcuts ;
2016-04-25 07:26:34 +02:00
Options . KeyboardShortcutsModified = false ;
Options . KeyboardShortcutsDefault = false ;
Options . MouseShortcuts = gMouseShortcuts ;
Options . MouseShortcutsModified = false ;
Options . MouseShortcutsDefault = false ;
2014-02-10 01:13:41 +01:00
if ( ! gMainWindow - > DoDialog ( LC_DIALOG_PREFERENCES , & Options ) )
return ;
2015-01-31 22:44:57 +01:00
bool LibraryChanged = Options . LibraryPath ! = lcGetProfileString ( LC_PROFILE_PARTS_LIBRARY ) ;
2014-02-10 01:13:41 +01:00
bool AAChanged = CurrentAASamples ! = Options . AASamples ;
mPreferences = Options . Preferences ;
mPreferences . SaveDefaults ( ) ;
lcSetProfileString ( LC_PROFILE_DEFAULT_AUTHOR_NAME , Options . DefaultAuthor ) ;
lcSetProfileString ( LC_PROFILE_PARTS_LIBRARY , Options . LibraryPath ) ;
lcSetProfileString ( LC_PROFILE_POVRAY_PATH , Options . POVRayPath ) ;
lcSetProfileString ( LC_PROFILE_POVRAY_LGEO_PATH , Options . LGEOPath ) ;
lcSetProfileInt ( LC_PROFILE_CHECK_UPDATES , Options . CheckForUpdates ) ;
lcSetProfileInt ( LC_PROFILE_ANTIALIASING_SAMPLES , Options . AASamples ) ;
if ( LibraryChanged & & AAChanged )
2015-01-30 17:30:13 +01:00
QMessageBox : : information ( gMainWindow , tr ( " LeoCAD " ) , tr ( " Parts library and Anti-aliasing changes will only take effect the next time you start LeoCAD. " ) ) ;
2014-02-10 01:13:41 +01:00
else if ( LibraryChanged )
2015-01-30 17:30:13 +01:00
QMessageBox : : information ( gMainWindow , tr ( " LeoCAD " ) , tr ( " Parts library changes will only take effect the next time you start LeoCAD. " ) ) ;
2014-02-10 01:13:41 +01:00
else if ( AAChanged )
2015-01-30 17:30:13 +01:00
QMessageBox : : information ( gMainWindow , tr ( " LeoCAD " ) , tr ( " Anti-aliasing changes will only take effect the next time you start LeoCAD. " ) ) ;
2014-02-10 01:13:41 +01:00
if ( Options . CategoriesModified )
{
if ( Options . CategoriesDefault )
lcResetDefaultCategories ( ) ;
else
{
gCategories = Options . Categories ;
lcSaveDefaultCategories ( ) ;
}
gMainWindow - > UpdateCategories ( ) ;
}
2016-04-25 07:26:34 +02:00
if ( Options . KeyboardShortcutsModified )
2014-02-10 01:13:41 +01:00
{
2016-04-25 07:26:34 +02:00
if ( Options . KeyboardShortcutsDefault )
2014-02-10 01:13:41 +01:00
lcResetDefaultKeyboardShortcuts ( ) ;
else
{
gKeyboardShortcuts = Options . KeyboardShortcuts ;
lcSaveDefaultKeyboardShortcuts ( ) ;
}
gMainWindow - > UpdateShortcuts ( ) ;
}
2016-04-25 07:26:34 +02:00
if ( Options . MouseShortcutsModified )
{
if ( Options . MouseShortcutsDefault )
lcResetDefaultMouseShortcuts ( ) ;
else
{
gMouseShortcuts = Options . MouseShortcuts ;
lcSaveDefaultMouseShortcuts ( ) ;
}
}
2014-02-10 01:13:41 +01:00
// TODO: printing preferences
/*
strcpy ( opts . strFooter , m_strFooter ) ;
strcpy ( opts . strHeader , m_strHeader ) ;
*/
2014-05-03 23:16:48 +02:00
gMainWindow - > UpdateAllViews ( ) ;
2014-03-07 03:39:28 +01:00
}