234 lines
9.1 KiB
C++
234 lines
9.1 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;
|
|
m_Lineweight = -1;
|
|
}
|
|
|
|
CSLNKSymbolImpl::~CSLNKSymbolImpl(void)
|
|
{
|
|
}
|
|
|
|
CSLNKSymbolImpl::CSLNKSymbolImpl(double dwgX, double dwgY, WT_Units units)
|
|
{
|
|
m_dwgX = dwgX;
|
|
m_dwgY = dwgY;
|
|
m_symbolName = "";
|
|
m_Rotation = 0;
|
|
m_Scale = 1.0;
|
|
m_ColorSet = false;
|
|
m_Lineweight = -1;
|
|
m_SLNKContour.m_Units = units;
|
|
m_SLNKContour.m_fromSymbol=true;
|
|
m_SLNKContour.m_outlineColor.set(0,0,0,0); // alpha=0-->transparant
|
|
m_SLNKContour.m_Labelpos = CSLNKContourImpl::LABEL_OUTSIDEBOTTOM; // default voor symbolen
|
|
}
|
|
|
|
WT_Result CSLNKSymbolImpl::serialize (WT_File & file, WT_Units & units,
|
|
CSLNKSymbolDefinition *symbdef,
|
|
WT_Integer32 &node_num,
|
|
double hintScale,
|
|
BOOL forFind, double scale)
|
|
{
|
|
ATLASSERT(symbdef != NULL);
|
|
|
|
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();
|
|
|
|
WT_Font default_font;
|
|
if (!this->m_unicode.length())
|
|
{
|
|
default_font.width_scale() = 0; // Triggert FONT_WIDTH_SCALE_BIT bitje zetten
|
|
default_font.rotation() = 0;
|
|
default_font.height() = 0;
|
|
default_font.flags() = 0;
|
|
default_font.serialize(file); // Op de default zetten.
|
|
file.desired_rendition().font() = file.rendition().font() = default_font;
|
|
}
|
|
|
|
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;
|
|
}
|
|
m_SLNKContour.m_ptLabel = LPInsertion;
|
|
// 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, key: %s, label: %s) coordinate overflow. Possible solutions:"
|
|
"\nDecrease drawing dwf resolution (%.6f)"
|
|
"\nIncrease symbool dwf resolution (%.6f)"
|
|
"\nDecrease symbol scale (%.6f)",m_symbolName, m_SLNKContour.m_Key, m_SLNKContour.m_ShowLabel,
|
|
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);
|
|
|
|
if (m_ColorSet && m_Color.rgba().m_rgb.a==0)
|
|
{
|
|
// Skip want toch onzichtbaar
|
|
}
|
|
else if (this->m_unicode.length())
|
|
{
|
|
if (m_ColorSet)
|
|
m_Color.serialize(file);
|
|
|
|
// Het roteren en verschalen gebeurt via WT_Transform SymbolTrans
|
|
// Een gewijzigde rotatie of schaal maakt dat we een (Font) moeten wegschrijven naar de DWF
|
|
// De toolkit snapt echter niet goed dat het nodig is bij gewijzigde Transform, daarom hieronder expliciet
|
|
file.desired_rendition().font().height() = 1000; // Zorg dat FONT_HEIGHT_BIT gezet raakt
|
|
file.desired_rendition().font().rotation() = 0; // Zorg dat FONT_ROTATION_BIT gezet raakt
|
|
file.desired_rendition().font().serialize(file);
|
|
|
|
//https://stackoverflow.com/questions/32781414/what-is-the-baseline-font-height-of-fontawesome-font
|
|
// Waarom moet ik hier 125 gebruiken? Omdat dat in de svg descent (64) / units-per-em (512) is!
|
|
WT_Text my_text(WT_Logical_Point(0, 125), this->m_unicode);
|
|
// het font is in CWhipFile::GenerateSymbols al goed gezet
|
|
my_text.serialize(file);
|
|
}
|
|
else
|
|
symbdef->serialize(file, m_Color, m_ColorSet, myRound(m_Lineweight * scale));
|
|
|
|
#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
|
|
{
|
|
//(((double)m_x * trans.m_x_scale) + trans.m_translate.m_x)
|
|
// Het insertionpoint was misschien wel goed maar test ook de eerste
|
|
// x-coordinaat van de bounding countour. Die gaf ook wel eens overflow
|
|
// Met rotation rekening houden maakt de expressie complexer
|
|
// if (m_Rotation == 0 && dx * m_SLNKContour.points()[1].m_x + lshift.m_x > INT_MAX)
|
|
if (dx * m_SLNKContour.points()[1].m_x + lshift.m_x > INT_MAX)
|
|
{
|
|
throw myCString("\nSLNKDWF symbol (%s, key: %s, label: %s) coordinate overflow. Possible solutions:"
|
|
"\nDecrease drawing dwf resolution (%.6f)"
|
|
"\nIncrease symbool dwf resolution (%.6f)"
|
|
"\nDecrease symbol scale (%.6f)",m_symbolName, m_SLNKContour.m_Key, m_SLNKContour.m_ShowLabel,
|
|
dScale, symbdef->m_dwgScale, m_Scale
|
|
);
|
|
}
|
|
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();
|
|
|
|
if (!this->m_unicode.length())
|
|
{
|
|
default_font.serialize(file); // Ook op de default zetten.
|
|
file.desired_rendition().font() = file.rendition().font() = default_font;
|
|
}
|
|
|
|
file.heuristics().set_apply_transform(WD_False); // Hebben we al rechtstreeks op de contour gedaan
|
|
m_SLNKContour.serialize(file, node_num, true, forFind, scale);
|
|
// Nog een keer voor een mogelijke outline
|
|
m_SLNKContour.serialize(file, node_num, false, forFind, scale);
|
|
|
|
// En transform weer terug
|
|
file.heuristics().set_transform(wasTransform);
|
|
file.heuristics().set_apply_transform(wasApplyTransform);
|
|
|
|
return result;
|
|
};
|