189 lines
7.3 KiB
C++
189 lines
7.3 KiB
C++
#include "StdAfx.h"
|
|
#include "myEPlotSection.h"
|
|
#include "SLNKSymbolDefImpl.h"
|
|
#include "SLNKSymbolImpl.h"
|
|
#include "../SLNKDWFImpl/CxImage\CxImage\ximage.h"
|
|
#include "../SLNKDWFImpl/Whip2DCImpl.h"
|
|
#include <math.h>
|
|
|
|
CSLNKSymbolImpl::CSLNKSymbolImpl(void)
|
|
{
|
|
}
|
|
|
|
CSLNKSymbolImpl::~CSLNKSymbolImpl(void)
|
|
{
|
|
}
|
|
|
|
CSLNKSymbolImpl::CSLNKSymbolImpl(double dwgX, double dwgY, CWhipFileState *State)
|
|
{
|
|
m_dwgX = dwgX;
|
|
m_dwgY = dwgY;
|
|
m_symbolName = "";
|
|
m_Rotation = 0;
|
|
m_Scale = 1.0;
|
|
m_SLNKContour.m_parentWhipFileState = State;
|
|
m_SLNKContour.m_fromSymbol=true;
|
|
}
|
|
|
|
WT_Result CSLNKSymbolImpl::serialize (WT_File & file, WT_Units & units,
|
|
CSLNKSymbolDefinition *symbdef, double hintScale)
|
|
{
|
|
ATLASSERT(symbdef != NULL);
|
|
|
|
WT_Point3D insertion(m_dwgX, m_dwgY);
|
|
//m_SLNKContour.m_parentWhipFileState->m_contunits
|
|
|
|
double dScale = units.application_to_dwf_transform()(0,0); // Drawing's dScale
|
|
|
|
WT_Transform wasTransform = file.heuristics().transform();
|
|
WT_Boolean wasApplyTransform = file.heuristics().apply_transform();
|
|
|
|
WT_Logical_Point LPInsertion = units.transform(insertion);
|
|
// Onze file had mogelijk al een transform staan. Die moeten we wel blijven ondersteunen
|
|
// (terugzetten komt wel)
|
|
if (wasApplyTransform)
|
|
{
|
|
LPInsertion *= wasTransform;
|
|
}
|
|
// WT_Transform ondersteunt wel rotaties 0,90,180 en 270. Dat gaat echter altijd om DWF 0,0
|
|
// terwijl wij toch echt om ons insertionpoint willen.
|
|
// Het (b)lijkt oplosbaar door ons punt te tegenroteren
|
|
WT_Transform tr0;
|
|
tr0.set_rotation((360-m_Rotation)%360);
|
|
LPInsertion *= tr0;
|
|
|
|
WT_Result result;
|
|
|
|
#ifdef _xDEBUG
|
|
{ // Cirkel onder het symbool tekenen
|
|
WT_Logical_Point center = units.transform(insertion);
|
|
// Binnenkant cirkel
|
|
file.desired_rendition().color() = WT_Color(128, 128, 128, 0); // doorzichtig werkt (nog) niet voor ellipsen
|
|
WT_Filled_Ellipse(center, 1500, 1500).serialize(file);
|
|
// Buitenkant cirkel
|
|
file.desired_rendition().color() = WT_Color(0, 255, 0, 0); // doorzichtig werkt (nog) niet voor ellipsen
|
|
file.desired_rendition().line_weight() = WT_Line_Weight(100);
|
|
WT_Outline_Ellipse(center, 1500, 1500).serialize(file);
|
|
file.desired_rendition().line_weight() = WT_Line_Weight(0);
|
|
}
|
|
#endif
|
|
#ifdef _DEBUG
|
|
{ // klein cirkeltje op insertion
|
|
WT_Logical_Point center = units.transform(insertion);
|
|
// Binnenkant cirkel
|
|
file.desired_rendition().color() = WT_Color(0, 0, 128, 0); // doorzichtig werkt (nog) niet voor ellipsen
|
|
WT_Filled_Ellipse(center, 50, 50).serialize(file);
|
|
// Buitenkant cirkel
|
|
file.desired_rendition().color() = WT_Color(0, 128, 0, 0); // doorzichtig werkt (nog) niet voor ellipsen
|
|
file.desired_rendition().line_weight() = WT_Line_Weight(10);
|
|
WT_Outline_Ellipse(center, 50, 50).serialize(file);
|
|
file.desired_rendition().line_weight() = WT_Line_Weight(0);
|
|
}
|
|
#endif
|
|
// Vertrouw de huidige rendition niet! Het eerste lijntje van een symbool kan default wit verwachten (CO206.DWF)
|
|
// Tijdens het serializen van het symbool hebben we niets met (desired)_rendition te maken
|
|
WT_Color().serialize(file); // Op de default zetten. TODO: Moet eigenlijk voor alle attributen
|
|
|
|
double dx, dy;
|
|
|
|
dx = dy = m_Scale * dScale / symbdef->m_dwgScale;
|
|
// PAS OP: (SDU tekening) je kunt hier in overflow problemen komen
|
|
// als dx*symbdef->m_Origin.m_x>MAXINT ofwel eigenlijk al als dx>1.0
|
|
// ofwel als d(rawing)Scale > symbdef->m_dwgScale (en dan heb ik het nog
|
|
// niet over verschaalde symbolen).
|
|
if (dx*symbdef->m_Origin.m_x > INT_MAX || dy*symbdef->m_Origin.m_y > INT_MAX)
|
|
{
|
|
throw myCString("\nSLNKDWF symbol coordinate overflow. Possible solutions:"
|
|
"\nDecrease drawing dwf resolution (%.6f)"
|
|
"\nIncrease symbool dwf resolution (%.6f)"
|
|
"\nDecrease symbol scale (%.6f)",dScale, symbdef->m_dwgScale, m_Scale
|
|
);
|
|
}
|
|
//myDoTRACE("\nSymbool m_Scale = %.6f, dScale = %.6f, symbdef->m_dwgScale = %.6f==>dx=%.6g", m_Scale, dScale, symbdef->m_dwgScale, dx);
|
|
// WT_Logical_Point lshift(LPInsertion);
|
|
|
|
WT_Logical_Point lshift(LPInsertion.m_x - myRound(dx*symbdef->m_Origin.m_x),
|
|
LPInsertion.m_y - myRound(dy*symbdef->m_Origin.m_y));
|
|
|
|
file.heuristics().set_transform(WT_Transform (lshift, dx, dy, m_Rotation));
|
|
file.heuristics().set_apply_transform(true);
|
|
|
|
#ifdef NO_BITMAPPEREN
|
|
// Vooralsnog uitgeschakeld: we hebben de (hoognodige) achtergrondkleur niet
|
|
Merk op dat builtin symbols (star) geen nog geen boundingbox ingevuld hebben
|
|
int pixeldx = 1000;
|
|
int pixeldy = 1000;
|
|
if (hintScale>0)
|
|
{
|
|
WT_Logical_Box bx = symbdef->m_BoundingBox;
|
|
pixeldx = myRound((bx.maxpt().m_x - bx.minpt().m_x)*m_Scale/symbdef->m_dwgScale/hintScale);
|
|
pixeldy = myRound((bx.maxpt().m_y - bx.minpt().m_y)*m_Scale/symbdef->m_dwgScale/hintScale);
|
|
//myDoTRACE("\nbx=(%d,%d)-(%d,%d)",bx.minpt().m_x,bx.minpt().m_y,bx.maxpt().m_x,bx.maxpt().m_y);
|
|
//myDoTRACE(" makes (%d,%d) pixels",pixeldx,pixeldy);
|
|
}
|
|
if ( 0 && pixeldx < 100 && pixeldy < 100 ) // Heel weinig pixels
|
|
{ // Bitmap versie van het symbool gebruiken
|
|
//double rescale = 1.0; //m_Scale/symbdef->m_dwgScale*dScale;
|
|
if (pixeldx > 0 && pixeldy > 0)
|
|
{
|
|
symbdef->asBitmap(pixeldx, pixeldy, 0xffffff)->serialize(file);
|
|
}
|
|
}
|
|
else
|
|
#endif
|
|
{ //Gewone vector versie
|
|
symbdef->serialize(file);
|
|
}
|
|
|
|
#ifdef _DEBUG
|
|
WT_Comments cmt;
|
|
CString s; s.Format("About to insert symbol contour %s", m_symbolName);
|
|
cmt.set(s);
|
|
cmt.serialize(file);
|
|
#endif
|
|
|
|
//Cirkeltje op symbool zwaartepunt
|
|
//file.desired_rendition().color() = WT_Color(255, 0, 0, 0);
|
|
//WT_Filled_Ellipse(symbdef->m_Center, 50, 50).serialize(file);
|
|
|
|
#ifdef _DEBUG
|
|
m_SLNKContour.m_outlineAlpha = 255; // Zichtbaar maken
|
|
#else
|
|
m_SLNKContour.m_outlineAlpha = 0; // Onzichtbaar maken
|
|
#endif
|
|
// En vervolgens nog een mooi bounding contourtje er om heen.
|
|
// Die is essentieel voor het aanwijzen. Doordat hierboven de alpha op 0 is gezet wordt hij wel transparant
|
|
WT_Color().serialize(file); // Op de default zetten.
|
|
file.desired_rendition().color() = file.rendition().color() = WT_Color();
|
|
m_SLNKContour.serialize(file, true);
|
|
|
|
// Nu contour aanpassen. Is handig voor later teksten bijplaatsen
|
|
// Echter: die willen we exclusief 'wasTranform' hebben. Daarvoor tegencorrigeren we
|
|
//
|
|
LPInsertion = units.transform(insertion);
|
|
WT_Transform tr1;
|
|
tr1.set_rotation((360-m_Rotation)%360);
|
|
LPInsertion *= tr1;
|
|
lshift = WT_Logical_Point(LPInsertion.m_x - myRound(dx*symbdef->m_Origin.m_x),
|
|
LPInsertion.m_y - myRound(dy*symbdef->m_Origin.m_y));
|
|
WT_Transform tm(lshift, dx, dy, m_Rotation);
|
|
m_SLNKContour.transform(tm); // Pas op: de bounds zijn nu misschien nog verkeerd
|
|
#if 0
|
|
// Tegencorrectie werkte niet goed met rotatie. Daarom maar zoals hierboven
|
|
WT_Transform tm(file.heuristics().transform());
|
|
WT_Logical_Point wasT(wasTransform.m_translate);
|
|
WT_Transform tr1;
|
|
tr1.set_rotation((360-m_Rotation)%360);
|
|
wasT *= tr1;
|
|
tm.m_translate.m_x -= wasT.m_x;
|
|
tm.m_translate.m_y -= wasT.m_y;
|
|
m_SLNKContour.transform(tm); // Pas op: de bounds zijn nu misschien nog verkeerd
|
|
#endif
|
|
|
|
// En transform weer terug
|
|
file.heuristics().set_transform(wasTransform);
|
|
file.heuristics().set_apply_transform(wasApplyTransform);
|
|
// ASSERT: Deze werkt nu ook m_SLNKContour.serialize(file, true, true);
|
|
return result;
|
|
};
|