layerdc.h

Go to the documentation of this file.
00001 /**
00002  * \file layerdc.h <gre/layerdc.h>
00003  * \brief GRE_LAYERDC class definition
00004  *
00005  * \if NODOC
00006  * $Id: layerdc.h_v 1.31 2005/05/03 15:02:25 mju Exp $
00007  *
00008  * $Log: layerdc.h_v $
00009  * Revision 1.31  2005/05/03 15:02:25  mju
00010  * Keep track of render target.
00011  * Add checkColorLock using elemtype/num and highlightset.
00012  *
00013  * Revision 1.30  2005/05/02 20:40:08  mju
00014  * Add checkColorOverride.
00015  *
00016  * Revision 1.29  2005/05/02 17:44:06  mju
00017  * Add checkColorLock.
00018  *
00019  * Revision 1.28  2005/03/01 14:21:15  mju
00020  * Add methods to access drawn sets.
00021  *
00022  * Revision 1.27  2005/02/25 20:31:31  mju
00023  * Include groupview hdr.
00024  *
00025  * Revision 1.26  2005/02/25 18:54:37  mju
00026  * Include layerview hdr.
00027  *
00028  * Revision 1.25  2005/02/25 17:47:27  mju
00029  * Remove setup2D/3D, add CanDrawLayer, Set3dStereoView.
00030  *
00031  * Revision 1.24  2005/02/24 20:38:57  mju
00032  * Remove commented-out method.
00033  *
00034  * Revision 1.23  2005/02/24 18:52:39  mju
00035  * Remove getBackgroundColor.
00036  * Make setDrawFlags non-inline.
00037  *
00038  * Revision 1.22  2005/02/23 18:53:08  mju
00039  * Add non-const getLayerView method.
00040  *
00041  * Revision 1.21  2005/02/23 16:56:08  mju
00042  * Add non-const variant of getLayerView.
00043  *
00044  * Revision 1.20  2005/02/14 18:53:11  mju
00045  * Use groupview.
00046  *
00047  * Revision 1.19  2005/02/04 18:57:35  mju
00048  * Add ctors using mgd device.
00049  * Add setDrawingDevice.
00050  * Deprecate ctors using mgd context.
00051  *
00052  * Revision 1.18  2005/01/27 21:42:47  mju
00053  * Undeprecate ctor.
00054  *
00055  * Revision 1.17  2005/01/24 21:37:24  mju
00056  * Add non-const get3dScene.
00057  *
00058  * Revision 1.16  2005/01/24 21:31:36  mju
00059  * Move members which can be saved between drawing to layerview.
00060  *
00061  * Revision 1.14  2005/01/21 17:30:29  mju
00062  * Make all members private.
00063  *
00064  * Revision 1.13  2005/01/20 22:47:31  mju
00065  * Add accessor methods.
00066  *
00067  * Revision 1.12  2005/01/20 16:55:43  mju
00068  * Enums for drawmode.
00069  *
00070  * Revision 1.11  2004/03/12 16:07:19  mju
00071  * Add isHidden fn.
00072  *
00073  * Revision 1.10  2004/03/05 17:01:57  mju
00074  * Make dtor virtual since has virtual fns.
00075  *
00076  * Revision 1.9  2003/10/06 20:47:23  mju
00077  * Add NotifyDrawElementBegin/End.
00078  *
00079  * Revision 1.8  2003/09/15 13:48:59  fileserver!dwilliss
00080  * Doxygen
00081  *
00082  * Revision 1.7  2003/09/10 17:03:44  scowan
00083  * Create no trans draw line clipped function.
00084  *
00085  * Revision 1.6  2003/07/31 22:09:43  mju
00086  * Ignore private section.
00087  *
00088  * Revision 1.5  2003/06/14 02:11:02  scowan
00089  * Removed dregion and changed to region2d.
00090  *
00091  * Revision 1.4  2003/06/04 23:13:54  scowan
00092  * Added methods and removed simple array.
00093  *
00094  * Revision 1.3  2003/03/20 23:14:49  vdronov
00095  * new trans
00096  *
00097  * Revision 1.2  2003/03/05 20:41:32  mju
00098  * Add GetTransLayerToDevice
00099  *
00100  * Revision 1.1  2002/09/19 17:08:41  mju
00101  * Initial revision
00102  *
00103  * \endif
00104 **/
00105 
00106 #ifndef  INC_GRE_LAYERDC_H
00107 #define  INC_GRE_LAYERDC_H
00108 
00109 #ifndef  INC_GRE_VIEW_H
00110    #include <gre/view.h>
00111 #endif
00112 
00113 #ifndef  INC_GRE_GROUP_H
00114    #include <gre/group.h>
00115 #endif
00116 
00117 #ifndef  INC_GRE_LAYERVIEW_H
00118    #include <gre/layerview.h>
00119 #endif
00120 
00121 #ifndef  INC_GRE_GROUPVIEW_H
00122    #include <gre/groupview.h>
00123 #endif
00124 
00125 #ifndef  INC_GRE_LRSURFACE_H
00126    #include <gre/lrsurface.h>
00127 #endif
00128 
00129 #ifndef  INC_MI32_REGION2D_H
00130    #include <mi32/region2d.h>
00131 #endif
00132 
00133 #ifndef  INC_MI32_SML_H
00134    #include <mi32/sml.h>
00135 #endif
00136 
00137 
00138 //===================================================================================================================
00139 //! Layer drawing context.
00140 //! Contains information needed to actually draw layer on a particular view.
00141 class GRE_LAYERDC : public POLYLINE::CLIP {
00142    public:
00143 
00144       //! Construct using layer, view and drawing device.
00145       GRE_LAYERDC (
00146          GRE_LAYER *layer,                   //!< Layer, must not be NULL
00147          GRE_VIEW *view,                     //!< View, should not be NULL
00148          MGD::DEVICE* pDevice = 0,
00149          GRE::DRAWFLAGS drawflags = GRE::DRAWFLAG_None
00150          );
00151 
00152       //! Construct using view, drawing device and transformation.
00153       //! Does not need a layer, but you need to calculate the transformation and pass it in.
00154       GRE_LAYERDC (
00155          GRE_VIEW *view,                     //!< View, cannot be NULL
00156          MGD::DEVICE* pDevice,               //!< Drawing device, cannot be NULL
00157          const TRANS2D_MAPGEN& ObjectToDevice,
00158          GRE::DRAWFLAGS drawflags = GRE::DRAWFLAG_None
00159          );
00160 
00161       //! Destructor.
00162       virtual ~GRE_LAYERDC ();
00163 
00164       //! Determine if possible to draw layer.
00165       //! @return false if out of view or cannot draw based on 2D/3D view type.
00166       bool CanDrawLayer (
00167          ) const;
00168 
00169       //! Check if drawing flags require a color lock, set color and lock if so.
00170       bool CheckColorLock (
00171          MGD::COLORLOCK& colorlock           //!< Color lock passed/returned
00172          );
00173 
00174       //! Check if drawing flags require a color lock, set color and lock if so.
00175       bool CheckColorLock (
00176          MGD::COLORLOCK& colorlock,          //!< Color lock passed/returned
00177          ELEMTYPE ElemType,                  //!< Element type
00178          INT32 ElemNum,                      //!< Element number
00179          const BITSET& HighlightSet          //!< Highlight set
00180          );
00181 
00182       //! Check if drawing flags require a color override.
00183       bool CheckColorOverride (
00184          COLOR& color                        //!< Override color returned
00185          );
00186 
00187       void ClearAllDrawnSets (
00188          );
00189 
00190       //! Draw line in 2D, does not translate or clip
00191       //! @return TRUE if visible, FALSE if not, < 0 if error.
00192       ERRVALUE DrawLine2D (
00193          POLYLINE& PolyLine
00194          ) { return (OnClip(PolyLine)); }
00195 
00196       //! Translate, clip and draw line in 2D
00197       //! @return TRUE if visible, FALSE if not, < 0 if error.
00198       int DrawLineClipped2D (
00199          POLYLINE& PolyLine
00200          ) const;
00201 
00202       //! Clip and draw line in 2D
00203       //! @return TRUE if visible, FALSE if not, < 0 if error.
00204       int DrawLineClipped2DNoTrans (
00205          POLYLINE& PolyLine
00206          ) const;
00207 
00208       //! Translate, clip and draw line in 3D
00209       //! @return TRUE if visible, FALSE if not, < 0 if error.
00210       int DrawLineClipped3D (
00211          POLYLINE& PolyLine
00212          ) const;
00213 
00214       //! Translate, clip and draw line in 3D
00215       //! @return TRUE if visible, FALSE if not, < 0 if error.
00216       int DrawLineClipped3D (
00217          DPOINT3D* points,                   //!< Array of points with X/Y coordinates in layer associated with context
00218          INT32 NumPoints                     //!< Number of points
00219          ) const;
00220 
00221       //! Clip and draw segment in 3D.
00222       //! @return TRUE if visible, FALSE if not, < 0 if error.
00223       int DrawSegment3D (
00224          const DPOINT3D& point1,             //!< First point in map coordinates
00225          const DPOINT3D& point2              //!< Second point in map coordinates
00226          ) const;
00227 
00228       //! Fill 3D flat polygon.
00229       //! @return true if was visible, false if not.
00230       bool Fill3dFlatPolygon (
00231          const DPOINT3D *points,             //!< Polygon vertices
00232          INT32 numPoints                     //!< Number of vertices
00233          ) const;
00234 
00235       //! Fill 3D triangle.
00236       //! @return true if was visible, false if not.
00237       bool Fill3dTriangle (
00238          const DPOINT3D *tp[3]               //!< Pointers to triangle vertices
00239          ) const;
00240 
00241       //! Get depth scaling, multiplied by depth to get drawing scale.
00242       double Get3dDepthScale (
00243          ) const { return (m_pLayerView->Get3dDepthScale()); }
00244 
00245       //! Get 3D scene containing 3D transformations.
00246       const GRE::SCENE3D& Get3dScene (
00247          ) const { return (m_Scene3D); }
00248 
00249       //! Get 3D scene containing 3D transformations.
00250       GRE::SCENE3D& Get3dScene (
00251          ) { return (m_Scene3D); }
00252 
00253       //! Get increment in layer relative to once cell in surface layer.
00254       double Get3dSurfaceIncrement (
00255          ) const { return (m_pLayerView->Get3dSurfaceIncrement()); }
00256 
00257       //! Get 3D stereo view setting.
00258       GRE::SCENE3D::STEREOVIEW Get3dStereoView (
00259          ) const { return (m_Scene3D.GetStereoView()); }
00260 
00261       //! Get 3D Z scaling.
00262       double Get3dZScale (
00263          ) const { return (m_pLayerView->Get3dZScale()); }
00264 
00265       //! Get clipping region in device coordinates.
00266       const REGION2D& GetClipRegion (
00267          ) const { return (m_ClipRegion); }
00268 
00269       //! Get design scale.
00270       double GetDesignScale (
00271          ) const { return (m_DesignScale); }
00272 
00273       //! Get drawing flags.
00274       GRE::DRAWFLAGS GetDrawFlags (
00275          ) const { return (m_drawflags); }
00276 
00277       //! Get drawing device context.
00278       MGD::CONTEXT* GetDrawingContext (
00279          ) const { return (m_ggc); }
00280 
00281       //! Get drawing device.
00282       MGD::DEVICE* GetDrawingDevice (
00283          ) const { return (m_ggc == 0 ? 0 : &m_ggc->GetDevice()); }
00284 
00285       //! Get scale at which layer is currently being drawn.
00286       double GetDrawingScale (
00287          ) const { return (m_DrawingScale); }
00288 
00289       //! Get target based on current drawing device.
00290       GRE::RENDERTARGET GetRenderTarget (
00291          ) const { return (m_RenderTarget); }
00292 
00293       //! Get pointer to 'drawn set' based on specified element type and current target device.
00294       //! @return Pointer to BITSET, NULL if none available.
00295       BITSET* GetElemDrawnSet (
00296          ELEMTYPE ElemType = ELEMTYPE_All
00297          ) const;
00298 
00299       //! Get layer.
00300       GRE_LAYER* GetLayer (
00301          ) const { return (m_layer); }
00302 
00303       //! Get LAYERVIEW (const).
00304       const GRE::LAYERVIEW* GetLayerView (
00305          ) const { return (m_pLayerView); }
00306 
00307       //! Get LAYERVIEW (non-const).
00308       GRE::LAYERVIEW* GetLayerView (
00309          ) { return (m_pLayerView); }
00310 
00311       bool GetNoDrawActive (
00312          ) const { return (m_NoDrawActive); }
00313 
00314       //! Get the clip rectangle in object coordinates
00315       const DRECT2D& GetObjectClipRect (
00316          ) const { return (m_ObjClipRect); }
00317 
00318       //! Get pixel size in millimeters.
00319       const DPOINT2D& GetPixelSizeMM (
00320          ) const { return (m_PixelSizeMM); }
00321 
00322       //! Get rotation angle.
00323       double GetRotationAngle (
00324          ) const { return (m_RotationAngle); }
00325 
00326       //! Get rotation cosine.
00327       double GetRotationCos (
00328          ) const { return (m_pGroupView->GetRotationCos()); }
00329 
00330       //! Get rotation sine.
00331       double GetRotationSin (
00332          ) const { return (m_pGroupView->GetRotationSin()); }
00333 
00334       //! Get surface layer for 3D draping.
00335       GRE_LAYER_SURFACE* GetSurfaceLayer (
00336          ) const { return (m_pLayerView->GetSurfaceLayer()); }
00337 
00338       //! Get surface Z coordinates for array of points.
00339       ERRVALUE GetSurfaceZ (
00340          DPOINT3D* points,                   //!< Array of points with X/Y coordinates in layer associated with context
00341          INT32 NumPoints                     //!< Number of points
00342          ) const;
00343 
00344       //! Get surface Z coordinates for POLYLINE.
00345       ERRVALUE GetSurfaceZ (
00346          POLYLINE& polyline                  //!< 3D polyline
00347          ) const;
00348 
00349       //! Get transformation from 'layer' to 'device' coordinates.
00350       const TRANS2D_MAPGEN& GetTransLayerDevice (
00351          ) const { return (m_pLayerView->GetTransLayerDevice()); }
00352 
00353       //! Get transformation from 'layer' to 'surface' coordinates.
00354       const TRANS2D_MAPGEN& GetTransLayerSurface (
00355          ) const { return (m_pLayerView->GetTransLayerSurface()); }
00356 
00357       GRE_VIEW* GetView (
00358          ) const { return (m_view); }
00359 
00360       //! Determine if has surface layer.
00361       bool HasSurfaceLayer (
00362          ) const { return (m_pLayerView->GetSurfaceLayer() != 0); }
00363 
00364       //! Determine if surface has nulls.
00365       bool HasSurfaceNulls (
00366          ) const { return (m_pLayerView->HasSurfaceNulls()); }
00367 
00368       //! Determine if drawing in 2D or 3D.
00369       bool Is3D (
00370          ) const { return (m_pLayerView->Is3D()); }
00371 
00372       //! Determine if layer is 'hidden' due to scale or other visibility setting.
00373       bool IsHidden (
00374          ) const { return (m_IsHidden); }
00375 
00376       //! Determine if surface (layer or flat) is being used.
00377       bool IsSurfaceUsed (
00378          ) const { return (m_pLayerView->IsSurfaceUsed()); }
00379 
00380       //! Send notification before drawing element.
00381       void NotifyDrawElementBegin (
00382          const RVC::ELEMENT& element
00383          ) const { m_view->NotifyDrawElementBegin(m_layer,element); }
00384 
00385       //! Send notification before drawing element.
00386       void NotifyDrawElementBegin (
00387          ELEMTYPE ElemType,
00388          INT32 ElemNum
00389          ) const { m_view->NotifyDrawElementBegin(m_layer,RVC::ELEMENT(ElemNum,ElemType)); }
00390 
00391       //! Send notification after drawing element.
00392       void NotifyDrawElementEnd (
00393          const RVC::ELEMENT& element
00394          ) const { m_view->NotifyDrawElementEnd(m_layer,element); }
00395 
00396       //! Send notification after drawing element.
00397       void NotifyDrawElementEnd (
00398          ELEMTYPE ElemType,
00399          INT32 ElemNum
00400          ) const { m_view->NotifyDrawElementEnd(m_layer,RVC::ELEMENT(ElemNum,ElemType)); }
00401 
00402       //! Set whether current element is scaled when rendered in 3D.
00403       void Set3dElemScaled (
00404          bool IsScaled
00405          ) { m_ScaleToMap3D = IsScaled; }
00406 
00407       void Set3dStereoView (
00408          GRE::SCENE3D::STEREOVIEW StereoView
00409          );
00410 
00411       //! Set drawing flags.
00412       void SetDrawFlags (
00413          GRE::DRAWFLAGS drawflags
00414          );
00415 
00416       //! Set drawing device.
00417       void SetDrawingDevice (
00418          MGD::DEVICE *pDevice
00419          );
00420 
00421       //! Translate 3D point to display coordinates.
00422       //! @return TRUE if point visible, FALSE if not, < 0 if error.
00423       int TransPoint3D (
00424          DPOINT3D& ipoint,                   //!< Point in layer coordinates, Z value may be altered if surface reference used
00425          DPOINT3D& opoint                    //!< Point in display coordinates with canonical depth returned
00426          ) const;
00427 
00428    private:
00429       #ifndef GENERATING_DOXYGEN_OUTPUT
00430 
00431       static SMLAUTOCLASS_NOALLOC_T<GRE_LAYERDC> s_SML_AutoClass;
00432 
00433       static void SML_Register ();
00434 
00435       GRE::GROUPVIEW *m_pGroupView;
00436       GRE::LAYERVIEW *m_pLayerView;
00437       GRE_LAYER *m_layer;
00438       GRE_VIEW *m_view;
00439       MGD::CONTEXT* m_ggc;                      // Generic graphic context
00440       GRE::DRAWFLAGS m_drawflags;               // Drawing flags
00441       REGION2D m_ClipRegion;                    // Current clipping region in device coordinates
00442       DRECT2D m_ObjClipRect;                    // Clipping rectangle in object coordinates
00443       DPOINT2D m_PixelSizeMM;                   // Device pixel size in millimeters
00444       double m_DesignScale;                     // Mirrored from LAYERVIEW for SML access
00445       double m_DrawingScale;
00446       double m_RotationAngle;                   // Mirrored from GROUPVIEW for SML access
00447       bool m_OwnGroupView;
00448       bool m_OwnLayerView;
00449       bool m_IsHidden;
00450       bool m_NoDrawActive;                      // Don't draw "active" element
00451       bool m_ScaleToMap3D;                      // Set if 3D scaling to map
00452       GRE::SCENE3D m_Scene3D;
00453       GRE::RENDERTARGET m_RenderTarget;
00454 
00455       void SetupForDrawFlags ();
00456       void SetupForStereoView ();
00457 
00458       // Not implemented.
00459       GRE_LAYERDC (const GRE_LAYERDC&);
00460       GRE_LAYERDC& operator= (const GRE_LAYERDC&);
00461       
00462       virtual ERRVALUE OnClip (const POLYLINE& PolyLine);
00463 
00464       #endif // GENERATING_DOXYGEN_OUTPUT
00465    };
00466 
00467 //===================================================================================================================
00468 
00469 #endif   // INC_GRE_LAYERDC_H

Generated on Wed May 31 15:26:40 2006 for TNTsdk by  doxygen 1.3.8-20040913