197 lines
7.2 KiB
C++
197 lines
7.2 KiB
C++
#include "StdAfx.h"
|
|
#include "myEPlotSection.h"
|
|
#include "SLNKSymbolDefImpl.h"
|
|
#include "SLNKSymbolImpl.h"
|
|
#include "../SLNKDWFImpl/Whip2DCImpl.h"
|
|
#include <math.h>
|
|
|
|
CSLNKSymbolImpl::CSLNKSymbolImpl(void)
|
|
{
|
|
m_ColorSet = false;
|
|
}
|
|
|
|
CSLNKSymbolImpl::~CSLNKSymbolImpl(void)
|
|
{
|
|
}
|
|
|
|
CSLNKSymbolImpl::CSLNKSymbolImpl(double dwgX, double dwgY, CWhipFile *whipfile)
|
|
{
|
|
m_dwgX = dwgX;
|
|
m_dwgY = dwgY;
|
|
m_symbolName = "";
|
|
m_Rotation = 0;
|
|
m_Scale = 1.0;
|
|
m_ColorSet = false;
|
|
m_SLNKContour.m_parentWhipFile = whipfile;
|
|
m_SLNKContour.m_fromSymbol=true;
|
|
m_SLNKContour.m_outlineColor.set(0,0,0,0); // alpha=0-->transparant
|
|
}
|
|
|
|
WT_Result CSLNKSymbolImpl::serialize (WT_File & file, WT_Units & units,
|
|
CSLNKSymbolDefinition *symbdef, double hintScale,
|
|
BOOL forFind, double scale)
|
|
{
|
|
ATLASSERT(symbdef != NULL);
|
|
|
|
WT_Point3D insertion(m_dwgX, m_dwgY);
|
|
|
|
if (symbdef->m_hasBitmap)
|
|
m_Rotation = 0; // geeft problemen bij bitmaps
|
|
|
|
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 (oops: die om MAX_INT/2)
|
|
// 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
|
|
|
|
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 (%s)coordinate overflow. Possible solutions:"
|
|
"\nDecrease drawing dwf resolution (%.6f)"
|
|
"\nIncrease symbool dwf resolution (%.6f)"
|
|
"\nDecrease symbol scale (%.6f)",m_symbolName, 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));
|
|
|
|
WT_Transform SymbolTrans (lshift, dx, dy, m_Rotation);
|
|
file.heuristics().set_transform(SymbolTrans);
|
|
file.heuristics().set_apply_transform(true);
|
|
|
|
#ifdef NO_BITMAPPEREN
|
|
// Vooralsnog uitgeschakeld: we hebben de (hoognodige) achtergrondkleur niet
|
|
Merk op dat builtin symbols (star) 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
|
|
if (m_ColorSet && m_Color.rgba().m_rgb.a==0)
|
|
{
|
|
// Skip want toch onzichtbaar
|
|
}
|
|
else
|
|
symbdef->serialize(file, m_Color, m_ColorSet);
|
|
}
|
|
|
|
#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);
|
|
|
|
// 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
|
|
// Om later clientside bij draggen verschuifproblemen te voorkomen bepalen we eventueel een nieuwe
|
|
// bounding contour alsof het symbool altijd al geroteerd gedefinieerd was op zijn definitieve positie.
|
|
// Contour is ook handig voor later teksten bijplaatsen maar pas wel op dat
|
|
// de contour al getransformeerd is naar de definitieve coordinaten ruimte (anders kregen we soms bij
|
|
// geroteerde symbolen overflow problemen)
|
|
//
|
|
|
|
#undef BOUNDINGBOX_HERBEREKENEN
|
|
#ifdef BOUNDINGBOX_HERBEREKENEN
|
|
WT_Polygon pl;
|
|
symbdef->calculateBoundary(pl, &SymbolTrans);
|
|
if (pl.count()>0)
|
|
{
|
|
m_SLNKContour.set(pl.count(), pl.points(), true);
|
|
}
|
|
else // Builtin of bitmap
|
|
#endif
|
|
{
|
|
m_SLNKContour.transform(SymbolTrans); // Pas op: de bounds zijn nu misschien nog verkeerd
|
|
}
|
|
|
|
WT_Color().serialize(file); // Op de default zetten.
|
|
file.desired_rendition().color() = file.rendition().color() = WT_Color();
|
|
|
|
WT_Fill().serialize(file); // Ook op de default zetten.
|
|
file.desired_rendition().fill() = file.rendition().fill() = WT_Fill();
|
|
|
|
file.heuristics().set_apply_transform(WD_False); // Hebben we al rechtstreeks op de contour gedaan
|
|
m_SLNKContour.serialize(file, true, forFind, scale);
|
|
// Nog een keer voor een mogelijke outline
|
|
m_SLNKContour.serialize(file, false, forFind, scale);
|
|
|
|
// En transform weer terug
|
|
file.heuristics().set_transform(wasTransform);
|
|
file.heuristics().set_apply_transform(wasApplyTransform);
|
|
|
|
return result;
|
|
};
|