| 1 | // Created on: 2011-08-01 |
| 2 | // Created by: Sergey ZERCHANINOV |
| 3 | // Copyright (c) 2011-2012 OPEN CASCADE SAS |
| 4 | // |
| 5 | // The content of this file is subject to the Open CASCADE Technology Public |
| 6 | // License Version 6.5 (the "License"). You may not use the content of this file |
| 7 | // except in compliance with the License. Please obtain a copy of the License |
| 8 | // at http://www.opencascade.org and read it completely before using this file. |
| 9 | // |
| 10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
| 11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
| 12 | // |
| 13 | // The Original Code and all software distributed under the License is |
| 14 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
| 15 | // Initial Developer hereby disclaims all such warranties, including without |
| 16 | // limitation, any warranties of merchantability, fitness for a particular |
| 17 | // purpose or non-infringement. Please see the License for the specific terms |
| 18 | // and conditions governing the rights and limitations under the License. |
| 19 | |
| 20 | |
| 21 | #include <OpenGl_CappingAlgo.hxx> |
| 22 | #include <OpenGl_Context.hxx> |
| 23 | #include <OpenGl_GlCore11.hxx> |
| 24 | #include <OpenGl_ShaderManager.hxx> |
| 25 | #include <OpenGl_ShaderProgram.hxx> |
| 26 | #include <OpenGl_Structure.hxx> |
| 27 | #include <OpenGl_telem_util.hxx> |
| 28 | #include <OpenGl_Vec.hxx> |
| 29 | #include <OpenGl_View.hxx> |
| 30 | #include <OpenGl_Workspace.hxx> |
| 31 | |
| 32 | #include <Graphic3d_SetOfHClipPlane_Handle.hxx> |
| 33 | |
| 34 | //! Auxiliary class for bounding box presentation |
| 35 | class OpenGl_BndBoxPrs : public OpenGl_Element |
| 36 | { |
| 37 | |
| 38 | public: |
| 39 | |
| 40 | //! Main constructor |
| 41 | OpenGl_BndBoxPrs (const CALL_DEF_BOUNDBOX& theBndBox) |
| 42 | { |
| 43 | const float Xm = theBndBox.Pmin.x; |
| 44 | const float Ym = theBndBox.Pmin.y; |
| 45 | const float Zm = theBndBox.Pmin.z; |
| 46 | const float XM = theBndBox.Pmax.x; |
| 47 | const float YM = theBndBox.Pmax.y; |
| 48 | const float ZM = theBndBox.Pmax.z; |
| 49 | myVerts[0] = OpenGl_Vec3 (Xm, Ym, Zm); |
| 50 | myVerts[1] = OpenGl_Vec3 (Xm, Ym, ZM); |
| 51 | myVerts[2] = OpenGl_Vec3 (Xm, YM, ZM); |
| 52 | myVerts[3] = OpenGl_Vec3 (Xm, YM, Zm); |
| 53 | myVerts[4] = OpenGl_Vec3 (Xm, Ym, Zm); |
| 54 | myVerts[5] = OpenGl_Vec3 (XM, Ym, Zm); |
| 55 | myVerts[6] = OpenGl_Vec3 (XM, Ym, ZM); |
| 56 | myVerts[7] = OpenGl_Vec3 (XM, YM, ZM); |
| 57 | myVerts[8] = OpenGl_Vec3 (XM, YM, Zm); |
| 58 | myVerts[9] = OpenGl_Vec3 (XM, Ym, Zm); |
| 59 | myVerts[10] = OpenGl_Vec3 (XM, YM, Zm); |
| 60 | myVerts[11] = OpenGl_Vec3 (Xm, YM, Zm); |
| 61 | myVerts[12] = OpenGl_Vec3 (Xm, YM, ZM); |
| 62 | myVerts[13] = OpenGl_Vec3 (XM, YM, ZM); |
| 63 | myVerts[14] = OpenGl_Vec3 (XM, Ym, ZM); |
| 64 | myVerts[15] = OpenGl_Vec3 (Xm, Ym, ZM); |
| 65 | } |
| 66 | |
| 67 | //! Render presentation |
| 68 | virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const |
| 69 | { |
| 70 | // Apply line aspect |
| 71 | const OpenGl_AspectLine* anAspectLine = theWorkspace->AspectLine (Standard_True); |
| 72 | const Handle(OpenGl_Texture) aPrevTexture = theWorkspace->DisableTexture(); |
| 73 | |
| 74 | glDisable (GL_LIGHTING); |
| 75 | if ((theWorkspace->NamedStatus & (OPENGL_NS_ADD | OPENGL_NS_IMMEDIATE)) != 0) |
| 76 | { |
| 77 | glDepthMask (GL_FALSE); |
| 78 | } |
| 79 | |
| 80 | // Use highlight colors |
| 81 | glColor3fv ((theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT) ? theWorkspace->HighlightColor->rgb : anAspectLine->Color().rgb); |
| 82 | |
| 83 | glEnableClientState (GL_VERTEX_ARRAY); |
| 84 | glVertexPointer (3, GL_FLOAT, 0, (GLfloat* )&myVerts); |
| 85 | glDrawArrays (GL_LINE_STRIP, 0, 16); |
| 86 | glDisableClientState (GL_VERTEX_ARRAY); |
| 87 | |
| 88 | // restore aspects |
| 89 | if (!aPrevTexture.IsNull()) |
| 90 | { |
| 91 | theWorkspace->EnableTexture (aPrevTexture); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | //! Release graphical resources |
| 96 | virtual void Release (const Handle(OpenGl_Context)& ) |
| 97 | { |
| 98 | // |
| 99 | } |
| 100 | |
| 101 | protected: |
| 102 | |
| 103 | //! Protected destructor |
| 104 | virtual ~OpenGl_BndBoxPrs() {} |
| 105 | |
| 106 | private: |
| 107 | |
| 108 | OpenGl_Vec3 myVerts[16]; //!< vertices array |
| 109 | |
| 110 | public: |
| 111 | |
| 112 | DEFINE_STANDARD_ALLOC |
| 113 | |
| 114 | }; |
| 115 | |
| 116 | /*----------------------------------------------------------------------*/ |
| 117 | |
| 118 | // ======================================================================= |
| 119 | // function : call_util_transpose_mat |
| 120 | // purpose : |
| 121 | // ======================================================================= |
| 122 | static void call_util_transpose_mat (float tmat[16], float mat[4][4]) |
| 123 | { |
| 124 | int i, j; |
| 125 | |
| 126 | for (i=0; i<4; i++) |
| 127 | for (j=0; j<4; j++) |
| 128 | tmat[j*4+i] = mat[i][j]; |
| 129 | } |
| 130 | |
| 131 | // ======================================================================= |
| 132 | // function : OpenGl_Structure |
| 133 | // purpose : |
| 134 | // ======================================================================= |
| 135 | OpenGl_Structure::OpenGl_Structure () |
| 136 | : myTransformation(NULL), |
| 137 | myTransPers(NULL), |
| 138 | myAspectLine(NULL), |
| 139 | myAspectFace(NULL), |
| 140 | myAspectMarker(NULL), |
| 141 | myAspectText(NULL), |
| 142 | myHighlightBox(NULL), |
| 143 | myHighlightColor(NULL), |
| 144 | myNamedStatus(0), |
| 145 | myZLayer(0) |
| 146 | { |
| 147 | } |
| 148 | |
| 149 | // ======================================================================= |
| 150 | // function : ~OpenGl_Structure |
| 151 | // purpose : |
| 152 | // ======================================================================= |
| 153 | OpenGl_Structure::~OpenGl_Structure() |
| 154 | { |
| 155 | Release (Handle(OpenGl_Context)()); |
| 156 | delete myTransformation; myTransformation = NULL; |
| 157 | delete myTransPers; myTransPers = NULL; |
| 158 | } |
| 159 | |
| 160 | // ======================================================================= |
| 161 | // function : SetTransformation |
| 162 | // purpose : |
| 163 | // ======================================================================= |
| 164 | void OpenGl_Structure::SetTransformation(const float *AMatrix) |
| 165 | { |
| 166 | if (!myTransformation) |
| 167 | myTransformation = new OpenGl_Matrix(); |
| 168 | |
| 169 | matcpy( myTransformation->mat, AMatrix ); |
| 170 | } |
| 171 | |
| 172 | // ======================================================================= |
| 173 | // function : SetTransformPersistence |
| 174 | // purpose : |
| 175 | // ======================================================================= |
| 176 | void OpenGl_Structure::SetTransformPersistence(const CALL_DEF_TRANSFORM_PERSISTENCE &ATransPers) |
| 177 | { |
| 178 | if (!myTransPers) |
| 179 | myTransPers = new TEL_TRANSFORM_PERSISTENCE; |
| 180 | |
| 181 | myTransPers->mode = ATransPers.Flag; |
| 182 | myTransPers->pointX = ATransPers.Point.x; |
| 183 | myTransPers->pointY = ATransPers.Point.y; |
| 184 | myTransPers->pointZ = ATransPers.Point.z; |
| 185 | } |
| 186 | |
| 187 | // ======================================================================= |
| 188 | // function : SetAspectLine |
| 189 | // purpose : |
| 190 | // ======================================================================= |
| 191 | void OpenGl_Structure::SetAspectLine (const CALL_DEF_CONTEXTLINE &theAspect) |
| 192 | { |
| 193 | if (!myAspectLine) |
| 194 | { |
| 195 | myAspectLine = new OpenGl_AspectLine(); |
| 196 | } |
| 197 | myAspectLine->SetAspect (theAspect); |
| 198 | } |
| 199 | |
| 200 | // ======================================================================= |
| 201 | // function : SetAspectFace |
| 202 | // purpose : |
| 203 | // ======================================================================= |
| 204 | void OpenGl_Structure::SetAspectFace (const CALL_DEF_CONTEXTFILLAREA& theAspect) |
| 205 | { |
| 206 | if (!myAspectFace) |
| 207 | { |
| 208 | myAspectFace = new OpenGl_AspectFace(); |
| 209 | } |
| 210 | myAspectFace->SetAspect (theAspect); |
| 211 | } |
| 212 | |
| 213 | // ======================================================================= |
| 214 | // function : SetAspectMarker |
| 215 | // purpose : |
| 216 | // ======================================================================= |
| 217 | void OpenGl_Structure::SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theAspect) |
| 218 | { |
| 219 | if (!myAspectMarker) |
| 220 | { |
| 221 | myAspectMarker = new OpenGl_AspectMarker(); |
| 222 | } |
| 223 | myAspectMarker->SetAspect (theAspect); |
| 224 | } |
| 225 | |
| 226 | // ======================================================================= |
| 227 | // function : SetAspectText |
| 228 | // purpose : |
| 229 | // ======================================================================= |
| 230 | void OpenGl_Structure::SetAspectText (const CALL_DEF_CONTEXTTEXT &theAspect) |
| 231 | { |
| 232 | if (!myAspectText) |
| 233 | { |
| 234 | myAspectText = new OpenGl_AspectText(); |
| 235 | } |
| 236 | myAspectText->SetAspect (theAspect); |
| 237 | } |
| 238 | |
| 239 | // ======================================================================= |
| 240 | // function : SetHighlightBox |
| 241 | // purpose : |
| 242 | // ======================================================================= |
| 243 | void OpenGl_Structure::SetHighlightBox (const Handle(OpenGl_Context)& theGlCtx, |
| 244 | const CALL_DEF_BOUNDBOX& theBoundBox) |
| 245 | { |
| 246 | if (myHighlightBox != NULL) |
| 247 | { |
| 248 | myHighlightBox->Release (theGlCtx); |
| 249 | } |
| 250 | else |
| 251 | { |
| 252 | myHighlightBox = new OpenGl_Group(); |
| 253 | } |
| 254 | |
| 255 | CALL_DEF_CONTEXTLINE aContextLine; |
| 256 | aContextLine.Color = theBoundBox.Color; |
| 257 | aContextLine.LineType = Aspect_TOL_SOLID; |
| 258 | aContextLine.Width = 1.0f; |
| 259 | myHighlightBox->SetAspectLine (aContextLine); |
| 260 | |
| 261 | OpenGl_BndBoxPrs* aBndBoxPrs = new OpenGl_BndBoxPrs (theBoundBox); |
| 262 | myHighlightBox->AddElement (TelParray, aBndBoxPrs); |
| 263 | } |
| 264 | |
| 265 | // ======================================================================= |
| 266 | // function : ClearHighlightBox |
| 267 | // purpose : |
| 268 | // ======================================================================= |
| 269 | void OpenGl_Structure::ClearHighlightBox (const Handle(OpenGl_Context)& theGlCtx) |
| 270 | { |
| 271 | if (myHighlightBox != NULL) |
| 272 | { |
| 273 | OpenGl_Element::Destroy (theGlCtx, myHighlightBox); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | // ======================================================================= |
| 278 | // function : SetHighlightColor |
| 279 | // purpose : |
| 280 | // ======================================================================= |
| 281 | void OpenGl_Structure::SetHighlightColor (const Handle(OpenGl_Context)& theGlCtx, |
| 282 | const Standard_ShortReal R, |
| 283 | const Standard_ShortReal G, |
| 284 | const Standard_ShortReal B) |
| 285 | { |
| 286 | ClearHighlightBox (theGlCtx); |
| 287 | if (myHighlightColor == NULL) |
| 288 | { |
| 289 | myHighlightColor = new TEL_COLOUR(); |
| 290 | } |
| 291 | |
| 292 | myHighlightColor->rgb[0] = R; |
| 293 | myHighlightColor->rgb[1] = G; |
| 294 | myHighlightColor->rgb[2] = B; |
| 295 | myHighlightColor->rgb[3] = 1.F; |
| 296 | } |
| 297 | |
| 298 | // ======================================================================= |
| 299 | // function : ClearHighlightColor |
| 300 | // purpose : |
| 301 | // ======================================================================= |
| 302 | void OpenGl_Structure::ClearHighlightColor (const Handle(OpenGl_Context)& theGlCtx) |
| 303 | { |
| 304 | ClearHighlightBox(theGlCtx); |
| 305 | delete myHighlightColor; |
| 306 | myHighlightColor = NULL; |
| 307 | } |
| 308 | |
| 309 | // ======================================================================= |
| 310 | // function : Connect |
| 311 | // purpose : |
| 312 | // ======================================================================= |
| 313 | void OpenGl_Structure::Connect (const OpenGl_Structure *AStructure) |
| 314 | { |
| 315 | Disconnect (AStructure); |
| 316 | myConnected.Append(AStructure); |
| 317 | } |
| 318 | |
| 319 | // ======================================================================= |
| 320 | // function : Disconnect |
| 321 | // purpose : |
| 322 | // ======================================================================= |
| 323 | void OpenGl_Structure::Disconnect (const OpenGl_Structure *AStructure) |
| 324 | { |
| 325 | OpenGl_ListOfStructure::Iterator its(myConnected); |
| 326 | while (its.More()) |
| 327 | { |
| 328 | // Check for the given structure |
| 329 | if (its.Value() == AStructure) |
| 330 | { |
| 331 | myConnected.Remove(its); |
| 332 | return; |
| 333 | } |
| 334 | its.Next(); |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | // ======================================================================= |
| 339 | // function : AddGroup |
| 340 | // purpose : |
| 341 | // ======================================================================= |
| 342 | OpenGl_Group * OpenGl_Structure::AddGroup () |
| 343 | { |
| 344 | // Create new group |
| 345 | OpenGl_Group *g = new OpenGl_Group; |
| 346 | myGroups.Append(g); |
| 347 | return g; |
| 348 | } |
| 349 | |
| 350 | // ======================================================================= |
| 351 | // function : RemoveGroup |
| 352 | // purpose : |
| 353 | // ======================================================================= |
| 354 | void OpenGl_Structure::RemoveGroup (const Handle(OpenGl_Context)& theGlCtx, |
| 355 | const OpenGl_Group* theGroup) |
| 356 | { |
| 357 | for (OpenGl_ListOfGroup::Iterator anIter (myGroups); anIter.More(); anIter.Next()) |
| 358 | { |
| 359 | // Check for the given group |
| 360 | if (anIter.Value() == theGroup) |
| 361 | { |
| 362 | // Delete object |
| 363 | OpenGl_Element::Destroy (theGlCtx, const_cast<OpenGl_Group*& > (anIter.ChangeValue())); |
| 364 | myGroups.Remove (anIter); |
| 365 | return; |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | // ======================================================================= |
| 371 | // function : Clear |
| 372 | // purpose : |
| 373 | // ======================================================================= |
| 374 | void OpenGl_Structure::Clear (const Handle(OpenGl_Context)& theGlCtx) |
| 375 | { |
| 376 | // Release groups |
| 377 | for (OpenGl_ListOfGroup::Iterator anIter (myGroups); anIter.More(); anIter.Next()) |
| 378 | { |
| 379 | // Delete objects |
| 380 | OpenGl_Element::Destroy (theGlCtx, const_cast<OpenGl_Group*& > (anIter.ChangeValue())); |
| 381 | } |
| 382 | myGroups.Clear(); |
| 383 | } |
| 384 | |
| 385 | // ======================================================================= |
| 386 | // function : Render |
| 387 | // purpose : |
| 388 | // ======================================================================= |
| 389 | void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &AWorkspace) const |
| 390 | { |
| 391 | // Process the structure only if visible |
| 392 | if ( myNamedStatus & OPENGL_NS_HIDE ) |
| 393 | return; |
| 394 | |
| 395 | // Render named status |
| 396 | const Standard_Integer named_status = AWorkspace->NamedStatus; |
| 397 | AWorkspace->NamedStatus |= myNamedStatus; |
| 398 | |
| 399 | // Is rendering in ADD or IMMEDIATE mode? |
| 400 | const Standard_Boolean isImmediate = (AWorkspace->NamedStatus & (OPENGL_NS_ADD | OPENGL_NS_IMMEDIATE)) != 0; |
| 401 | |
| 402 | const Handle(OpenGl_Context)& aCtx = AWorkspace->GetGlContext(); |
| 403 | |
| 404 | // Apply local transformation |
| 405 | GLint matrix_mode = 0; |
| 406 | const OpenGl_Matrix *local_trsf = NULL; |
| 407 | if (myTransformation) |
| 408 | { |
| 409 | if (isImmediate) |
| 410 | { |
| 411 | Tmatrix3 aModelWorld; |
| 412 | call_util_transpose_mat (*aModelWorld, myTransformation->mat); |
| 413 | glGetIntegerv (GL_MATRIX_MODE, &matrix_mode); |
| 414 | |
| 415 | if (!aCtx->ShaderManager()->IsEmpty()) |
| 416 | { |
| 417 | Tmatrix3 aWorldView; |
| 418 | glGetFloatv (GL_MODELVIEW_MATRIX, *aWorldView); |
| 419 | |
| 420 | Tmatrix3 aProjection; |
| 421 | glGetFloatv (GL_PROJECTION_MATRIX, *aProjection); |
| 422 | |
| 423 | aCtx->ShaderManager()->UpdateModelWorldStateTo (aModelWorld); |
| 424 | aCtx->ShaderManager()->UpdateWorldViewStateTo (aWorldView); |
| 425 | aCtx->ShaderManager()->UpdateProjectionStateTo (aProjection); |
| 426 | } |
| 427 | |
| 428 | glMatrixMode (GL_MODELVIEW); |
| 429 | glPushMatrix (); |
| 430 | glScalef (1.F, 1.F, 1.F); |
| 431 | glMultMatrixf (*aModelWorld); |
| 432 | } |
| 433 | else |
| 434 | { |
| 435 | glMatrixMode (GL_MODELVIEW); |
| 436 | glPushMatrix(); |
| 437 | |
| 438 | local_trsf = AWorkspace->SetStructureMatrix (myTransformation); |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | // Apply transform persistence |
| 443 | const TEL_TRANSFORM_PERSISTENCE *trans_pers = NULL; |
| 444 | if ( myTransPers && myTransPers->mode != 0 ) |
| 445 | { |
| 446 | trans_pers = AWorkspace->ActiveView()->BeginTransformPersistence (aCtx, myTransPers); |
| 447 | } |
| 448 | |
| 449 | // Apply aspects |
| 450 | const OpenGl_AspectLine *aspect_line = AWorkspace->AspectLine(Standard_False); |
| 451 | const OpenGl_AspectFace *aspect_face = AWorkspace->AspectFace(Standard_False); |
| 452 | const OpenGl_AspectMarker *aspect_marker = AWorkspace->AspectMarker(Standard_False); |
| 453 | const OpenGl_AspectText *aspect_text = AWorkspace->AspectText(Standard_False); |
| 454 | if (myAspectLine) |
| 455 | AWorkspace->SetAspectLine(myAspectLine); |
| 456 | if (myAspectFace) |
| 457 | AWorkspace->SetAspectFace(myAspectFace); |
| 458 | if (myAspectMarker) |
| 459 | AWorkspace->SetAspectMarker(myAspectMarker); |
| 460 | if (myAspectText) |
| 461 | AWorkspace->SetAspectText(myAspectText); |
| 462 | |
| 463 | // Apply highlight box |
| 464 | if (myHighlightBox) |
| 465 | myHighlightBox->Render( AWorkspace ); |
| 466 | |
| 467 | // Apply highlight color |
| 468 | const TEL_COLOUR *highlight_color = AWorkspace->HighlightColor; |
| 469 | if (myHighlightColor) |
| 470 | AWorkspace->HighlightColor = myHighlightColor; |
| 471 | |
| 472 | // Render connected structures |
| 473 | OpenGl_ListOfStructure::Iterator its(myConnected); |
| 474 | while (its.More()) |
| 475 | { |
| 476 | its.Value()->Render(AWorkspace); |
| 477 | its.Next(); |
| 478 | } |
| 479 | |
| 480 | // Set up plane equations for non-structure transformed global model-view matrix |
| 481 | const Handle(OpenGl_Context)& aContext = AWorkspace->GetGlContext(); |
| 482 | |
| 483 | // List of planes to be applied to context state |
| 484 | Handle(Graphic3d_SetOfHClipPlane) aUserPlanes; |
| 485 | |
| 486 | // Collect clipping planes of structure scope |
| 487 | if (!myClipPlanes.IsEmpty()) |
| 488 | { |
| 489 | Graphic3d_SetOfHClipPlane::Iterator aClippingIt (myClipPlanes); |
| 490 | for (; aClippingIt.More(); aClippingIt.Next()) |
| 491 | { |
| 492 | const Handle(Graphic3d_ClipPlane)& aClipPlane = aClippingIt.Value(); |
| 493 | if (!aClipPlane->IsOn()) |
| 494 | { |
| 495 | continue; |
| 496 | } |
| 497 | |
| 498 | if (aUserPlanes.IsNull()) |
| 499 | { |
| 500 | aUserPlanes = new Graphic3d_SetOfHClipPlane(); |
| 501 | } |
| 502 | |
| 503 | aUserPlanes->Add (aClipPlane); |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | if (!aUserPlanes.IsNull() && !aUserPlanes->IsEmpty()) |
| 508 | { |
| 509 | // add planes at loaded view matrix state |
| 510 | aContext->ChangeClipping().AddWorld (*aUserPlanes, AWorkspace); |
| 511 | |
| 512 | // Set OCCT state uniform variables |
| 513 | if (!aContext->ShaderManager()->IsEmpty()) |
| 514 | { |
| 515 | aContext->ShaderManager()->UpdateClippingState(); |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | // Render groups |
| 520 | OpenGl_ListOfGroup::Iterator itg(myGroups); |
| 521 | while (itg.More()) |
| 522 | { |
| 523 | itg.Value()->Render(AWorkspace); |
| 524 | itg.Next(); |
| 525 | } |
| 526 | |
| 527 | // Render capping for structure groups |
| 528 | if (!aContext->Clipping().Planes().IsEmpty()) |
| 529 | { |
| 530 | OpenGl_CappingAlgo::RenderCapping (AWorkspace, myGroups); |
| 531 | } |
| 532 | |
| 533 | // Revert structure clippings |
| 534 | if (!aUserPlanes.IsNull() && !aUserPlanes->IsEmpty()) |
| 535 | { |
| 536 | aContext->ChangeClipping().Remove (*aUserPlanes); |
| 537 | |
| 538 | // Set OCCT state uniform variables |
| 539 | if (!aContext->ShaderManager()->IsEmpty()) |
| 540 | { |
| 541 | aContext->ShaderManager()->RevertClippingState(); |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | // Restore highlight color |
| 546 | AWorkspace->HighlightColor = highlight_color; |
| 547 | |
| 548 | // Restore aspects |
| 549 | AWorkspace->SetAspectLine(aspect_line); |
| 550 | AWorkspace->SetAspectFace(aspect_face); |
| 551 | AWorkspace->SetAspectMarker(aspect_marker); |
| 552 | AWorkspace->SetAspectText(aspect_text); |
| 553 | |
| 554 | // Restore transform persistence |
| 555 | if ( myTransPers && myTransPers->mode != 0 ) |
| 556 | { |
| 557 | AWorkspace->ActiveView()->BeginTransformPersistence (aContext, trans_pers); |
| 558 | } |
| 559 | |
| 560 | // Restore local transformation |
| 561 | if (myTransformation) |
| 562 | { |
| 563 | if (isImmediate) |
| 564 | { |
| 565 | glPopMatrix (); |
| 566 | glMatrixMode (matrix_mode); |
| 567 | |
| 568 | Tmatrix3 aModelWorldState = { { 1.f, 0.f, 0.f, 0.f }, |
| 569 | { 0.f, 1.f, 0.f, 0.f }, |
| 570 | { 0.f, 0.f, 1.f, 0.f }, |
| 571 | { 0.f, 0.f, 0.f, 1.f } }; |
| 572 | |
| 573 | aContext->ShaderManager()->RevertModelWorldStateTo (aModelWorldState); |
| 574 | } |
| 575 | else |
| 576 | { |
| 577 | AWorkspace->SetStructureMatrix (local_trsf, true); |
| 578 | |
| 579 | glMatrixMode (GL_MODELVIEW); |
| 580 | glPopMatrix(); |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | // Restore named status |
| 585 | AWorkspace->NamedStatus = named_status; |
| 586 | } |
| 587 | |
| 588 | // ======================================================================= |
| 589 | // function : Release |
| 590 | // purpose : |
| 591 | // ======================================================================= |
| 592 | void OpenGl_Structure::Release (const Handle(OpenGl_Context)& theGlCtx) |
| 593 | { |
| 594 | // Release groups |
| 595 | Clear (theGlCtx); |
| 596 | OpenGl_Element::Destroy (theGlCtx, myAspectLine); |
| 597 | OpenGl_Element::Destroy (theGlCtx, myAspectFace); |
| 598 | OpenGl_Element::Destroy (theGlCtx, myAspectMarker); |
| 599 | OpenGl_Element::Destroy (theGlCtx, myAspectText); |
| 600 | ClearHighlightColor (theGlCtx); |
| 601 | } |
| 602 | |
| 603 | // ======================================================================= |
| 604 | // function : ReleaseGlResources |
| 605 | // purpose : |
| 606 | // ======================================================================= |
| 607 | void OpenGl_Structure::ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx) |
| 608 | { |
| 609 | for (OpenGl_ListOfGroup::Iterator anIter (myGroups); anIter.More(); anIter.Next()) |
| 610 | { |
| 611 | OpenGl_Group* aGroup = const_cast<OpenGl_Group*& > (anIter.ChangeValue()); |
| 612 | if (aGroup != NULL) |
| 613 | { |
| 614 | aGroup->Release (theGlCtx); |
| 615 | } |
| 616 | } |
| 617 | if (myAspectLine != NULL) |
| 618 | { |
| 619 | myAspectLine->Release (theGlCtx); |
| 620 | } |
| 621 | if (myAspectFace != NULL) |
| 622 | { |
| 623 | myAspectFace->Release (theGlCtx); |
| 624 | } |
| 625 | if (myAspectMarker != NULL) |
| 626 | { |
| 627 | myAspectMarker->Release (theGlCtx); |
| 628 | } |
| 629 | if (myAspectText != NULL) |
| 630 | { |
| 631 | myAspectText->Release (theGlCtx); |
| 632 | } |
| 633 | if (myHighlightBox != NULL) |
| 634 | { |
| 635 | myHighlightBox->Release (theGlCtx); |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | //======================================================================= |
| 640 | //function : SetZLayer |
| 641 | //purpose : |
| 642 | //======================================================================= |
| 643 | void OpenGl_Structure::SetZLayer (const Standard_Integer theLayerIndex) |
| 644 | { |
| 645 | myZLayer = theLayerIndex; |
| 646 | } |
| 647 | |
| 648 | //======================================================================= |
| 649 | //function : GetZLayer |
| 650 | //purpose : |
| 651 | //======================================================================= |
| 652 | Standard_Integer OpenGl_Structure::GetZLayer () const |
| 653 | { |
| 654 | return myZLayer; |
| 655 | } |