// $Revision: 1.4 $ // Copyright (C) 1994, 1995 Taligent, Inc. All rights reserved. #ifndef TaligentSamples_MARKDRAWER #include "MarkDrawer.h" #endif #ifndef TaligentSamples_STANDARDGRAPH #include "StandardGraph.h" #endif //============================================================================== // TMarkDrawer TaligentTypeExtensionMacro_Abstract(TMarkDrawer); TMarkDrawer::TMarkDrawer() : TGraphDrawer(), fMarkColor(*TColorPaint::GetBlack().GetColor()), fMarkLength(0.), fMarkInterval(1) { } TMarkDrawer::TMarkDrawer(GraphValue markLength, GraphValue markInterval, const TPaint& markColor) : TGraphDrawer(), fMarkColor(*markColor.GetColor()), fMarkLength(markLength), fMarkInterval(markInterval) { } TMarkDrawer::TMarkDrawer(const TMarkDrawer& source) : TGraphDrawer(source), fMarkColor(source.fMarkColor), fMarkLength(source.fMarkLength), fMarkInterval(source.fMarkInterval) { } TMarkDrawer::~TMarkDrawer() { } TMarkDrawer& TMarkDrawer::operator=(const TMarkDrawer& source) { if (&source != this) { TGraphDrawer::operator=(source); fMarkColor = source.fMarkColor; fMarkLength = source.fMarkLength; fMarkInterval = source.fMarkInterval; } return *this; } TStream& TMarkDrawer::operator>>=(TStream& toStream) const { ::WriteVersion(toStream, kOriginalVersion); TGraphDrawer::operator>>=(toStream); fMarkColor >>= toStream; fMarkLength >>= toStream; fMarkInterval >>= toStream; return toStream; } TStream& TMarkDrawer::operator<<=(TStream& fromStream) { ::ReadVersion(fromStream, kOriginalVersion, kOriginalVersion); TGraphDrawer::operator<<=(fromStream); fMarkColor <<= fromStream; fMarkLength <<= fromStream; fMarkInterval <<= fromStream; return fromStream; } const TRGBColor& TMarkDrawer::GetMarkColor() const { return fMarkColor; } GraphValue TMarkDrawer::GetMarkLength() const { return fMarkLength; } GraphValue TMarkDrawer::GetMarkInterval() const { return fMarkInterval; } void TMarkDrawer::SetMarkColor(const TRGBColor& color) { fMarkColor = color; } void TMarkDrawer::SetMarkLength(GraphValue length) { fMarkLength = length; } void TMarkDrawer::SetMarkInterval(GraphValue interval) { fMarkInterval = interval; } //============================================================================== // TXMarkDrawer TaligentTypeExtensionMacro(TXMarkDrawer); TXMarkDrawer::TXMarkDrawer() : TMarkDrawer() { } TXMarkDrawer::TXMarkDrawer(GraphValue markLength, GraphValue markInterval) : TMarkDrawer(markLength, markInterval) { } TXMarkDrawer::TXMarkDrawer(const TXMarkDrawer& source) : TMarkDrawer(source) { } TXMarkDrawer::~TXMarkDrawer() { } TXMarkDrawer& TXMarkDrawer::operator=(const TXMarkDrawer& source) { if (&source != this) { TMarkDrawer::operator=(source); } return *this; } TStream& TXMarkDrawer::operator>>=(TStream& toStream) const { ::WriteVersion(toStream, kOriginalVersion); TMarkDrawer::operator>>=(toStream); return toStream; } TStream& TXMarkDrawer::operator<<=(TStream& fromStream) { ::ReadVersion(fromStream, kOriginalVersion, kOriginalVersion); TMarkDrawer::operator<<=(fromStream); return fromStream; } void TXMarkDrawer::DrawIntoGraph(TGrafPort& port) const { TLine mark(TGLine(), new TGrafBundle(GetMarkColor())); const TStandardGraph& graph = GetTargetGraph(); GraphValue interval = GetMarkInterval(); GraphValue xValue = graph.GetXRange().GetMin(); TGPoint startPoint; unsigned long numberOfMarks = (graph.GetXRange().GetLength() / GetMarkInterval()) + 1; for (unsigned long markIndex = 0; markIndex < numberOfMarks; ++markIndex) { startPoint = graph.MapValuesToPoint(xValue, graph.GetYRange().GetMin()); mark.SetStartPoint(startPoint); mark.SetEndPoint(TGPoint(startPoint.fX, startPoint.fY + GetMarkLength())); mark.Draw(port); xValue += interval; } } TGRect TXMarkDrawer::GetBounds() const { TGRect totalBounds; const TStandardGraph& graph = GetTargetGraph(); GraphValue numberOfMarks = graph.GetXRange().GetLength() / GetMarkInterval(); GraphValue lastMark = numberOfMarks * GetMarkInterval(); GraphValue xValue = graph.GetXRange().GetMin(); GraphValue yValue = graph.GetYRange().GetMin(); totalBounds.SetTopLeft(graph.MapValuesToPoint(xValue, yValue)); TGPoint point = graph.MapValuesToPoint(graph.GetXRange().GetMin() + lastMark, graph.GetYRange().GetMin()); point.fY += GetMarkLength(); totalBounds.SetBottomRight(point); return totalBounds; } //============================================================================== // TYMarkDrawer TaligentTypeExtensionMacro(TYMarkDrawer); TYMarkDrawer::TYMarkDrawer() : TMarkDrawer() { } TYMarkDrawer::TYMarkDrawer(GraphValue markLength, GraphValue markInterval) : TMarkDrawer(markLength, markInterval) { } TYMarkDrawer::TYMarkDrawer(const TYMarkDrawer& source) : TMarkDrawer(source) { } TYMarkDrawer::~TYMarkDrawer() { } TYMarkDrawer& TYMarkDrawer::operator=(const TYMarkDrawer& source) { if (&source != this) { TMarkDrawer::operator=(source); } return *this; } TStream& TYMarkDrawer::operator>>=(TStream& toStream) const { ::WriteVersion(toStream, kOriginalVersion); TMarkDrawer::operator>>=(toStream); return toStream; } TStream& TYMarkDrawer::operator<<=(TStream& fromStream) { ::ReadVersion(fromStream, kOriginalVersion, kOriginalVersion); TMarkDrawer::operator<<=(fromStream); return fromStream; } void TYMarkDrawer::DrawIntoGraph(TGrafPort& port) const { TLine mark(TGLine(), new TGrafBundle(GetMarkColor())); const TStandardGraph& graph = GetTargetGraph(); GraphValue yValue = graph.GetYRange().GetMin(); GraphValue xAxis = graph.GetXRange().GetMin(); TGPoint startPoint; unsigned long numberOfMarks = (graph.GetYRange().GetLength() / GetMarkInterval()) + 1; for (unsigned long markIndex = 0; markIndex < numberOfMarks; ++markIndex) { startPoint = graph.MapValuesToPoint(graph.GetXRange().GetMin(), yValue); mark.SetStartPoint(startPoint); mark.SetEndPoint(TGPoint(startPoint.fX - GetMarkLength(), startPoint.fY)); mark.Draw(port); yValue += GetMarkInterval(); } } TGRect TYMarkDrawer::GetBounds() const { TGRect totalBounds; const TStandardGraph& graph = GetTargetGraph(); GraphValue numberOfMarks = graph.GetYRange().GetLength() / GetMarkInterval(); GraphValue lastMark = numberOfMarks * GetMarkInterval(); TGPoint point = graph.MapValuesToPoint(graph.GetXRange().GetMin(), graph.GetYRange().GetMin() + lastMark); point.fX -= GetMarkLength(); totalBounds.SetTopLeft(point); GraphValue xValue = graph.GetXRange().GetMin(); GraphValue yValue = graph.GetYRange().GetMin(); totalBounds.SetBottomRight(graph.MapValuesToPoint(xValue, yValue)); return totalBounds; }