mirror of
https://github.com/leozide/leocad
synced 2024-11-17 07:47:55 +01:00
Added export to Brick Link.
This commit is contained in:
parent
5becf6f62b
commit
1fbb448ba4
9 changed files with 226 additions and 1 deletions
|
@ -22,6 +22,7 @@ LC_KEYBOARD_COMMAND DefaultKeyboardShortcuts[] =
|
|||
{ LC_FILE_PICTURE, "Save Picture", 0, 0, 0 },
|
||||
{ LC_FILE_3DS, "Export 3D Studio", 0, 0, 0 },
|
||||
{ LC_FILE_HTML, "Export HTML", 0, 0, 0 },
|
||||
{ LC_FILE_BRICKLINK, "Export BrickLink", 0, 0, 0 },
|
||||
{ LC_FILE_POVRAY, "Export POV-Ray", 0, 0, 0 },
|
||||
{ LC_FILE_WAVEFRONT, "Export Wavefront", 0, 0, 0 },
|
||||
{ LC_FILE_PROPERTIES, "Project Properties", 0, 0, 0 },
|
||||
|
|
|
@ -195,6 +195,153 @@ static void GetToken(char*& Ptr, char* Token)
|
|||
*Token = 0;
|
||||
}
|
||||
|
||||
int lcGetBrickLinkColor(int ColorIndex)
|
||||
{
|
||||
struct lcBrickLinkEntry
|
||||
{
|
||||
int Code;
|
||||
const char* Name;
|
||||
};
|
||||
|
||||
lcBrickLinkEntry BrickLinkColors[] =
|
||||
{
|
||||
{ 41, "Aqua" },
|
||||
{ 11, "Black" },
|
||||
{ 7, "Blue" },
|
||||
{ 97, "Blue Violet" }, // Blue-Violet
|
||||
{ 36, "Bright Green" },
|
||||
{ 105, "Bright Light Blue" },
|
||||
{ 110, "Bright Light Orange" },
|
||||
{ 103, "Bright Light Yellow" },
|
||||
{ 104, "Bright Pink" },
|
||||
{ 8, "Brown" },
|
||||
{ 153, "Dark Azure" },
|
||||
{ 63, "Dark Blue" },
|
||||
{ 109, "Dark Blue Violet" }, // Dark Blue-Violet
|
||||
{ 85, "Dark Bluish Gray" },
|
||||
{ 120, "Dark Brown" },
|
||||
{ 91, "Dark Flesh" },
|
||||
{ 10, "Dark Gray" },
|
||||
{ 80, "Dark Green" },
|
||||
{ 68, "Dark Orange" },
|
||||
{ 47, "Dark Pink" },
|
||||
{ 89, "Dark Purple" },
|
||||
{ 59, "Dark Red" },
|
||||
{ 69, "Dark Tan" },
|
||||
{ 39, "Dark Turquoise" },
|
||||
{ 29, "Earth Orange" },
|
||||
{ 106, "Fabuland Brown" },
|
||||
{ 160, "Fabuland Orange" }, // No match
|
||||
{ 28, "Flesh" },
|
||||
{ 6, "Green" },
|
||||
{ 154, "Lavender" },
|
||||
{ 152, "Light Aqua" },
|
||||
{ 62, "Light Blue" },
|
||||
{ 86, "Light Bluish Gray" },
|
||||
{ 90, "Light Flesh" },
|
||||
{ 9, "Light Gray" },
|
||||
{ 38, "Light Green" },
|
||||
{ 35, "Light Lime" },
|
||||
{ 32, "Light Orange" },
|
||||
{ 56, "Light Pink" },
|
||||
{ 93, "Light Purple" },
|
||||
{ 26, "Light Salmon" },
|
||||
{ 40, "Light Turquoise" },
|
||||
{ 44, "Light Violet" },
|
||||
{ 33, "Light Yellow" },
|
||||
{ 34, "Lime" },
|
||||
{ 72, "Maersk Blue" },
|
||||
{ 71, "Magenta" },
|
||||
{ 156, "Medium Azure" },
|
||||
{ 42, "Medium Blue" },
|
||||
{ 150, "Medium Dark Flesh" },
|
||||
{ 94, "Medium Dark Pink" },
|
||||
{ 37, "Medium Green" },
|
||||
{ 157, "Medium Lavender" },
|
||||
{ 76, "Medium Lime" },
|
||||
{ 31, "Medium Orange" },
|
||||
{ 73, "Medium Violet" },
|
||||
{ 155, "Olive Green" },
|
||||
{ 4, "Orange" },
|
||||
{ 23, "Pink" },
|
||||
{ 24, "Purple" },
|
||||
{ 5, "Red" },
|
||||
{ 88, "Reddish Brown" },
|
||||
{ 27, "Rust" },
|
||||
{ 25, "Salmon" },
|
||||
{ 55, "Sand Blue" },
|
||||
{ 48, "Sand Green" },
|
||||
{ 54, "Sand Purple" },
|
||||
{ 58, "Sand Red" },
|
||||
{ 87, "Sky Blue" },
|
||||
{ 2, "Tan" },
|
||||
{ 99, "Very Light Bluish Gray" },
|
||||
{ 49, "Very Light Gray" },
|
||||
{ 96, "Very Light Orange" },
|
||||
{ 43, "Violet" },
|
||||
{ 1, "White" },
|
||||
{ 3, "Yellow" },
|
||||
{ 158, "Yellowish Green" },
|
||||
{ 13, "Trans Black" }, // Trans-Black
|
||||
{ 108, "Trans Bright Green" }, // Trans-Bright Green
|
||||
{ 12, "Trans Clear" }, // Trans-Clear
|
||||
{ 14, "Trans Dark Blue" }, // Trans-Dark Blue
|
||||
{ 50, "Trans Dark Pink" }, // Trans-Dark Pink
|
||||
{ 20, "Trans Green" }, // Trans-Green
|
||||
{ 15, "Trans Light Blue" }, // Trans-Light Blue
|
||||
{ 114, "Trans Light Purple" }, // Trans-Light Purple
|
||||
{ 74, "Trans Medium Blue" }, // Trans-Medium Blue
|
||||
{ 16, "Trans Neon Green" }, // Trans-Neon Green
|
||||
{ 18, "Trans Neon Orange" }, // Trans-Neon Orange
|
||||
{ 121, "Trans Neon Yellow" }, // Trans-Neon Yellow
|
||||
{ 98, "Trans Orange" }, // Trans-Orange
|
||||
{ 107, "Trans Pink" }, // Trans-Pink
|
||||
{ 51, "Trans Purple" }, // Trans-Purple
|
||||
{ 17, "Trans Red" }, // Trans-Red
|
||||
{ 113, "Trans Very Light Blue" }, // Trans-Very Lt Blue
|
||||
{ 19, "Trans Yellow" }, // Trans-Yellow
|
||||
{ 57, "Chrome Antique Brass" },
|
||||
{ 122, "Chrome Black" },
|
||||
{ 52, "Chrome Blue" },
|
||||
{ 21, "Chrome Gold" },
|
||||
{ 64, "Chrome Green" },
|
||||
{ 82, "Chrome Pink" },
|
||||
{ 22, "Chrome Silver" },
|
||||
{ 84, "Copper" },
|
||||
{ 81, "Flat Dark Gold" },
|
||||
{ 95, "Flat Silver" },
|
||||
{ 78, "Metal Blue" },
|
||||
{ 77, "Pearl Dark Gray" },
|
||||
{ 115, "Pearl Gold" },
|
||||
{ 61, "Pearl Light Gold" },
|
||||
{ 66, "Pearl Light Gray" },
|
||||
{ 119, "Pearl Very Light Grey" }, // Pearl Very Light Gray
|
||||
{ 83, "Pearl White" },
|
||||
{ 65, "Metallic Gold" },
|
||||
{ 70, "Metallic Green" },
|
||||
{ 67, "Metallic Silver" },
|
||||
{ 46, "Glow In Dark Opaque" },
|
||||
{ 118, "Glow In Dark Trans" },
|
||||
{ 159, "Glow in Dark White" }, // No match
|
||||
{ 60, "Milky White" },
|
||||
{ 101, "Glitter Trans Clear" }, // Glitter Trans-Clear
|
||||
{ 100, "Glitter Trans Dark Pink" }, // Glitter Trans-Dark Pink
|
||||
{ 102, "Glitter Trans Purple" }, // Glitter Trans-Purple
|
||||
{ 116, "Speckle Black Copper" }, // Speckle Black-Copper
|
||||
{ 151, "Speckle Black Gold" }, // Speckle Black-Gold
|
||||
{ 111, "Speckle Black Silver" }, // Speckle Black-Silver
|
||||
{ 117, "Speckle Dark Bluish Gray Silver" }, // Speckle DBGray-Silver
|
||||
};
|
||||
|
||||
const char* Name = gColorList[ColorIndex].Name;
|
||||
|
||||
for (int Color = 0; Color < sizeof(BrickLinkColors) / sizeof(BrickLinkColors[0]); Color++)
|
||||
if (!strcmp(Name, BrickLinkColors[Color].Name))
|
||||
return BrickLinkColors[Color].Code;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool lcLoadColorFile(lcFile& File)
|
||||
{
|
||||
char Line[1024], Token[1024];
|
||||
|
|
|
@ -40,6 +40,7 @@ extern int gDefaultColor;
|
|||
void lcLoadDefaultColors();
|
||||
bool lcLoadColorFile(lcFile& File);
|
||||
int lcGetColorIndex(lcuint32 ColorCode);
|
||||
int lcGetBrickLinkColor(int ColorIndex);
|
||||
|
||||
inline lcuint32 lcGetColorCodeFromExtendedColor(int Color)
|
||||
{
|
||||
|
|
|
@ -4071,6 +4071,60 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
|
|||
}
|
||||
} break;
|
||||
|
||||
case LC_FILE_BRICKLINK:
|
||||
{
|
||||
if (!m_pPieces)
|
||||
return;
|
||||
|
||||
char FileName[LC_MAXPATH];
|
||||
if (!SystemDoDialog(LC_DLG_BRICKLINK, FileName))
|
||||
break;
|
||||
|
||||
lcDiskFile BrickLinkFile;
|
||||
char Line[1024];
|
||||
|
||||
if (!BrickLinkFile.Open(FileName, "wt"))
|
||||
{
|
||||
SystemDoMessageBox("Could not open file for writing.", LC_MB_OK|LC_MB_ICONERROR);
|
||||
break;
|
||||
}
|
||||
|
||||
ObjArray<lcPiecesUsedEntry> PiecesUsed;
|
||||
GetPiecesUsed(PiecesUsed);
|
||||
|
||||
const char* OldLocale = setlocale(LC_NUMERIC, "C");
|
||||
BrickLinkFile.WriteLine("<INVENTORY>\n");
|
||||
|
||||
for (int PieceIdx = 0; PieceIdx < PiecesUsed.GetSize(); PieceIdx++)
|
||||
{
|
||||
BrickLinkFile.WriteLine(" <ITEM>\n");
|
||||
BrickLinkFile.WriteLine(" <ITEMTYPE>P</ITEMTYPE>\n");
|
||||
|
||||
sprintf(Line, " <ITEMID>%s</ITEMID>\n", PiecesUsed[PieceIdx].Info->m_strName);
|
||||
BrickLinkFile.WriteLine(Line);
|
||||
|
||||
int Count = PiecesUsed[PieceIdx].Count;
|
||||
if (Count > 1)
|
||||
{
|
||||
sprintf(Line, " <MINQTY>%d</MINQTY>\n", Count);
|
||||
BrickLinkFile.WriteLine(Line);
|
||||
}
|
||||
|
||||
int Color = lcGetBrickLinkColor(PiecesUsed[PieceIdx].ColorIndex);
|
||||
if (Color)
|
||||
{
|
||||
sprintf(Line, " <COLOR>%d</COLOR>\n", Color);
|
||||
BrickLinkFile.WriteLine(Line);
|
||||
}
|
||||
|
||||
BrickLinkFile.WriteLine(" </ITEM>\n");
|
||||
}
|
||||
|
||||
BrickLinkFile.WriteLine("</INVENTORY>\n");
|
||||
|
||||
setlocale(LC_NUMERIC, OldLocale);
|
||||
} break;
|
||||
|
||||
// Export to POV-Ray, swap X & Y from our cs to work with LGEO.
|
||||
case LC_FILE_POVRAY:
|
||||
{
|
||||
|
|
|
@ -32,6 +32,7 @@ enum LC_COMMANDS
|
|||
LC_FILE_PICTURE,
|
||||
LC_FILE_3DS,
|
||||
LC_FILE_HTML,
|
||||
LC_FILE_BRICKLINK,
|
||||
LC_FILE_POVRAY,
|
||||
LC_FILE_WAVEFRONT,
|
||||
LC_FILE_PROPERTIES,
|
||||
|
@ -241,6 +242,7 @@ enum LC_DIALOGS
|
|||
LC_DLG_FILE_SAVE,
|
||||
LC_DLG_DIRECTORY_BROWSE,
|
||||
LC_DLG_PICTURE_SAVE,
|
||||
LC_DLG_BRICKLINK,
|
||||
LC_DLG_HTML,
|
||||
LC_DLG_POVRAY,
|
||||
LC_DLG_WAVEFRONT,
|
||||
|
|
|
@ -235,6 +235,7 @@ BEGIN
|
|||
POPUP "Export"
|
||||
BEGIN
|
||||
MENUITEM "3D Studio...", ID_FILE_EXPORT_3DSTUDIO
|
||||
MENUITEM "BrickLink...", 33201
|
||||
MENUITEM "HTML...", ID_FILE_EXPORT_HTML
|
||||
MENUITEM "POV-Ray...", ID_FILE_EXPORT_POVRAY
|
||||
MENUITEM "Wavefront...", ID_FILE_EXPORT_WAVEFRONT
|
||||
|
@ -1749,6 +1750,8 @@ END
|
|||
STRINGTABLE
|
||||
BEGIN
|
||||
ID_VIEW_VIEWPOINT_HOME "View model from the default position."
|
||||
ID_FILE_EXPORT_BRICKLINK
|
||||
"Export a list of pieces that can be imported into the BrickLink website"
|
||||
END
|
||||
|
||||
STRINGTABLE
|
||||
|
|
|
@ -797,6 +797,10 @@ BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam)
|
|||
project->HandleCommand(LC_FILE_HTML, 0);
|
||||
} break;
|
||||
|
||||
case ID_FILE_EXPORT_BRICKLINK: {
|
||||
project->HandleCommand(LC_FILE_BRICKLINK, 0);
|
||||
} break;
|
||||
|
||||
case ID_FILE_EXPORT_POVRAY: {
|
||||
project->HandleCommand(LC_FILE_POVRAY, 0);
|
||||
} break;
|
||||
|
@ -1277,6 +1281,7 @@ void CMainFrame::UpdateMenuAccelerators()
|
|||
ID_FILE_SAVEPICTURE, // LC_FILE_PICTURE
|
||||
ID_FILE_EXPORT_3DSTUDIO, // LC_FILE_3DS
|
||||
ID_FILE_EXPORT_HTML, // LC_FILE_HTML
|
||||
ID_FILE_EXPORT_BRICKLINK, // LC_FILE_BRICKLINK
|
||||
ID_FILE_EXPORT_POVRAY, // LC_FILE_POVRAY
|
||||
ID_FILE_EXPORT_WAVEFRONT, // LC_FILE_WAVEFRONT
|
||||
ID_FILE_PROPERTIES, // LC_FILE_PROPERTIES
|
||||
|
|
|
@ -1023,6 +1023,17 @@ bool SystemDoDialog(int nMode, void* param)
|
|||
}
|
||||
} break;
|
||||
|
||||
case LC_DLG_BRICKLINK:
|
||||
{
|
||||
CFileDialog dlg(FALSE, "*.xml", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
|
||||
"XML Files (*.xml)|*.xml|All Files (*.*)|*.*||", AfxGetMainWnd());
|
||||
if (dlg.DoModal() == IDOK)
|
||||
{
|
||||
strcpy((char*)param, dlg.GetPathName());
|
||||
return true;
|
||||
}
|
||||
} break;
|
||||
|
||||
case LC_DLG_POVRAY:
|
||||
{
|
||||
CPOVDlg dlg;
|
||||
|
|
|
@ -592,6 +592,7 @@
|
|||
#define ID_VIEW_VIEWPOINT_LEFT 33198
|
||||
#define ID_VIEW_VIEWPOINT_RIGHT 33199
|
||||
#define ID_VIEW_VIEWPOINT_HOME 33200
|
||||
#define ID_FILE_EXPORT_BRICKLINK 33201
|
||||
#define ID_VIEW_PIECES_BAR 59425
|
||||
#define ID_VIEW_TOOLS_BAR 59426
|
||||
#define ID_VIEW_ANIMATION_BAR 59427
|
||||
|
@ -604,7 +605,7 @@
|
|||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_3D_CONTROLS 1
|
||||
#define _APS_NEXT_RESOURCE_VALUE 246
|
||||
#define _APS_NEXT_COMMAND_VALUE 33201
|
||||
#define _APS_NEXT_COMMAND_VALUE 33202
|
||||
#define _APS_NEXT_CONTROL_VALUE 1250
|
||||
#define _APS_NEXT_SYMED_VALUE 121
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue