diff --git a/SlnkDWFCom/SLNKContour.cpp b/SlnkDWFCom/SLNKContour.cpp index 54409ec..d44b355 100644 --- a/SlnkDWFCom/SLNKContour.cpp +++ b/SlnkDWFCom/SLNKContour.cpp @@ -14,27 +14,34 @@ void CSLNKContour::SetImpl(CSLNKContourImpl * pSLNKContour) { m_SLNKContour = pSLNKContour; - if (m_SLNKContour->m_fromSymbol) return; // Die zijn vast nog niet getransformeerd + m_doneBounds = false; +} - WT_Logical_Box bx = pSLNKContour->bounds(); +void CSLNKContour::calculateBounds() +{ + if (m_doneBounds) + return; + m_doneBounds = true; + + WT_Logical_Box bx = m_SLNKContour->bounds(); // Als je hierna nog punten toevoegt heb je een probleem WT_Point3D dwgPt; CComQIPtr pt; - dwgPt = pSLNKContour->m_parentWhipFile->m_contunits.transform(bx.minpt()); + dwgPt = m_SLNKContour->m_parentWhipFile->m_contunits.transform(bx.minpt()); m_dwgBounding->get_min(&pt); pt->put_DwgX(dwgPt.m_x); pt->put_DwgY(dwgPt.m_y); pt.Release(); - dwgPt = pSLNKContour->m_parentWhipFile->m_contunits.transform(bx.maxpt()); + dwgPt = m_SLNKContour->m_parentWhipFile->m_contunits.transform(bx.maxpt()); m_dwgBounding->get_max(&pt); pt->put_DwgX(dwgPt.m_x); pt->put_DwgY(dwgPt.m_y); pt.Release(); - WT_Logical_Point lp = CSLNKContourImpl::Centroid(*pSLNKContour); - dwgPt = pSLNKContour->m_parentWhipFile->m_contunits.transform(lp); + WT_Logical_Point lp = CSLNKContourImpl::Centroid(*m_SLNKContour); + dwgPt = m_SLNKContour->m_parentWhipFile->m_contunits.transform(lp); m_dwgCenter->put_DwgX(dwgPt.m_x); m_dwgCenter->put_DwgY(dwgPt.m_y); }; @@ -98,6 +105,7 @@ STDMETHODIMP CSLNKContour::get_Extents(IBoundingBox** pVal) if (m_SLNKContour->m_fromSymbol) return E_NOTIMPL; // (nog) niet op symbolen + calculateBounds(); return m_dwgBounding->QueryInterface(IID_IBoundingBox, (void**)pVal); } @@ -105,6 +113,8 @@ STDMETHODIMP CSLNKContour::get_Center(IDWGPoint** pVal) { if (m_SLNKContour->m_fromSymbol) return E_NOTIMPL; // (nog) niet op symbolen + + calculateBounds(); return m_dwgCenter->QueryInterface(IID_IDWGPoint, (void**)pVal); } diff --git a/SlnkDWFCom/SLNKContour.h b/SlnkDWFCom/SLNKContour.h index ff6eff3..f73efb7 100644 --- a/SlnkDWFCom/SLNKContour.h +++ b/SlnkDWFCom/SLNKContour.h @@ -79,9 +79,11 @@ END_COM_MAP() HRESULT hr = pParent->QueryInterface(IID_IWhipFile, (void **)&m_parent_iWhipFile); }; void SetImpl(CSLNKContourImpl * pSLNKContour); + void calculateBounds(); private: CSLNKContourImpl * m_SLNKContour; + bool m_doneBounds; // zijn de volgende twee bepaald? CComQIPtr m_dwgCenter; CComQIPtr m_dwgBounding; CComQIPtr m_parent_iWhipFile; // Om scope levend te houden diff --git a/SlnkDWFImpl/SLNKContourImpl.cpp b/SlnkDWFImpl/SLNKContourImpl.cpp index 896e47b..4017d92 100644 --- a/SlnkDWFImpl/SLNKContourImpl.cpp +++ b/SlnkDWFImpl/SLNKContourImpl.cpp @@ -325,7 +325,7 @@ WT_Logical_Point CSLNKContourImpl::LabelPosition(LABELPOS pos /*= LABEL_DEFAULT* return WT_Logical_Point((WT_Integer32)(ptx / dDWFArea6), (WT_Integer32)(pty / dDWFArea6)); } -void CSLNKContourImpl::SerializeLabel(WT_File &my_file, +void CSLNKContourImpl::SerializeLabel(WT_File &my_file, double scale, HDC myDC) { @@ -682,6 +682,12 @@ WT_Result CSLNKContourImpl::serialize(WT_File & file, BOOL solidOnly, BOOL forFi file.desired_rendition().line_weight() = myRound(m_Lineweight * scale); // Fraaier bij lijndikte aan begin/eind file.desired_rendition().line_style().line_end_cap() = WT_Line_Style::Round_Cap; + + // Als eerste punt ongelijk aan laatste punt dan points() eentje uitbreiden + // De polygon sluit vanzelf wel maar deze polyline niet + if (count() > 2 && (points()[0].m_x != points()[count()-1].m_x || points()[0].m_y != points()[count()-1].m_y)) + AddPoint(points()[0]); + WT_Polyline my_line( count(), points(), WD_False); my_line.serialize(file); } @@ -691,8 +697,15 @@ WT_Result CSLNKContourImpl::serialize(WT_File & file, BOOL solidOnly, BOOL forFi void CSLNKContourImpl::AddPoint(double pValX, double pValY, WT_Units units) { - bool wasEmpty = (points()[0].m_x == INT_MAX && + AddPoint(units.transform(WT_Point3D(pValX, pValY))); +} + +void CSLNKContourImpl::AddPoint(WT_Logical_Point pt) +{ + bool wasEmpty = (points()[0].m_x == INT_MAX && points()[0].m_y == INT_MAX); + + // TODO: Overflow controle? WT_Logical_Point *pts = new WT_Logical_Point[count()+1]; int i; for (i = 0; i < count(); i++) @@ -700,8 +713,8 @@ void CSLNKContourImpl::AddPoint(double pValX, double pValY, WT_Units units) pts[i] = points()[i]; } // Het nieuwe punt - pts[i] = units.transform(WT_Point3D(pValX, pValY)); - + pts[i] = pt; + // Bij wasEmpty het eerste dummy punt overslaan set(wasEmpty?1:(count() + 1), &pts[wasEmpty?1:0], true); @@ -710,5 +723,4 @@ void CSLNKContourImpl::AddPoint(double pValX, double pValY, WT_Units units) m_ptLabel = points()[0]; delete[] pts; - } \ No newline at end of file diff --git a/SlnkDWFImpl/SLNKContourImpl.h b/SlnkDWFImpl/SLNKContourImpl.h index 20c2337..6d8365e 100644 --- a/SlnkDWFImpl/SLNKContourImpl.h +++ b/SlnkDWFImpl/SLNKContourImpl.h @@ -67,5 +67,6 @@ public: double scale, HDC myDC, int width=-2); void AddPoint(double pValX, double pValY, WT_Units units); + void AddPoint(WT_Logical_Point pt); static WT_Integer32 m_next_node_num; };