1 //#*************************************************************************************** 2 //# filename: renderContext.h 3 //# 4 //# author: Johannes Gerstmayr, Yuri Vetyukov 5 //# 6 //# generated: 7 //# description: 8 //# 9 //# comments: 10 //# 11 //# Copyright (c) 2003-2013 Johannes Gerstmayr, Linz Center of Mechatronics GmbH, Austrian 12 //# Center of Competence in Mechatronics GmbH, Institute of Technical Mechanics at the 13 //# Johannes Kepler Universitaet Linz, Austria. All rights reserved. 14 //# 15 //# This file is part of HotInt. 16 //# HotInt is free software: you can redistribute it and/or modify it under the terms of 17 //# the HOTINT license. See folder 'licenses' for more details. 18 //# 19 //# bug reports are welcome!!! 20 //# WWW: www.hotint.org 21 //# email: bug_reports@hotint.org or support@hotint.org 22 //#*************************************************************************************** 23 24 #pragma once 25 26 // PAINTING graphics 27 struct RenderContext 28 { ~RenderContextRenderContext29 virtual ~RenderContext() {} 30 31 // the color setting affects all the graphics & text in the graphics window; 32 // r, g, b change from 0 to 1 33 virtual void ChooseColor(float r, float g, float b) = 0; 34 virtual void ChooseLineThickness(float thickness) = 0; // thickness in pixels 35 virtual void ChoosePointSize(float size) = 0; 36 struct Vertex 37 { 38 float x, y, z; VertexRenderContext::Vertex39 Vertex() {} VertexRenderContext::Vertex40 Vertex(float x_, float y_, float z_) : x(x_),y(y_),z(z_) {} 41 }; 42 43 // these functions execute corresponding OpenGL commands 44 virtual void glBeginPoints() = 0; // GL_POINTS 45 virtual void glBeginLines() = 0; // GL_LINES 46 virtual void glBeginLineStrip() = 0; // GL_LINE_STRIP 47 virtual void glBeginLineLoop() = 0; // GL_LINE_LOOP 48 virtual void glBeginTriangles() = 0; // GL_TRIANGLES 49 virtual void glBeginTriangleStrip() = 0;// GL_TRIANGLE_STRIP 50 virtual void glBeginTriangleFan() = 0; // GL_TRIANGLE_FAN 51 virtual void glBeginQuads() = 0; // GL_QUADS 52 virtual void glBeginQuadStrip() = 0; // GL_QUAD_STRIP 53 virtual void glBeginPolygon() = 0; // GL_POLYGON 54 virtual void glEnd() = 0; 55 virtual void glColor3f(float x, float y, float z) = 0; 56 virtual void glColor4f(float x, float y, float z, float transp) = 0; 57 virtual void glEnableColorMaterial() = 0; 58 virtual void glDisableColorMaterial() = 0; 59 // both commands specify a point of the primitive 60 // must be MinCoord <= x,y,z <= MaxCoord, where 61 // MinCoord & MaxCoord have been specified in GetSceneMinMaxCoordinates() 62 // the whole figure should be centered around the point (0,0,0), 63 // as the rotation is going around this point 64 virtual void glVertex(float x, float y, float z) = 0; 65 virtual void glRasterPos(float x, float y, float z) = 0; 66 virtual void glVertex(const Vertex & v) = 0; 67 68 // in the mode with lighting the normals start playing a role 69 // the normals need not to be normalized 70 virtual void glNormal(float x, float y, float z) = 0; 71 virtual void glNormal(const Vertex & v) = 0; 72 73 virtual void glVertex(const double* v) = 0; 74 virtual void glNormal(const double* v) = 0; 75 76 //use different offset for lines on solid, should improve visibility... 77 virtual void BeginLinesOnSolid() = 0; 78 virtual void EndLinesOnSolid() = 0; 79 80 81 //functions to draw texture: 82 virtual void glInitializeTexture(unsigned int* texName, const void* texImage, int imageH, int imageW) = 0; //initialize texture 83 virtual void glBeginTexture(const unsigned int& texName) = 0; //call this function just before begin QUADS 84 virtual void glEndTexture() = 0; //call this function just after glEnd() of QUADS 85 virtual void glTexCoord2f(float x, float y) = 0; //local coordinates in texture image (0,0) - (1,1) 86 87 virtual void glBeginTexture1D(const unsigned int& texName) = 0; //call this function just before begin QUADS 88 virtual void glEndTexture1D() = 0; //call this function just after glEnd() of QUADS 89 virtual void glTexCoord1f(float x) = 0; //local coordinates in texture image (0 - 1) 90 91 92 93 //If you want to draw without transformation, first call glPushMatrices(), after 94 //drawing dont forget to call glPopMatrices() 95 virtual void glPushMatrices() = 0; 96 virtual void glPopMatrices() = 0; 97 98 // defined symbols 99 virtual void DrawNode(float x, float y, float z) = 0; 100 virtual void DrawFixedDof(float x, float y, float z, int dof_num) = 0; 101 // here dof_num changes from 0 to 2: x, y, z 102 virtual void DrawForce(float x, float y, float z, float dirx, float diry, float dirz) = 0; 103 // dir defines the direction and not the magnitude 104 105 // the text color is not affected by ChooseColor() 106 // here the window coordinates are specified, (-1,-1) -- bottom-left, (1,1) -- top-right 107 virtual void PrintText2D(float x, float y, const char * text) = 0; 108 // here the structured text can be written. nLineNo >=0; 109 // nXPos < 0 -- the text is aligned to the left; 110 // nXPos == 0 -- the text is aligned to the center; 111 // nXPos > 0 -- the text is aligned to the right; 112 virtual void PrintTextStruct(int nLineNo, int nXPos, const char * text) = 0; 113 // here the 3D scene coordinates are specified, 114 // so that the text position on the screen is not fixed 115 virtual void PrintText3D(float x, float y, float z, const char * text) = 0; 116 117 virtual void SetTextColor(float r, float g, float b) = 0; 118 virtual void SetBackgroundColor(float r, float g, float b) = 0; 119 virtual void SetCenterOffset(float x, float y, float z) = 0; 120 121 //size of drawing window in pixel 122 virtual void GetWindowSize(int& width, int& height) = 0; 123 124 // the following options are set by the user in the driving module 125 // in order to tell the working module what to paint and how to paint the scene 126 virtual int GetDetailLevel() = 0; // how many line segments represent an arc 127 virtual int ShowLegend() = 0; 128 }; 129 130 // Interface to the DrawWindow2D for Control Elements 131 //!AD: 2012-12-12 [ 132 struct ControlWindowContext 133 { ~ControlWindowContextControlWindowContext134 virtual ~ControlWindowContext() {} 135 136 ////// identify the type and number of the element on the MBS-side 137 ////typedef enum { TNoMBSElem = 0, TIOBlock = 1, TSensor = 2 } TMBSElementType; 138 139 ////// identify the type and number of the element on the Draw-side 140 ////typedef enum { TNoSubType = 0, 141 //// TElementFrame = 1, TElementName = 2, 142 //// TInputNode = 3, TOutputNode = 4, 143 //// TConstructionNode = 5, TConnectionLine = 6, 144 //// TTextObject = 7, 145 //// TSymbol = 8} TDrawElementType; 146 147 ////typedef enum { TNoGeoType = 0, TGLine = 1, TGRectangle = 2, TGEllipse = 3, TGText = 4} TGeomElementType; 148 149 //// typedef enum {HLeft=1, HCenter=5, HRight=9, 150 //// VTop=10, VCenter=50, VBottom=90} TTextAllign; 151 152 // this struct holds all informaiton for the object to be drawn 153 // each MBS-Side element is mapped to one or more Draw-Elements 154 //$ YV 2012-12-21: I'd use Vectors here 155 struct DrawComponent 156 { 157 // this defines the element in the MBS - COMBINATION is UNIQUE (for a MBS element...) 158 TMBSElementType mbs_type; // type of the Element ( see enum TMBSElementType ) 159 int mbs_elnr; // number of the corresponding element in the MBS 160 // this defines the component ( - ? COMBINATION is UNIQUE ? NOT IMPLEMENTED THAT WAY YET) 161 TDrawElementType sub_type; // type of the Element ( see enum TMBSElementType ) 162 int sub_elnr; 163 // this defines the drawn shape 164 TGeomElementType geo_type; 165 166 Vector2D center,size; // positions used for rect, ellipse, line 167 Vector3D col,col2; // foreground and background color of element (border+area / line / text) 168 mystr text; // text description - ElementName ... 169 TTextAllign textallign; // identifier for relative textposition ...... 170 171 // accessfunctions CenterControlWindowContext::DrawComponent172 Vector2D& Center() { return center; } SizeControlWindowContext::DrawComponent173 Vector2D& Size() { return size; } P1ControlWindowContext::DrawComponent174 Vector2D& P1() { return center; } P2ControlWindowContext::DrawComponent175 Vector2D& P2() { return size; } ColorControlWindowContext::DrawComponent176 Vector3D& Color() { return col; } BackgroundControlWindowContext::DrawComponent177 Vector3D& Background() { return col2; } TextControlWindowContext::DrawComponent178 mystr& Text() { return text; } TextAllignControlWindowContext::DrawComponent179 TTextAllign& TextAllign() { return textallign; } 180 181 DrawComponentControlWindowContext::DrawComponent182 DrawComponent() : mbs_type(TNoMBSElem), mbs_elnr(0), sub_type(TNoSubType), sub_elnr(0), geo_type(TNoGeoType), 183 center(0), size(0), col(0), col2(0), 184 text(0) 185 { 186 textallign = TTextAllign (HCenter+VCenter); 187 } 188 DrawComponentControlWindowContext::DrawComponent189 DrawComponent(const DrawComponent& other) 190 { 191 mbs_type = other.mbs_type; 192 mbs_elnr = other.mbs_elnr; 193 sub_type = other.sub_type; 194 sub_elnr = other.sub_elnr; 195 geo_type = other.geo_type; 196 197 center = other.center; 198 size = other.size; 199 col = other.col; 200 col2 = other.col2; 201 text = other.text; 202 textallign = other.textallign; 203 } 204 // Type considering Drawing - Geometry Type IsLineControlWindowContext::DrawComponent205 int IsLine() const { if (geo_type == TGLine) return 1; else return 0; } IsRectangleControlWindowContext::DrawComponent206 int IsRectangle() const { if (geo_type == TGRectangle) return 1; else return 0; } IsEllipseControlWindowContext::DrawComponent207 int IsEllipse() const { if (geo_type == TGEllipse) return 1; else return 0; } IsTextControlWindowContext::DrawComponent208 int IsText() const { if (geo_type == TGText) return 1; else return 0; } 209 210 // Tyoe considering Selection - Subtype IsSymbolControlWindowContext::DrawComponent211 int IsSymbol() const { if (sub_type == TSymbol) return 1; else return 0; } 212 213 // Type considering Selection IsSelectableControlWindowContext::DrawComponent214 int IsSelectable() const { if (IsSelectableMBSElement() || IsSelectableConnectionLine() || IsSelectableConstructionNode()) return 1; else return 0; } IsSelectableMBSElementControlWindowContext::DrawComponent215 int IsSelectableMBSElement() const { if (sub_type == TElementFrame || sub_type == TElementName || sub_type == TSymbol) return 1; else return 0; } IsSelectableConnectionLineControlWindowContext::DrawComponent216 int IsSelectableConnectionLine() const { if (sub_type == TConnectionLine ) return 1; else return 0; } IsSelectableConstructionNodeControlWindowContext::DrawComponent217 int IsSelectableConstructionNode() const { if (sub_type == TConstructionNode ) return 1; else return 0; } 218 GetXMinControlWindowContext::DrawComponent219 double GetXMin() const 220 { 221 if (IsLine()) { return Minimum(center.X(),size.X()); } 222 else { return center.X()-0.5*abs(size.X()); } 223 } GetXMaxControlWindowContext::DrawComponent224 double GetXMax() const 225 { 226 if (IsLine()) { return Maximum(center.X(),size.X()); } 227 else { return center.X()+0.5*abs(size.X()); } 228 } 229 GetYMinControlWindowContext::DrawComponent230 double GetYMin() const 231 { 232 if (IsLine()) { return Minimum(center.Y(),size.Y()); } 233 else { return center.Y()-0.5*abs(size.Y()); } 234 } GetYMaxControlWindowContext::DrawComponent235 double GetYMax() const 236 { 237 if (IsLine()) { return Maximum(center.Y(),size.Y()); } 238 else { return center.Y()+0.5*abs(size.Y()); } 239 } 240 }; 241 242 // Add an DrawElement to the List, this is done by the MBS-Elements 243 virtual int AddDrawComponent(const DrawComponent& elem) = 0; 244 245 // DrawFunction for elements of the DrawElementsList 246 virtual int DrawScene() = 0; 247 248 // reset thhe content of the window 249 virtual void Reset() = 0; 250 251 }; 252