p Graphic3d
p Image
p MeshVS
-p NIS
p OpenGl
p Prs3d
p PrsMgr
r Textures
r Shaders
t TKMeshVS
-t TKNIS
t TKOpenGl
t TKService
t TKV3d
p IVtkTools
t TKIVtk
p IVtkDraw
-t TKIVtkDraw
\ No newline at end of file
+t TKIVtkDraw
+++ /dev/null
-CSF_OpenGlLibs
+++ /dev/null
-EXTERNLIB
-FILES
-NIS_Allocator.cxx
-NIS_Allocator.hxx
-NIS_Drawer.cxx
-NIS_Drawer.hxx
-NIS_DrawList.cxx
-NIS_DrawList.hxx
-NIS_InteractiveContext.cxx
-NIS_InteractiveContext.hxx
-NIS_InteractiveObject.cxx
-NIS_InteractiveObject.hxx
-NIS_ObjectsIterator.cxx
-NIS_ObjectsIterator.hxx
-NIS_SelectFilter.cxx
-NIS_SelectFilter.hxx
-NIS_Surface.cxx
-NIS_Surface.hxx
-NIS_SurfaceDrawer.cxx
-NIS_SurfaceDrawer.hxx
-NIS_Triangulated.cxx
-NIS_Triangulated.hxx
-NIS_TriangulatedDrawer.cxx
-NIS_TriangulatedDrawer.hxx
-NIS_View.cxx
-NIS_View.hxx
-Handle_NIS_InteractiveObject.hxx
-Handle_NIS_View.hxx
-NIS_CMPLRS.edl
+++ /dev/null
-// Created on: 2007-07-14
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2007-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#ifndef Handle_NIS_InteractiveObject_HeaderFile
-#define Handle_NIS_InteractiveObject_HeaderFile
-
-#include <Standard_DefineHandle.hxx>
-#include <Standard_Transient.hxx>
-
-class NIS_InteractiveObject;
-
-/**
- * Definition of HANDLE object using Standard_DefineHandle.hxx
- */
-DEFINE_STANDARD_HANDLE (NIS_InteractiveObject, Standard_Transient)
-
-#endif
+++ /dev/null
-// Created on: 2007-07-06
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2007-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#ifndef Handle_NIS_View_HeaderFile
-#define Handle_NIS_View_HeaderFile
-
-#include <Standard_DefineHandle.hxx>
-#include <Handle_V3d_View.hxx>
-
-class NIS_View;
-
-// Definition of HANDLE object using Standard_DefineHandle.hxx
-DEFINE_STANDARD_HANDLE (NIS_View, V3d_View)
-
-#endif
+++ /dev/null
--- Created on: 2008-07-02
--- Created by: Alexander GRIGORIEV
--- Copyright (c) 2008-2014 OPEN CASCADE SAS
---
--- This file is part of Open CASCADE Technology software library.
---
--- This library is free software; you can redistribute it and/or modify it under
--- the terms of the GNU Lesser General Public License version 2.1 as published
--- by the Free Software Foundation, with special exception defined in the file
--- OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
--- distribution for complete text of the license and disclaimer of any warranty.
---
--- Alternatively, this file may be used under the terms of Open CASCADE
--- commercial license or contractual agreement.
-
--- Dummy package header
-
-package NIS
-uses
- V3d,
- Bnd
-is
- imported Drawer;
- imported DrawList;
- imported InteractiveContext;
- imported InteractiveObject;
- imported ObjectsIterator;
- imported SelectFilter;
- imported Surface;
- imported SurfaceDrawer;
- imported Triangulated;
- imported TriangulatedDrawer;
- imported View;
-
-end NIS;
+++ /dev/null
-// Created on: 2010-10-22
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2010-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <NIS_Allocator.hxx>
-
-IMPLEMENT_STANDARD_HANDLE (NIS_Allocator, NCollection_IncAllocator)
-IMPLEMENT_STANDARD_RTTIEXT (NIS_Allocator, NCollection_IncAllocator)
-
-//=======================================================================
-//function : NIS_Allocator
-//purpose :
-//=======================================================================
-
-NIS_Allocator::NIS_Allocator (const size_t theBlockSize)
- : NCollection_IncAllocator (theBlockSize),
- myNAllocated (0),
- myNFreed (0)
-{}
-
-//=======================================================================
-//function : ResetCounters
-//purpose :
-//=======================================================================
-
-void NIS_Allocator::ResetCounters ()
-{
- myNAllocated = 0;
- myNFreed = 0;
-}
-
-//=======================================================================
-//function : Allocate
-//purpose :
-//=======================================================================
-
-void* NIS_Allocator::Allocate (const size_t size)
-{
- size_t* pResult = reinterpret_cast<size_t*>
- (NCollection_IncAllocator::Allocate(size + sizeof(size_t)));
- pResult[0] = size;
- myNAllocated += size;
- return &pResult[1];
-}
-
-//=======================================================================
-//function : Free
-//purpose :
-//=======================================================================
-
-void NIS_Allocator::Free (void *anAddress)
-{
- if (anAddress) {
- size_t* pAddress = reinterpret_cast<size_t*>(anAddress) - 1;
- myNFreed += pAddress[0];
- NCollection_IncAllocator::Free(pAddress);
- }
-}
+++ /dev/null
-// Created on: 2010-10-22
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2010-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#ifndef NIS_Allocator_HeaderFile
-#define NIS_Allocator_HeaderFile
-
-#include <NCollection_IncAllocator.hxx>
-
-/**
- * Subclass of Incremental Allocator. It is aware of the total
- * allocated and released memory. Used in NIS_Interactive context as
- * private allocator that manages all memory used by interactive objects.
- */
-
-class NIS_Allocator : public NCollection_IncAllocator
-{
- public:
- // ---------- PUBLIC METHODS ----------
-
-
- /**
- * Constructor.
- */
- Standard_EXPORT NIS_Allocator (const size_t theBlockSize = 24600);
-
- /**
- * Query the total number of allocated bytes
- */
- inline Standard_Size NAllocated () const
- {
- return myNAllocated;
- }
-
- /**
- * Query the total number of released bytes
- */
- inline Standard_Size NFreed () const
- {
- return myNFreed;
- }
-
- /**
- * Set both counters to zero. Should be called with method Reset of the base
- * class NCollection_IncAlocator.
- */
- Standard_EXPORT void ResetCounters ();
-
- /**
- * Allocate memory with given size. Returns NULL on failure
- */
- Standard_EXPORT virtual void* Allocate (const size_t size);
-
- /*
- * Free a previously allocated memory. Does nothing but count released bytes.
- */
- Standard_EXPORT virtual void Free (void *anAddress);
-
- private:
- // ---------- PRIVATE FIELDS ----------
-
- Standard_Size myNAllocated;
- Standard_Size myNFreed;
-
- public:
-// Declaration of CASCADE RTTI
-DEFINE_STANDARD_RTTI (NIS_Allocator)
-};
-
-// Definition of HANDLE object using Standard_DefineHandle.hxx
-DEFINE_STANDARD_HANDLE (NIS_Allocator, NCollection_IncAllocator)
-
-
-#endif
+++ /dev/null
--- Created by: Stephane Callegari
--- Copyright (c) 1996-1999 Matra Datavision
--- Copyright (c) 1999-2014 OPEN CASCADE SAS
---
--- This file is part of Open CASCADE Technology software library.
---
--- This library is free software; you can redistribute it and/or modify it under
--- the terms of the GNU Lesser General Public License version 2.1 as published
--- by the Free Software Foundation, with special exception defined in the file
--- OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
--- distribution for complete text of the license and disclaimer of any warranty.
---
--- Alternatively, this file may be used under the terms of Open CASCADE
--- commercial license or contractual agreement.
-
--- 01-11-97 : BGN : Portage HP/OpenGL
--- (avec option +a1 pour C++, et -Aa pour C)
-
-@ifnotdefined ( %NIS_CMPLRS_EDL) then
-
- @set %NIS_CMPLRS_EDL = "";
-
- @uses "CSF.edl";
-
- @string %CMPLRS_CXX_Options += %CSF_X11_INCLUDE " " %CSF_OPENGL_INCLUDE " " ;
- @string %CMPLRS_C_Options += %CSF_X11_INCLUDE " " %CSF_OPENGL_INCLUDE " " ;
-
- @if ( %Station == "hp" ) then
-
- -- BGN : et ajout de _HPUX_SOURCE pour /usr/include/math.h (M_PI)
- @string %CMPLRS_C_Options += " -D_HPUX_SOURCE";
-
- @if ( %DebugMode == "False" ) then
- @set %CMPLRS_C_ModeOpt = "+O1 -DNo_Exception ";
- @set %CMPLRS_F77_ModeOpt = "+O1";
- @endif;
-
- @endif;
-
- @if ( %Station == "ao1" ) then
-
- @string %CMPLRS_C_Options += " -DJWR_DEC_TRIFAN_BUG";
- @string %CMPLRS_C_Options += " -std1";
-
- @endif;
-
- -- FMN @string %CMPLRS_C_Options += " -DLMC_COLOR";
- @string %CMPLRS_C_Options += " -DSILGL -DSILGL_VRS=50";
-
-
-
-@endif;
-
+++ /dev/null
-// Created on: 2007-07-09
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2007-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <NIS_Drawer.hxx>
-#include <NIS_View.hxx>
-
-#include <OpenGl_GlCore11.hxx>
-
-//=======================================================================
-//function : NIS_DrawList()
-//purpose : Empty Constructor
-//=======================================================================
-
-NIS_DrawList::NIS_DrawList ()
-{
-#ifdef ARRAY_LISTS
- myListID = 0;
-#else
- myListID[0] = 0;
- myListID[1] = 0;
- myListID[2] = 0;
- myListID[3] = 0;
- myListID[4] = 0;
-#endif
- myIsUpdated[0] = Standard_True;
- myIsUpdated[1] = Standard_True;
- myIsUpdated[2] = Standard_True;
- myIsUpdated[3] = Standard_True;
- myIsUpdated[4] = Standard_True;
-}
-
-//=======================================================================
-//function : NIS_DrawList()
-//purpose : Constructor
-//=======================================================================
-
-NIS_DrawList::NIS_DrawList (const Handle(NIS_View)& theView)
- : myView (theView)
-{
-#ifdef ARRAY_LISTS
- myListID = 0;
-#else
- myListID[0] = 0;
- myListID[1] = 0;
- myListID[2] = 0;
- myListID[3] = 0;
- myListID[4] = 0;
-#endif
- myIsUpdated[0] = Standard_True;
- myIsUpdated[1] = Standard_True;
- myIsUpdated[2] = Standard_True;
- myIsUpdated[3] = Standard_True;
- myIsUpdated[4] = Standard_True;
-}
-
-//=======================================================================
-//function : ~NIS_DrawList
-//purpose :
-//=======================================================================
-
-NIS_DrawList::~NIS_DrawList ()
-{
- //if (myListID != 0)
- //glDeleteLists (myListID, 5);
-}
-
-//=======================================================================
-//function : ClearListID
-//purpose : Set myListID to 0.
-//=======================================================================
-
-void NIS_DrawList::ClearListID (const Standard_Integer theType)
-{
-#ifndef ARRAY_LISTS
- if (theType >= 0) {
- // To be called only in Callback context (i.e. when GL context is active)
- if (myListID[theType] > 0) {
- glDeleteLists(myListID[theType], 1);
- myListID[theType] = 0;
- }
- myIsUpdated[theType] = Standard_False;
- }
-#endif
-}
-
-//=======================================================================
-//function : ClearListID
-//purpose : Set myListID to 0.
-//=======================================================================
-
-void NIS_DrawList::ClearListID (const Handle(NIS_View)& theView)
-{
-#ifdef ARRAY_LISTS
- if (myListID > 0)
- myView->GetExListId().Add(myListID);
- myListID = 0;
-#else
- NIS_View * pView = (myView.IsNull()) ?
- theView.operator->() : myView.operator->();
- if (pView) {
- if (myListID[0] > 0)
- pView->GetExListId().Add(myListID[0]);
- myListID[0] = 0;
- if (myListID[1] > 0)
- pView->GetExListId().Add(myListID[1]);
- myListID[1] = 0;
- if (myListID[2] > 0)
- pView->GetExListId().Add(myListID[2]);
- myListID[2] = 0;
- if (myListID[3] > 0)
- pView->GetExListId().Add(myListID[3]);
- myListID[3] = 0;
- if (myListID[4] > 0)
- pView->GetExListId().Add(myListID[4]);
- myListID[4] = 0;
- }
-
-#endif
- myIsUpdated[0] = Standard_False;
- myIsUpdated[1] = Standard_False;
- myIsUpdated[2] = Standard_False;
- myIsUpdated[3] = Standard_False;
- myIsUpdated[4] = Standard_False;
-}
-
-//=======================================================================
-//function : BeginPrepare
-//purpose :
-//=======================================================================
-
-void NIS_DrawList::BeginPrepare (const Standard_Integer theType)
-{
-#ifdef ARRAY_LISTS
- if (myListID == 0)
- myListID = glGenLists(5);
-#else
- if (GetListID(theType) == 0)
- myListID[theType] = glGenLists(1);
-#endif
- glNewList (GetListID(theType), GL_COMPILE);
-}
-
-//=======================================================================
-//function : EndPrepare
-//purpose :
-//=======================================================================
-
-void NIS_DrawList::EndPrepare (const Standard_Integer theType)
-{
- glEndList ();
- myIsUpdated[theType] = Standard_False;
-}
-
-//=======================================================================
-//function : Call
-//purpose :
-//=======================================================================
-
-void NIS_DrawList::Call (const Standard_Integer theType)
-{
- glCallList (GetListID (theType));
-}
-
-//=======================================================================
-//function : SetDynHilighted
-//purpose :
-//=======================================================================
-
-Standard_Boolean NIS_DrawList::SetDynHilighted
- (const Standard_Boolean isHili,
- const Handle(NIS_InteractiveObject)& theObj)
-{
- Standard_Boolean aResult (Standard_False);
- NCollection_List<Handle(NIS_InteractiveObject)>::Iterator anIt(myDynHilighted);
- for (; anIt.More(); anIt.Next())
- if (anIt.Value() == theObj)
- break;
- if (anIt.More()) {
- if (isHili == Standard_False) {
- myIsUpdated[NIS_Drawer::Draw_DynHilighted] = Standard_True;
- myDynHilighted.Remove (anIt);
- aResult = Standard_True;
- }
- } else
- if (isHili == Standard_True) {
- myIsUpdated[NIS_Drawer::Draw_DynHilighted] = Standard_True;
- myDynHilighted.Append (theObj);
- aResult = Standard_True;
- }
- return aResult;
-}
-
-//=======================================================================
-//function : SetUpdated
-//purpose :
-//=======================================================================
-
-void NIS_DrawList::SetUpdated (const Standard_Integer theType,
- const Standard_Boolean theFlag)
-{
- if (theFlag)
- SetUpdated(theType);
- else
- myIsUpdated [theType] = Standard_False;
-}
-
-//=======================================================================
-//function : SetUpdated
-//purpose :
-//=======================================================================
-
-void NIS_DrawList::SetUpdated (const Standard_Integer theType)
-{
- myIsUpdated [theType] = Standard_True;
- if (theType == NIS_Drawer::Draw_Hilighted)
- myDynHilighted.Clear();
-}
+++ /dev/null
-// Created on: 2007-07-09
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2007-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#ifndef NIS_DrawList_HeaderFile
-#define NIS_DrawList_HeaderFile
-
-#include <Handle_NIS_View.hxx>
-#include <Handle_NIS_InteractiveObject.hxx>
-#include <NCollection_List.hxx>
-
-class NIS_InteractiveContext;
-/**
- * This macro defines that OpenGL draw lists will be allocated as array of 5
- * integers and any of them would not be deleted unless all interactive objects
- * in the given drawer are removed.
- * When the macro is undefined every draw list is created when needed and it is
- * destroyed when there is no objects to show in this draw list.
- */
-//#define ARRAY_LISTS
-
-/**
- * Implementation of a set of OpenGL draw lists for a given NIS_Drawer and
- * given NIS_View. Stored in NIS_Drawer instances.
- */
-
-class NIS_DrawList
-{
- public:
- // ---------- PUBLIC METHODS ----------
-
-
- /**
- * Empty constructor.
- */
- Standard_EXPORT NIS_DrawList ();
-
- /**
- * Constructor
- */
- Standard_EXPORT NIS_DrawList (const Handle(NIS_View)& theView);
-
- /**
- * Destructor.
- */
- Standard_EXPORT virtual ~NIS_DrawList ();
-
- /**
- * Query the list corresponding to the given type.
- * @param theType
- * Integer value coinciding with the enumerated NIS_Drawer:DrawType.
- */
- inline Standard_Integer GetListID (const Standard_Integer theType) const
-#ifdef ARRAY_LISTS
- { return myListID + theType; }
-#else
- { return myListID[theType]; }
-#endif
-
- /**
- * Set myListID to 0.
- * @return
- * Previous value of myListID
- */
- Standard_EXPORT void ClearListID (const Standard_Integer theType);
-
- /**
- * Set myListID to 0.
- * @return
- * Previous value of myListID
- */
- Standard_EXPORT void ClearListID (const Handle(NIS_View)& theView=NULL);
-
- /**
- * This method is called to start recording a new list. It must be eventually
- * followed by EndPrepare.
- * @param theType
- * Integer value coinciding with the enumerated NIS_Drawer::DrawType.
- */
- Standard_EXPORT virtual void BeginPrepare (const Standard_Integer theType);
-
- /**
- * This method is called to end recording a new list. It must be preceded
- * by BeginPrepare.
- * @param theType
- * Integer value coinciding with the enumerated NIS_Drawer::DrawType.
- */
- Standard_EXPORT virtual void EndPrepare (const Standard_Integer theType);
-
- /**
- * Call the previously prepared list when the screen is redrawn.
- * @param theType
- * Integer value coinciding with the enumerated NIS_Drawer::DrawType.
- */
- Standard_EXPORT virtual void Call (const Standard_Integer theType);
-
- /**
- * Query if the given list should be prepared again.
- * @param theType
- * Integer value coinciding with the enumerated NIS_Drawer::DrawType.
- */
- inline Standard_Boolean IsUpdated (const Standard_Integer theType) const
- { return myIsUpdated [theType]; }
-
- /**
- * Set the flag indicating that the List should be updated (rebuilt).
- */
- Standard_EXPORT void SetUpdated (const Standard_Integer theType);
-
- /**
- * Query if the given list should be processed by Dynamic Hilighting.
- */
- inline const NCollection_List<Handle(NIS_InteractiveObject)>&
- DynHilightedList() const
- { return myDynHilighted; }
-
- /**
- * Query the View.
- */
- inline const Handle(NIS_View)& GetView () const
- { return myView; }
-
- /**
- * Update the list of Dynamically Hilighted entities.
- */
- Standard_EXPORT Standard_Boolean SetDynHilighted
- (const Standard_Boolean isHilight,
- const Handle(NIS_InteractiveObject)& theObj);
-
- protected:
- // ---------- PROTECTED METHODS ----------
- Standard_EXPORT void SetUpdated (const Standard_Integer,
- const Standard_Boolean);
-
-#ifdef ARRAY_LISTS
- inline void SetListID (const Standard_Integer theID)
- { myListID = theID; }
-#endif
-
- private:
- // ---------- PRIVATE METHODS (PROHIBITED) ----------
- NIS_DrawList (const NIS_DrawList& theOther);
- // NIS_DrawList& operator = (const NIS_DrawList& theOther);
-
- private:
- // ---------- PRIVATE FIELDS ----------
-
- Handle(NIS_View) myView;
-#ifdef ARRAY_LISTS
- Standard_Integer myListID;
-#else
- Standard_Integer myListID[5];
-#endif
- Standard_Boolean myIsUpdated[5];
- NCollection_List<Handle(NIS_InteractiveObject)> myDynHilighted;
-};
-
-
-#endif
+++ /dev/null
-// Created on: 2007-07-06
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2007-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <NIS_Drawer.hxx>
-#include <NIS_View.hxx>
-#include <NIS_InteractiveContext.hxx>
-#include <NIS_InteractiveObject.hxx>
-#include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
-#include <Standard_TypeMismatch.hxx>
-#include <Standard_NoSuchObject.hxx>
-
-IMPLEMENT_STANDARD_HANDLE (NIS_Drawer, Standard_Transient)
-IMPLEMENT_STANDARD_RTTIEXT (NIS_Drawer, Standard_Transient)
-
-//=======================================================================
-//function : NIS_Drawer
-//purpose : Destructor
-//=======================================================================
-
-NIS_Drawer::~NIS_Drawer ()
-{
- NCollection_List<NIS_DrawList*>::Iterator anIter (myLists);
- for (; anIter.More(); anIter.Next())
- delete anIter.Value();
-}
-
-//=======================================================================
-//function : Assign
-//purpose :
-//=======================================================================
-
-void NIS_Drawer::Assign (const Handle(NIS_Drawer)& theOther)
-{
- if (theOther->IsKind(DynamicType()) == Standard_False)
- Standard_TypeMismatch::Raise ("NIS_Drawer::Assign");
- myIniId = theOther->myIniId;
- myObjPerDrawer = theOther->myObjPerDrawer;
- myTransparency = theOther->myTransparency;
-}
-
-//=======================================================================
-//function : HashCode
-//purpose :
-//=======================================================================
-
-Standard_Integer NIS_Drawer::HashCode(const Standard_Integer theN) const
-{
- Standard_Integer aKey = ::HashCode (DynamicType(), theN);
- aKey += (myIniId / myObjPerDrawer);
- return ((aKey & 0x7fffffff) % theN) + 1;
-}
-
-//=======================================================================
-//function : IsEqual
-//purpose :
-//=======================================================================
-
-Standard_Boolean NIS_Drawer::IsEqual (const Handle(NIS_Drawer)& theOther) const
-{
- Standard_Boolean aResult (Standard_False);
- if (theOther.IsNull() == Standard_False)
- if (DynamicType() == theOther->DynamicType())
- if (theOther->myIniId/theOther->myObjPerDrawer == myIniId/myObjPerDrawer)
- aResult = Standard_True;
-
- if (aResult)
- if (fabs(myTransparency - theOther->myTransparency) > 0.01)
- aResult = Standard_False;
-
- return aResult;
-}
-
-//=======================================================================
-//function : BeforeDraw
-//purpose : Called before Draw(), once per group of interactive objects.
-//=======================================================================
-
-void NIS_Drawer::BeforeDraw (const DrawType, const NIS_DrawList&)
-{
-}
-
-//=======================================================================
-//function : AfterDraw
-//purpose : Called after Draw(), once per group of interactive objects.
-//=======================================================================
-
-void NIS_Drawer::AfterDraw (const DrawType, const NIS_DrawList&)
-{
-}
-
-//=======================================================================
-//function : UpdateExListId
-//purpose :
-//=======================================================================
-
-void NIS_Drawer::UpdateExListId (const Handle(NIS_View)& theView) const
-{
- if (theView.IsNull()) {
- if (myCtx) {
- if (myCtx->myViews.IsEmpty() == Standard_False) {
- const Handle(NIS_View)& aView = myCtx->myViews.First();
- NCollection_List<NIS_DrawList *>::Iterator anIterL(myLists);
- for (; anIterL.More(); anIterL.Next()) {
- NIS_DrawList * const pList = anIterL.Value();
- pList->ClearListID(aView);
- }
- }
- }
- } else {
- NCollection_List<NIS_DrawList *>::Iterator anIterL(myLists);
- for (; anIterL.More(); anIterL.Next()) {
- NIS_DrawList * const pList = anIterL.Value();
- if (pList->GetView() == theView) {
- pList->ClearListID(theView);
- break;
- }
- }
- }
-}
-
-//=======================================================================
-//function : redraw
-//purpose :
-//=======================================================================
-
-void NIS_Drawer::redraw (const DrawType theType,
- const Handle(NIS_View)& theView)
-{
- if (myCtx &&
- myMapID.IsEmpty() == Standard_False &&
- theView.IsNull() == Standard_False)
- {
- NCollection_List<NIS_DrawList*>::Iterator anIter (myLists);
- for (; anIter.More(); anIter.Next()) {
- NIS_DrawList& aDrawList = * anIter.ChangeValue();
- const Handle(NIS_View)& aView = aDrawList.GetView();
- if (aView == theView || aView.IsNull()) {
- if (aDrawList.IsUpdated(theType)) {
- // Get the IDs of objects concerned
- TColStd_PackedMapOfInteger mapObj;
- mapObj.Intersection (myCtx->myMapObjects[theType], myMapID);
-#ifndef ARRAY_LISTS
- // Release the list that is no more in use
- if (mapObj.IsEmpty() && theType != Draw_DynHilighted) {
- aDrawList.ClearListID(theType);
- break;
- }
-#endif
- aDrawList.BeginPrepare(theType);
- prepareList (theType, aDrawList, mapObj);
- aDrawList.EndPrepare(theType);
- }
- if (aDrawList.GetListID(theType) > 0)
- aDrawList.Call(theType);
- break;
- }
- }
- }
-}
-
-//=======================================================================
-//function : SetUpdated
-//purpose :
-//=======================================================================
-
-void NIS_Drawer::SetUpdated (const DrawType theType) const
-{
- NCollection_List<NIS_DrawList*>::Iterator anIter (myLists);
- for (; anIter.More(); anIter.Next()) {
- NIS_DrawList& aDrawList = * anIter.ChangeValue();
- aDrawList.SetUpdated (theType);
- }
- const_cast<Bnd_B3f&>(myBox).Clear();
-}
-
-//=======================================================================
-//function : SetUpdated
-//purpose :
-//=======================================================================
-
-void NIS_Drawer::SetUpdated (const DrawType theType1,
- const DrawType theType2) const
-{
- NCollection_List<NIS_DrawList*>::Iterator anIter (myLists);
- for (; anIter.More(); anIter.Next()) {
- NIS_DrawList& aDrawList = * anIter.ChangeValue();
- aDrawList.SetUpdated (theType1);
- aDrawList.SetUpdated (theType2);
- }
- const_cast<Bnd_B3f&>(myBox).Clear();
-}
-
-//=======================================================================
-//function : SetUpdated
-//purpose :
-//=======================================================================
-
-
-void NIS_Drawer::SetUpdated (const DrawType theType1,
- const DrawType theType2,
- const DrawType theType3) const
-{
- NCollection_List<NIS_DrawList*>::Iterator anIter (myLists);
- for (; anIter.More(); anIter.Next()) {
- NIS_DrawList& aDrawList = * anIter.ChangeValue();
- aDrawList.SetUpdated (theType1);
- aDrawList.SetUpdated (theType2);
- aDrawList.SetUpdated (theType3);
- }
- const_cast<Bnd_B3f&>(myBox).Clear();
-}
-
-//=======================================================================
-//function : SetUpdated
-//purpose :
-//=======================================================================
-
-
-void NIS_Drawer::SetUpdated (const DrawType theType1,
- const DrawType theType2,
- const DrawType theType3,
- const DrawType theType4) const
-{
- NCollection_List<NIS_DrawList*>::Iterator anIter (myLists);
- for (; anIter.More(); anIter.Next()) {
- NIS_DrawList& aDrawList = * anIter.ChangeValue();
- aDrawList.SetUpdated (theType1);
- aDrawList.SetUpdated (theType2);
- aDrawList.SetUpdated (theType3);
- aDrawList.SetUpdated (theType4);
- }
- const_cast<Bnd_B3f&>(myBox).Clear();
-}
-
-//=======================================================================
-//function : SetDynamicHilighted
-//purpose :
-//=======================================================================
-
-void NIS_Drawer::SetDynamicHilighted
- (const Standard_Boolean isHilighted,
- const Handle(NIS_InteractiveObject)& theObj,
- const Handle(NIS_View)& theView)
-{
- if (myCtx && theObj.IsNull() == Standard_False) {
- NCollection_List<NIS_DrawList*>::Iterator anIter (myLists);
- if (theView.IsNull()) {
- for (; anIter.More(); anIter.Next()) {
- NIS_DrawList& aDrawList = * anIter.ChangeValue();
- aDrawList.SetDynHilighted (isHilighted, theObj);
- aDrawList.SetUpdated (Draw_DynHilighted);
- }
- theObj->myIsDynHilighted = isHilighted;
- } else
- for (; anIter.More(); anIter.Next()) {
- NIS_DrawList& aDrawList = * anIter.ChangeValue();
- const Handle(NIS_View)& aView = aDrawList.GetView();
- if (aView == theView || aView.IsNull()) {
- aDrawList.SetDynHilighted (isHilighted, theObj);
- theObj->myIsDynHilighted = isHilighted;
- aDrawList.SetUpdated (Draw_DynHilighted);
- }
- }
- }
-}
-
-//=======================================================================
-//function : removeObject
-//purpose :
-//=======================================================================
-
-void NIS_Drawer::removeObject (const NIS_InteractiveObject * theObj,
- const Standard_Boolean isUpdateViews)
-{
- const Standard_Integer anID = theObj->ID();
- myMapID.Remove (anID);
- // Stop dynamic hilighting if it has been activated
- if (theObj->IsDynHilighted())
- SetDynamicHilighted (Standard_False, theObj);
- if (myMapID.IsEmpty()) {
- UpdateExListId(NULL);
- // Remove the drawer from context.
- myCtx->myDrawers.Remove(this);
- }
- // Set Updated for the draw type.
- else if (theObj->IsHidden() == Standard_False && isUpdateViews)
- SetUpdated (theObj->DrawType());
-}
-
-//=======================================================================
-//function : addObject
-//purpose :
-//=======================================================================
-
-void NIS_Drawer::addObject (const NIS_InteractiveObject * theObj,
- const Standard_Boolean isShareList,
- const Standard_Boolean isUpdateViews)
-{
- myMapID.Add (theObj->ID());
-
- // Fill the drawer (if new) with DrawList instances for available Views.
- if ( myLists.IsEmpty())
- {
- if (isShareList)
- myLists.Append (createDefaultList(NULL));
- else {
- NCollection_List<Handle(NIS_View)>::Iterator anIter(GetContext()->myViews);
- for (; anIter.More(); anIter.Next())
- myLists.Append (createDefaultList(anIter.Value()));
- }
- }
-
- if (theObj->IsHidden() == Standard_False && isUpdateViews)
- SetUpdated (theObj->DrawType());
-}
-
-//=======================================================================
-//function : GetBox
-//purpose :
-//=======================================================================
-
-const Bnd_B3f& NIS_Drawer::GetBox (const NIS_View * pView) const
-{
- if (myBox.IsVoid()) {
- if (myCtx) {
- TColStd_MapIteratorOfPackedMapOfInteger anIter;
- if (pView == 0L)
- anIter.Initialize (myMapID);
- else {
- NCollection_List<NIS_DrawList*>::Iterator anIterL (myLists);
- for (; anIterL.More(); anIterL.Next()) {
- NIS_DrawList& aDrawList = * anIterL.ChangeValue();
- const Handle(NIS_View)& aView = aDrawList.GetView();
- if (aView.IsNull() || aView.operator->() == pView)
- break;
- }
- if (anIterL.More())
- anIter.Initialize (myMapID);
- }
-
- for (; anIter.More(); anIter.Next()) {
- const Handle(NIS_InteractiveObject)& anObj =
- myCtx->GetObject(anIter.Key());
- if (anObj.IsNull() == Standard_False)
- if (anObj->IsHidden() == Standard_False)
- const_cast<Bnd_B3f&>(myBox).Add (anObj->GetBox());
- }
- }
- }
- return myBox;
-}
-
-
-//=======================================================================
-//function : prepareList
-//purpose :
-//=======================================================================
-void NIS_Drawer::prepareList(const NIS_Drawer::DrawType theType,
- const NIS_DrawList& theDrawList,
- const TColStd_PackedMapOfInteger& mapObj)
-{
- if (!myCtx)
- return;
-
- // Dynamic hilighting is treated in a separate loop because the hilighted
- // instances are contained in the special list rather than in the Context
- if (theType == NIS_Drawer::Draw_DynHilighted) {
- NCollection_List<Handle(NIS_InteractiveObject)>::Iterator
- anIter (theDrawList.DynHilightedList());
- if (anIter.More()) {
- BeforeDraw (theType, theDrawList);
- for (; anIter.More(); anIter.Next())
- Draw (anIter.Value(), NIS_Drawer::Draw_DynHilighted, theDrawList);
- AfterDraw (theType, theDrawList);
- }
- } else {
- // The common part of two maps (objects for this draw type & objects in
- // the current Drawer) is used for updating the presentation.
- TColStd_MapIteratorOfPackedMapOfInteger anIter (mapObj);
- if (anIter.More()) {
- BeforeDraw (theType, theDrawList);
- for (; anIter.More(); anIter.Next()) {
- const Handle(NIS_InteractiveObject)& anObj =
- myCtx->GetObject(anIter.Key());
- if (anObj.IsNull() == Standard_False)
- if (anObj->IsHidden() == Standard_False)
- Draw (anObj, theType, theDrawList);
- }
- AfterDraw (theType, theDrawList);
- }
- }
-}
-
-//=======================================================================
-//function : createDefaultList
-//purpose :
-//=======================================================================
-NIS_DrawList* NIS_Drawer::createDefaultList
- (const Handle(NIS_View)& theView) const
-{
- return new NIS_DrawList(theView);
-}
+++ /dev/null
-// Created on: 2007-07-06
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2007-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#ifndef NIS_Drawer_HeaderFile
-#define NIS_Drawer_HeaderFile
-
-#include <Standard_Transient.hxx>
-#include <NCollection_List.hxx>
-#include <TColStd_PackedMapOfInteger.hxx>
-#include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
-#include <NIS_DrawList.hxx>
-#include <Bnd_B3f.hxx>
-
-#ifdef WNT
-#pragma warning (push)
-// Disable warning 4480: nonstandard extension used: specifying underlying type for enum 'enum'
-#pragma warning (disable:4480)
-#endif
-
-class Handle(NIS_InteractiveObject);
-class Handle(NIS_View);
-class Handle(NIS_Drawer);
-class NIS_InteractiveContext;
-class NIS_View;
-template <class A> class NCollection_Vector;
-
-/**
- * Abstract Drawer type.
- * Drawer provides the immediate OpenGL drawing for every NIS_InteractiveObject
- * maneged by the given Drawer instance. Each Drawer instance has reciprocal
- * link with a number of NIS_InteractiveObject instances of the same
- * (corresponding to Drawer) type. The idea is to group the drawing for all
- * referred interactive objects using the same pre- and post-treatment like
- * color setting, matrix, polygon offset, line thickness and what not.
- *
- * @section nis_drawer_visualprop Visual properties of Drawer
- * Normally visual properties of any NIS_InteractiveObject are stored in its
- * Drawer instance, but not in an object. For example, if an interactive object
- * has method SetColor() then the color is stored in the corresponding Drawer
- * rather than in the interactive object itself. This scheme avoid useless
- * duplication when a lot of objects have similar properties like color. Please
- * see @see nis_interactiveobject_drawer to learn how this mechanism
- * works from the side of NIS_InteractiveObject.
- *
- * @section nis_drawer_drawing Drawing
- * There are 3 virtual methods to implement OpenGL drawing in this API. They
- * define the drawing cycle that consists of filling the internal OpenGL draw
- * list with commands. This drawing cycle is triggered when the corresponding
- * internal instance of NIS_DrawList has 'IsUpdated' flag (you can set this
- * flag by means of public methods NIS_Drawer::SetUpdated()).
- * <ul>
- * <li><b>BeforeDraw()</b> : contains all OpenGL commands that define the
- * common set of visual properties for all managed interactive objects.
- * This method is called once in the beginning of drawing cycle for the
- * Drawer instance</li>
- * <li><b>Draw()</b> : all OpenGL commands that are specific to a given
- * interactive object, usually definition of vertices, triangles, lines,
- * or their arrays.</li>
- * <li><b>AfterDraw()</b> : commands that revert the status of OpenGL context
- * to the state before execution of BeforeDraw(). This method is called
- * once in the end of drawing cycle.</li>
- * </ul>
- * Each of these methods receives NIS_DrawList and DrawType, both identify the
- * OpenGL draw list that should be filled with commands. Based on DrawType
- * you will be able to define different presentation - the most important case
- * is how hilighted (selected) interactive object is presented.
- * <p>
- * For advanced purposes you also can redefine the virtual method redraw(), it
- * is dedicated to higher-level management of draw lists and ordering of
- * their update when necessary.
- *
- * @section nis_drawer_distinction Distinction of Drawer instances
- * Every Drawer should define which interactive objects it may manage and
- * which - may not. The same idea could be shaped alternatively: every
- * interactive object should understand to what Drawer it can attach itself.
- * This question is answerd by special virtual method IsEqual() that compares
- * two Drawers of the same type. <b>Two instances of Drawer are equal if they
- * have the same set of visual properties that are implemented in BeforeDraw().
- * </b> The method IsEqual() is the core of Drawer architecture and it must
- * be implemented very carefully for any new type. Particularly, for any
- * derived class the method IsEqual() should first call the same method of
- * its superclass.
- * <p>
- * For the optimal efficiency of OpenGL drawing it is better to keep the size
- * of draw list (i.e., the number of interactive objects in a Drawer instance)
- * not too small and not too big. The latter limitation is entered by the
- * protected field myObjPerDrawer. It is used in method IsEqual() of the base
- * Drawer class: two Drawers are not equal if they are initialized on objects
- * that have too different IDs -- even if all visual properties of these two
- * Drawer instances coincide.
- * <p>
- * @section nis_drawer_cloning Cloning Drawer instances
- * It is possible to clone a Drawer instance with the viryual method Assign().
- * This method copies all visual properties and other important data from the
- * Drawer provided as parameter. Method Clone() also should be very carefully
- * implemented for any new Drawer type, to make sure that all necessary data
- * fields and structures are properly copied.
- */
-
-class NIS_Drawer : public Standard_Transient
-{
- public:
-#if defined(WNT) && (_MSC_VER >= 1400)
- enum DrawType : unsigned int {
-#else
- enum DrawType {
-#endif
- Draw_Normal = 0,
- Draw_Top = 1,
- Draw_Transparent = 2,
- Draw_Hilighted = 3,
- Draw_DynHilighted = 4
- };
-
- public:
- // ---------- PUBLIC METHODS ----------
-
-
- /**
- * Empty constructor.
- */
- inline NIS_Drawer ()
- : myTransparency (0.f),
- myIniId (0),
- myObjPerDrawer (1024),
- myCtx (0L)
- {}
-
- /**
- * Destructor.
- */
- Standard_EXPORT virtual ~NIS_Drawer ();
-
- /**
- * Query the Interactive Context.
- */
- inline NIS_InteractiveContext * GetContext () const
- { return myCtx; }
-
- /**
- * Copy the relevant information from another instance of Drawer.
- * raises exception if theOther has incompatible type (test IsKind).
- */
- Standard_EXPORT virtual void Assign (const Handle(NIS_Drawer)& theOther);
-
- /**
- * Create a3D bounding box of drawn objects.
- * @param pView
- * In not NULL, only objects visible in this view are taken.
- */
- Standard_EXPORT virtual const Bnd_B3f&
- GetBox (const NIS_View * pView = 0L) const;
-
- /**
- * Mark all draw lists for update
- */
- Standard_EXPORT void SetUpdated (const DrawType theType) const;
-
- Standard_EXPORT void SetUpdated (const DrawType theType1,
- const DrawType theType2) const;
-
- Standard_EXPORT void SetUpdated (const DrawType theType1,
- const DrawType theType2,
- const DrawType theType3) const;
-
- Standard_EXPORT void SetUpdated (const DrawType theType1,
- const DrawType theType2,
- const DrawType theType3,
- const DrawType theType4) const;
-
- /**
- * Switch on/off the dynamic hilight of the given object in the
- * given view.
- * @param isHilighted
- * True if the object should be hilighted, False - if not hilighted
- * @param theObj
- * Object instance that should be hilighted or unhilighted.
- * @param theView
- * View where the status of object must be changed. If NULL, the object
- * is hilighted/unhilighted in all views.
- */
- Standard_EXPORT void SetDynamicHilighted
- (const Standard_Boolean isHilighted,
- const Handle(NIS_InteractiveObject)& theObj,
- const Handle(NIS_View)& theView = 0L);
-
- /**
- * Hash value, for Map interface.
- */
- Standard_EXPORT virtual Standard_Integer
- HashCode(const Standard_Integer theN) const;
-
- /**
- * Matching two instances, for Map interface.
- */
- Standard_EXPORT virtual Standard_Boolean
- IsEqual (const Handle(NIS_Drawer)& theOth) const;
-
- /**
- * Obtain the iterator of IDs of associated objects.
- */
- inline TColStd_MapIteratorOfPackedMapOfInteger
- ObjectIterator () const
- { return TColStd_MapIteratorOfPackedMapOfInteger (myMapID); }
-
- /**
- * Query associated draw lists.
- */
- inline NCollection_List<NIS_DrawList *>
- GetLists() const
- { return myLists; }
-
-protected:
- /**
- * Called to add draw list IDs to ex-list Ids of view. These draw lists are
- * eventually released in the callback function, before anything is displayed
- */
- Standard_EXPORT void UpdateExListId (const Handle(NIS_View)& theView) const;
-
- // ---------- PROTECTED METHODS ----------
-
- /**
- * Called before execution of Draw(), once per group of interactive objects.
- */
- Standard_EXPORT virtual void BeforeDraw
- (const DrawType theType,
- const NIS_DrawList& theDrawList );
-
- /**
- * Called after execution of Draw(), once per group of interactive objects.
- */
- Standard_EXPORT virtual void AfterDraw
- (const DrawType theType,
- const NIS_DrawList& theDrawList);
-
- /**
- * Main function: display the given interactive object in the given view.
- */
- Standard_EXPORT virtual void Draw (const Handle(NIS_InteractiveObject)&,
- const DrawType theType,
- const NIS_DrawList& theDrawList)= 0;
-
- Standard_EXPORT virtual void redraw (const DrawType theType,
- const Handle(NIS_View)& theView);
-
- Standard_EXPORT void addObject (const NIS_InteractiveObject * theObj,
- const Standard_Boolean isShareList,
- const Standard_Boolean isUpVws);
-
- Standard_EXPORT void removeObject (const NIS_InteractiveObject * theObj,
- const Standard_Boolean isUpVws);
-
- Standard_EXPORT virtual NIS_DrawList*
- createDefaultList (const Handle(NIS_View)&) const;
-
- protected:
- //! Get the number of interactive objects in this drawer
- inline Standard_Integer NObjects() const
- { return myMapID.Extent(); }
-
- private:
- // ---------- PRIVATE (PROHIBITED) METHODS ----------
-
- NIS_Drawer (const NIS_Drawer& theOther);
- NIS_Drawer& operator = (const NIS_Drawer& theOther);
-
- // ---------- PRIVATE METHODS ----------
- void prepareList (const NIS_Drawer::DrawType theType,
- const NIS_DrawList& theDrawLst,
- const TColStd_PackedMapOfInteger& mapObj);
-
- protected:
-// ---------- PROTECTED FIELDS ----------
- NCollection_List<NIS_DrawList*> myLists;
- Standard_ShortReal myTransparency;
- //! ID of the initializing InteractiveObject. It is never changed, can be
- //! used to compute hash code of the Drawer instance.
- Standard_Integer myIniId;
- //! Maximal range of IDs of objects in one drawer. Limits the size of
- //! draw lists. Can be initialized only in constructor (default 1024). It is
- //! strictly prohibited to change this value outside the constructor.
- Standard_Integer myObjPerDrawer;
-
- private:
- // ---------- PRIVATE FIELDS ----------
-
- NIS_InteractiveContext * myCtx;
- TColStd_PackedMapOfInteger myMapID;
- Bnd_B3f myBox;
-
- friend class NIS_InteractiveContext;
- friend class NIS_InteractiveObject;
- friend class NIS_View;
-
- public:
-// Declaration of CASCADE RTTI
-DEFINE_STANDARD_RTTI (NIS_Drawer)
-};
-
-// Definition of HANDLE object using Standard_DefineHandle.hxx
-DEFINE_STANDARD_HANDLE (NIS_Drawer, Standard_Transient)
-
-//=======================================================================
-//function : HashCode
-//purpose :
-//=======================================================================
-
-inline Standard_Integer HashCode (const Handle(NIS_Drawer)& theDrawer,
- const Standard_Integer theN)
-{ return theDrawer.IsNull() ? 0 : theDrawer->HashCode (theN); }
-
-//=======================================================================
-//function : IsEqual
-//purpose :
-//=======================================================================
-
-inline Standard_Boolean IsEqual (const Handle(NIS_Drawer)& theDrawer1,
- const Handle(NIS_Drawer)& theDrawer2)
-{ return theDrawer1.IsNull()? Standard_False: theDrawer1->IsEqual(theDrawer2); }
-
-#ifdef WNT
-#pragma warning (pop)
-#endif
-
-#endif
+++ /dev/null
-// Created on: 2007-07-06
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2007-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <NIS_InteractiveContext.hxx>
-#include <NIS_InteractiveObject.hxx>
-#include <NIS_View.hxx>
-#include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
-#include <Standard_NoSuchObject.hxx>
-#include <Bnd_B2f.hxx>
-
-IMPLEMENT_STANDARD_HANDLE (NIS_InteractiveContext, Standard_Transient)
-IMPLEMENT_STANDARD_RTTIEXT (NIS_InteractiveContext, Standard_Transient)
-
-static void markAllDrawersUpdated (const NCollection_Map<Handle(NIS_Drawer)>&);
-
-//=======================================================================
-//function : NIS_InteractiveContext()
-//purpose : Constructor
-//=======================================================================
-
-NIS_InteractiveContext::NIS_InteractiveContext ()
- : myAllocator (new NIS_Allocator(1024*100)),
- myLastObjectId (0),
- myObjects (1000),
-// myDrawers (101, myAllocator),
- mySelectionMode (Mode_NoSelection),
- myIsShareDrawList (Standard_True)
-{
- // ID == 0 is invalid so we reserve this item from subsequent allocation.
- myObjects.SetValue(myLastObjectId, NULL);
-}
-
-//=======================================================================
-//function : ~NIS_InteractiveContext
-//purpose : Destructor
-//=======================================================================
-
-NIS_InteractiveContext::~NIS_InteractiveContext ()
-{
- // Unregister this context in all referred views
- NCollection_List<Handle(NIS_View)>::Iterator anIterV (myViews);
- for (; anIterV.More(); anIterV.Next())
- if (anIterV.Value().IsNull() == Standard_False)
- anIterV.Value()->RemoveContext(this);
-
-// // Unregister this context in all referred drawers
-// NCollection_Map<Handle(NIS_Drawer)>::Iterator anIterD (myDrawers);
-// for (; anIterD.More(); anIterD.Next())
-// if (anIterD.Value().IsNull() == Standard_False)
-// anIterD.Value()->myCtx = 0L;
-}
-
-
-//=======================================================================
-//function : AttachView
-//purpose :
-//=======================================================================
-
-void NIS_InteractiveContext::AttachView (const Handle(NIS_View)& theView)
-{
- if (theView.IsNull() == Standard_False) {
- NCollection_List<Handle(NIS_View)>::Iterator anIter (myViews);
- for (; anIter.More(); anIter.Next())
- if (anIter.Value() == theView)
- break;
- if (anIter.More() == Standard_False) {
- myViews.Append (theView);
- theView->AddContext (this);
- NCollection_Map<Handle(NIS_Drawer)>::Iterator anIterD (myDrawers);
- for (; anIterD.More(); anIterD.Next()) {
- const Handle(NIS_Drawer)& aDrawer = anIterD.Value();
- if (aDrawer.IsNull() == Standard_False)
- aDrawer->myLists.Append(aDrawer->createDefaultList(theView));
- }
- }
- }
-}
-
-//=======================================================================
-//function : DetachView
-//purpose :
-//=======================================================================
-
-void NIS_InteractiveContext::DetachView (const Handle(NIS_View)& theView)
-{
- if (theView.IsNull() == Standard_False) {
- NCollection_List<Handle(NIS_View)>::Iterator anIter (myViews);
- for (; anIter.More(); anIter.Next())
- if (anIter.Value() == theView) {
- myViews.Remove(anIter);
- theView->RemoveContext(this);
- NCollection_Map<Handle(NIS_Drawer)>::Iterator anIterD (myDrawers);
- for (; anIterD.More(); anIterD.Next()) {
- const Handle(NIS_Drawer)& aDrawer = anIterD.Value();
- if (aDrawer.IsNull() == Standard_False) {
- NCollection_List<NIS_DrawList*>::Iterator anIterL(aDrawer->myLists);
- for (; anIterL.More(); anIterL.Next())
- if (anIterL.Value()->GetView() == theView) {
- delete anIterL.Value();
- aDrawer->myLists.Remove (anIterL);
- break;
- }
- }
- }
- break;
- }
- }
-}
-
-//=======================================================================
-//function : GetObject
-//purpose :
-//=======================================================================
-
-const Handle(NIS_InteractiveObject)& NIS_InteractiveContext::GetObject
- (const Standard_Integer theID) const
-{
- if (!myObjects.IsBound(theID))
- {
- static Handle(NIS_InteractiveObject) aNull;
- return aNull;
- }
- return myObjects(theID);
-}
-
-//=======================================================================
-//function : redraw
-//purpose :
-//=======================================================================
-
-void NIS_InteractiveContext::redraw (const Handle(NIS_View)& theView,
- const NIS_Drawer::DrawType theType)
-{
- NCollection_Map <Handle(NIS_Drawer)>::Iterator anIter (myDrawers);
- for (; anIter.More(); anIter.Next())
- if (anIter.Value().IsNull() == Standard_False)
- anIter.Value()->redraw (theType, theView);
-}
-
-//=======================================================================
-//function : GetBox
-//purpose :
-//=======================================================================
-
-void NIS_InteractiveContext::GetBox (Bnd_B3f& theBox,
- const NIS_View * theView) const
-{
- NCollection_Map <Handle(NIS_Drawer)>::Iterator anIterD (myDrawers);
- for (; anIterD.More(); anIterD.Next())
- if (anIterD.Value().IsNull() == Standard_False)
- theBox.Add(anIterD.Value()->GetBox(theView));
-}
-
-//=======================================================================
-//function : Display
-//purpose :
-//=======================================================================
-
-void NIS_InteractiveContext::Display
- (Handle(NIS_InteractiveObject)& theObj,
- const Handle(NIS_Drawer)& theDrawer,
- const Standard_Boolean isUpdateViews)
-{
- if (theObj.IsNull())
- return;
- objectForDisplay(theObj, theObj->DrawType());
- const Handle(NIS_Drawer)& aDrawer = drawerForDisplay(theObj, theDrawer);
- // Display Object as Normal or Transparent if it has been hidden
- if (theObj->IsHidden())
- theObj->myIsHidden = Standard_False;
-
- // Set Update flag in the Drawer
- if (isUpdateViews)
- aDrawer->SetUpdated (theObj->DrawType());
-}
-
-//=======================================================================
-//function : DisplayOnTop
-//purpose :
-//=======================================================================
-
-void NIS_InteractiveContext::DisplayOnTop
- (Handle(NIS_InteractiveObject)& theObj,
- const Handle(NIS_Drawer)& theDrawer,
- const Standard_Boolean isUpdateViews)
-{
- if (theObj.IsNull())
- return;
-
- objectForDisplay(theObj, NIS_Drawer::Draw_Top);
- const Handle(NIS_Drawer)& aDrawer = drawerForDisplay(theObj, theDrawer);
-
- // Display Object as Normal or Transparent if it has been hidden
- if (theObj->IsHidden())
- theObj->myIsHidden = Standard_False;
-
- // Set Update flag in the Drawer
- if (isUpdateViews)
- aDrawer->SetUpdated (theObj->DrawType());
-}
-
-//=======================================================================
-//function : Erase
-//purpose :
-//=======================================================================
-
-void NIS_InteractiveContext::Erase (const Handle(NIS_InteractiveObject)& theObj,
- const Standard_Boolean isUpdateViews)
-{
- if (theObj->IsHidden() == Standard_False) {
- theObj->myIsHidden = Standard_True;
- const Handle(NIS_Drawer)& aDrawer = theObj->GetDrawer();
- if (aDrawer.IsNull() == Standard_False) {
- // Unhilight the erased object
- if (theObj->IsDynHilighted()) {
- NCollection_List<Handle(NIS_View)>::Iterator anIterV (myViews);
- for (; anIterV.More(); anIterV.Next())
- if (anIterV.Value().IsNull() == Standard_False)
- anIterV.Value()->DynamicUnhilight (theObj);
- }
- // Update status of lists
- if (isUpdateViews)
- aDrawer->SetUpdated(theObj->DrawType());
- }
- }
-}
-
-//=======================================================================
-//function : Remove
-//purpose :
-//=======================================================================
-
-void NIS_InteractiveContext::Remove (const Handle(NIS_InteractiveObject)& theObj,
- const Standard_Boolean isUpdateViews)
-{
- if (theObj.IsNull() == Standard_False) {
- const Handle(NIS_Drawer)& aDrawer = theObj->GetDrawer();
- if ( aDrawer.IsNull() )
- return;
- if (aDrawer->myCtx == this) {
- // Remove the hilighting if the object has been hilighted
- if (theObj->IsDynHilighted()) {
- NCollection_List<Handle(NIS_View)>::Iterator anIterV (myViews);
- for (; anIterV.More(); anIterV.Next())
- if (anIterV.Value().IsNull() == Standard_False)
- anIterV.Value()->DynamicUnhilight (theObj);
- }
- // Remove the object from the context
- const Standard_Integer anID = theObj->ID();
- const NIS_Drawer::DrawType aDrawType (theObj->DrawType());
- if (myMapObjects[Standard_Integer(aDrawType)].Remove(anID))
- aDrawer->removeObject(theObj.operator->(), isUpdateViews);
- theObj->myID = 0;
- theObj->myDrawer.Nullify();
- myObjects.UnsetValue(anID);
- myMapNonSelectableObjects.Remove(anID);
- }
- }
-}
-
-//=======================================================================
-//function : DisplayAll
-//purpose :
-//=======================================================================
-
-void NIS_InteractiveContext::DisplayAll ()
-{
- // UnHide all objects in the Context
- NCollection_SparseArray <Handle(NIS_InteractiveObject)>::ConstIterator
- anIter(myObjects);
- for (; anIter.More(); anIter.Next()) {
- const Handle(NIS_InteractiveObject)& anObj = anIter.Value();
- if (anObj.IsNull() == Standard_False)
- if (anObj->IsHidden())
- anObj->myIsHidden = Standard_False;
- }
-
- // Update status of objects in Drawers (particularly cancel dyn. hilighting)
- NCollection_Map<Handle(NIS_Drawer)>::Iterator anIterD (myDrawers);
- for (; anIterD.More(); anIterD.Next()) {
- const Handle(NIS_Drawer)& aDrawer = anIterD.Value();
- if (aDrawer.IsNull() == Standard_False) {
- aDrawer->SetUpdated (NIS_Drawer::Draw_Normal,
- NIS_Drawer::Draw_Top,
- NIS_Drawer::Draw_Transparent,
- NIS_Drawer::Draw_Hilighted);
- }
- }
-}
-
-//=======================================================================
-//function : EraseAll
-//purpose :
-//=======================================================================
-
-void NIS_InteractiveContext::EraseAll ()
-{
- // Hide all objects in the Context
- NCollection_SparseArray <Handle(NIS_InteractiveObject)>::ConstIterator
- anIter(myObjects);
- for (; anIter.More(); anIter.Next()) {
- const Handle(NIS_InteractiveObject)& anObj = anIter.Value();
- if (anObj.IsNull() == Standard_False) {
- if (anObj->IsHidden() == Standard_False)
- anObj->myIsHidden = Standard_True;
- if (anObj->IsDynHilighted()) {
- NCollection_List<Handle(NIS_View)>::Iterator anIterV (myViews);
- for (; anIterV.More(); anIterV.Next())
- if (anIterV.Value().IsNull() == Standard_False)
- anIterV.Value()->DynamicUnhilight (anObj);
- }
- }
- }
-
- // Update status of objects in Drawers (particularly cancel dyn. hilighting)
- NCollection_Map<Handle(NIS_Drawer)>::Iterator anIterD (myDrawers);
- for (; anIterD.More(); anIterD.Next()) {
- const Handle(NIS_Drawer)& aDrawer = anIterD.Value();
- if (aDrawer.IsNull() == Standard_False) {
- aDrawer->SetUpdated (NIS_Drawer::Draw_Normal,
- NIS_Drawer::Draw_Top,
- NIS_Drawer::Draw_Transparent,
- NIS_Drawer::Draw_Hilighted);
-// if (aList.myDynHilighted.IsEmpty() == Standard_False) {
-// aList.myIsUpdated[NIS_Drawer::Draw_DynHilighted]= Standard_True;
-// aList.myDynHilighted.Clear();
-// }
-
- }
- }
-}
-
-//=======================================================================
-//function : RemoveAll
-//purpose :
-//=======================================================================
-
-void NIS_InteractiveContext::RemoveAll ()
-{
- // Remove objects from the Context
- NCollection_SparseArray <Handle(NIS_InteractiveObject)>::Iterator
- anIter(myObjects);
- for (; anIter.More(); anIter.Next()) {
- Handle(NIS_InteractiveObject)& anObj = anIter.ChangeValue();
- if (anObj.IsNull() == Standard_False) {
- if (anObj->IsDynHilighted()) {
- NCollection_List<Handle(NIS_View)>::Iterator anIterV (myViews);
- for (; anIterV.More(); anIterV.Next())
- if (anIterV.Value().IsNull() == Standard_False)
- anIterV.Value()->DynamicUnhilight (anObj);
- }
- anObj->myID = 0;
- anObj->myDrawer.Nullify();
- anObj.Nullify();
- }
- }
-
- // Mark all draw lists to be removed in the view callback
- NCollection_Map<Handle(NIS_Drawer)>::Iterator anIterD (myDrawers);
- for (; anIterD.More(); anIterD.Next()) {
- const Handle(NIS_Drawer)& aDrawer = anIterD.Value();
- if (aDrawer.IsNull() == Standard_False) {
- aDrawer->myMapID.Clear();
- aDrawer->UpdateExListId(NULL);
- aDrawer->myLists.Clear();
- }
- }
- // Remove Drawers
- myDrawers.Clear();
-
- // Release memory
- myAllocator->Reset();
- myAllocator->ResetCounters();
-
- // Remove objects from maps
- myMapObjects[0].Clear();
- myMapObjects[1].Clear();
- myMapObjects[2].Clear();
- myMapObjects[3].Clear();
- myMapNonSelectableObjects.Clear();
- myObjects.Clear();
-}
-
-//=======================================================================
-//function : RebuildViews
-//purpose :
-//=======================================================================
-
-void NIS_InteractiveContext::RebuildViews ()
-{
- const Handle(NIS_Allocator) aNewAlloc = compactObjects();
-
- // Recalculate all DrawLists in all drawers
- markAllDrawersUpdated(myDrawers);
-
- // It is time to destroy the old allocator, not before this line. Because
- // the old allocator is needed to tidy up draw lists in SetUpdated() calls.
- if (aNewAlloc.IsNull() == Standard_False)
- myAllocator = aNewAlloc;
-
- NCollection_List<Handle(NIS_View)>::Iterator anIterV(myViews);
- for (; anIterV.More(); anIterV.Next()) {
- const Handle(NIS_View)& aView = anIterV.Value();
- if (aView.IsNull() == Standard_False)
- aView->Redraw();
- }
-}
-
-//=======================================================================
-//function : UpdateViews
-//purpose : Only repaint the views refreshing their presentations only for
-// those drawers that have been marked as updated.
-//=======================================================================
-
-void NIS_InteractiveContext::UpdateViews ()
-{
- const Handle(NIS_Allocator) aNewAlloc = compactObjects();
- if (aNewAlloc.IsNull() == Standard_False)
- myAllocator = aNewAlloc;
-
- NCollection_List<Handle(NIS_View)>::Iterator anIterV(myViews);
- for (; anIterV.More(); anIterV.Next()) {
- const Handle(NIS_View)& aView = anIterV.Value();
- if (aView.IsNull() == Standard_False)
- aView->Redraw();
- }
-}
-
-//=======================================================================
-//function : SetSelected
-//purpose :
-//=======================================================================
-
-Standard_Boolean NIS_InteractiveContext::SetSelected
- (const Handle(NIS_InteractiveObject)& theObj,
- const Standard_Boolean isSelected)
-{
- Standard_Boolean aResult (Standard_False);
- if (theObj.IsNull() == Standard_False) {
- const Standard_Integer anID = theObj->ID();
- if (isSelected == Standard_False) {
- if (myMapObjects[NIS_Drawer::Draw_Hilighted].Remove(anID)) {
- deselectObj (theObj, anID);
- aResult = Standard_True;
- }
- } else {
- if (IsSelectable(anID) == Standard_True) {
- if (myMapObjects[NIS_Drawer::Draw_Hilighted].Add(anID)) {
- selectObj (theObj, anID);
- aResult = Standard_True;
- }
- }
- }
- }
- return aResult;
-}
-
-//=======================================================================
-//function : ProcessSelection
-//purpose :
-//=======================================================================
-
-Standard_Boolean NIS_InteractiveContext::ProcessSelection
- (const Handle(NIS_InteractiveObject)& theObj,
- const Standard_Boolean isMultiple)
-{
- Standard_Boolean aResult (Standard_False);
- Standard_Integer anID (0);
- Standard_Boolean wasSelected (Standard_False);
- if (theObj.IsNull() == Standard_False) {
- const Handle(NIS_Drawer)& aDrawer = theObj->GetDrawer();
- if (aDrawer.IsNull() == Standard_False) {
- if (aDrawer->GetContext() == this) {
- anID = theObj->ID();
- wasSelected = myMapObjects[NIS_Drawer::Draw_Hilighted].Contains (anID);
- }
- }
- }
-
- switch (mySelectionMode) {
- case Mode_Normal:
- case Mode_Additive:
- if (isMultiple == Standard_False) {
- ClearSelected();
- aResult = Standard_True;
- } else if (wasSelected && mySelectionMode == Mode_Normal) {
- myMapObjects[NIS_Drawer::Draw_Hilighted].Remove( anID );
- deselectObj (theObj, anID);
- aResult = Standard_True;
- break;
- }
- if (wasSelected == Standard_False && IsSelectable(anID) == Standard_True) {
- myMapObjects[NIS_Drawer::Draw_Hilighted].Add( anID );
- selectObj (theObj, anID);
- aResult = Standard_True;
- }
- break;
- case Mode_Exclusive:
- if (wasSelected) {
- myMapObjects[NIS_Drawer::Draw_Hilighted].Remove( anID );
- deselectObj (theObj, anID);
- aResult = Standard_True;
- }
- break;
- default: ;
- }
- return aResult;
-}
-
-//=======================================================================
-//function : ProcessSelection
-//purpose :
-//=======================================================================
-
-void NIS_InteractiveContext::ProcessSelection
- (const TColStd_PackedMapOfInteger& mapSel,
- const Standard_Boolean isMultiple)
-{
- //subtract non-selectable objects
- TColStd_PackedMapOfInteger aMap;
- aMap.Subtraction (mapSel, myMapNonSelectableObjects);
-
- TColStd_MapIteratorOfPackedMapOfInteger anIter;
- switch (mySelectionMode) {
- case Mode_Normal:
- if (isMultiple == Standard_False) {
- ClearSelected();
- myMapObjects[NIS_Drawer::Draw_Hilighted] = aMap;
- for (anIter.Initialize (aMap); anIter.More(); anIter.Next()) {
- const Standard_Integer anID = anIter.Key();
- selectObj (myObjects(anID), anID);
- }
- } else {
- TColStd_PackedMapOfInteger aMapSub;
- aMapSub.Intersection(aMap, myMapObjects[NIS_Drawer::Draw_Hilighted]);
- aMap.Subtract (myMapObjects[NIS_Drawer::Draw_Hilighted]);
- myMapObjects[NIS_Drawer::Draw_Hilighted].Unite (aMap);
- myMapObjects[NIS_Drawer::Draw_Hilighted].Subtract (aMapSub);
- for (anIter.Initialize (aMap); anIter.More(); anIter.Next()) {
- const Standard_Integer anID = anIter.Key();
- selectObj (myObjects(anID), anID);
- }
- for (anIter.Initialize (aMapSub); anIter.More(); anIter.Next()) {
- const Standard_Integer anID = anIter.Key();
- deselectObj (myObjects(anID), anID);
- }
- }
- break;
- case Mode_Additive:
- aMap.Subtract (myMapObjects[NIS_Drawer::Draw_Hilighted]);
- myMapObjects[NIS_Drawer::Draw_Hilighted].Unite (aMap);
- for (anIter.Initialize (aMap); anIter.More(); anIter.Next()) {
- const Standard_Integer anID = anIter.Key();
- selectObj (myObjects(anID), anID);
- }
- break;
- case Mode_Exclusive:
- aMap.Intersect (myMapObjects[NIS_Drawer::Draw_Hilighted]);
- myMapObjects[NIS_Drawer::Draw_Hilighted].Subtract (aMap);
- for (anIter.Initialize (aMap); anIter.More(); anIter.Next()) {
- const Standard_Integer anID = anIter.Key();
- deselectObj (myObjects(anID), anID);
- }
- break;
- default: ;
- }
-}
-
-//=======================================================================
-//function : IsSelected
-//purpose :
-//=======================================================================
-
-Standard_Boolean NIS_InteractiveContext::IsSelected
- (const Handle(NIS_InteractiveObject)& theObj)
-{
- Standard_Boolean aResult (Standard_False);
- if (theObj.IsNull() == Standard_False) {
- const Standard_Integer anID = theObj->ID();
- aResult = myMapObjects[NIS_Drawer::Draw_Hilighted].Contains(anID);
- }
- return aResult;
-}
-
-//=======================================================================
-//function : ClearSelected
-//purpose :
-//=======================================================================
-
-void NIS_InteractiveContext::ClearSelected ()
-{
- TColStd_MapIteratorOfPackedMapOfInteger anIter
- (myMapObjects[NIS_Drawer::Draw_Hilighted]);
- for (; anIter.More(); anIter.Next()) {
- const Standard_Integer anID = anIter.Key();
- deselectObj (myObjects(anID), anID);
- }
- myMapObjects[NIS_Drawer::Draw_Hilighted].Clear();
-}
-
-//=======================================================================
-//function : SetSelected
-//purpose :
-//=======================================================================
-
-void NIS_InteractiveContext::SetSelected
- (const TColStd_PackedMapOfInteger& mapSel,
- const Standard_Boolean isAdded)
-{
- //subtract non-selectable objects
- TColStd_PackedMapOfInteger aMap;
- aMap.Subtraction (mapSel, myMapNonSelectableObjects);
-
- if (aMap.IsEmpty() && isAdded == Standard_False)
- ClearSelected();
- else {
- // Deselect objects
- TColStd_MapIteratorOfPackedMapOfInteger anIter;
- if (isAdded == Standard_False) {
- TColStd_PackedMapOfInteger aMapSub;
- aMapSub.Subtraction (myMapObjects[NIS_Drawer::Draw_Hilighted], aMap);
- for (anIter.Initialize(aMapSub); anIter.More(); anIter.Next()) {
- const Standard_Integer anID = anIter.Key();
- deselectObj (myObjects(anID), anID);
- }
- myMapObjects[NIS_Drawer::Draw_Hilighted].Subtract(aMapSub);
- }
- aMap.Subtract (myMapObjects[NIS_Drawer::Draw_Hilighted]);
- myMapObjects[NIS_Drawer::Draw_Hilighted].Unite (aMap);
-
- // Select objects
- for (anIter.Initialize (aMap); anIter.More(); anIter.Next()) {
- const Standard_Integer anID = anIter.Key();
- selectObj (myObjects(anID), anID);
- }
- }
-}
-
-//=======================================================================
-//function : selectObject
-//purpose :
-//=======================================================================
-
-Standard_Real NIS_InteractiveContext::selectObject
- (Handle(NIS_InteractiveObject)& theSel,
- NCollection_List<DetectedEnt>& theDetected,
- const gp_Ax1& theAxis,
- const Standard_Real theOver,
- const Standard_Boolean isOnlySel) const
-{
- static const Standard_Real anInfiniteDist = 0.5 * RealLast();
- Standard_Real aMinDist(anInfiniteDist);
- if (mySelectionMode != Mode_NoSelection || isOnlySel == Standard_False)
- {
- DetectedEnt anEnt;
- NCollection_SparseArray <Handle(NIS_InteractiveObject)>::ConstIterator
- anIter(myObjects);
- for (; anIter.More(); anIter.Next()) {
- const Handle(NIS_InteractiveObject)& anObj = anIter.Value();
- if (anObj.IsNull() == Standard_False)
- if (anObj->IsDisplayed() &&
- (!myMapNonSelectableObjects.Contains (anObj->ID()) ||
- isOnlySel == Standard_False))
- {
- // Pass the object through the SelectFilter if available
- if (mySelectFilter.IsNull() == Standard_False)
- if (mySelectFilter->IsOk (anObj.operator->()) == Standard_False)
- continue;
- // Check the intersection with the box
- const Bnd_B3f& aBox = anObj->GetBox();
- if (aBox.IsOut (theAxis, Standard_False, theOver) == Standard_False)
- {
- anEnt.Dist = anObj->Intersect (theAxis, theOver);
- if (anEnt.Dist < anInfiniteDist) {
- anEnt.PObj = anObj.operator->();
- // Insert the detected entity in the sorted list
- NCollection_List<DetectedEnt>::Iterator anIterD(theDetected);
- for (; anIterD.More(); anIterD.Next()) {
- if (anEnt.Dist < anIterD.Value().Dist) {
- theDetected.InsertBefore(anEnt, anIterD);
- break;
- }
- }
- if (anIterD.More() == Standard_False)
- theDetected.Append(anEnt);
- if (anEnt.Dist < aMinDist) {
- aMinDist = anEnt.Dist;
- theSel = anObj;
- }
- }
- }
- }
- }
- }
- return aMinDist;
-}
-
-//=======================================================================
-//function : SetSelectable
-//purpose :
-//=======================================================================
-
-void NIS_InteractiveContext::SetSelectable
- (const TColStd_PackedMapOfInteger& objIDs,
- const Standard_Boolean isSelectable)
-{
- if (isSelectable) { // subtract given IDs from myMapNonSelectableObjects
- myMapNonSelectableObjects.Subtract(objIDs);
- }
- else { // deselect IDs, add them to myMapNonSelectableObjects
- Standard_Integer anID;
- TColStd_MapIteratorOfPackedMapOfInteger anIter(objIDs);
- for (; anIter.More(); anIter.Next()) {
- anID = anIter.Key();
- if ( myMapObjects[NIS_Drawer::Draw_Hilighted].Contains(anID)) {
- myMapObjects[NIS_Drawer::Draw_Hilighted].Remove(anID);
- deselectObj (myObjects(anID), anID);
- }
- }
- myMapNonSelectableObjects.Unite(objIDs);
- }
-}
-
-//=======================================================================
-//function : selectObjects
-//purpose :
-//=======================================================================
-
-Standard_Boolean NIS_InteractiveContext::selectObjects
- (TColStd_PackedMapOfInteger& mapObj,
- const Bnd_B3f& theBox,
- const gp_Trsf& theTrf,
- const gp_Trsf& theTrfInv,
- const Standard_Boolean isFullyIncluded) const
-{
- Standard_Boolean aResult (Standard_False);
- if (mySelectionMode != Mode_NoSelection) {
- NCollection_SparseArray <Handle(NIS_InteractiveObject)>::ConstIterator
- anIter(myObjects);
- for (; anIter.More(); anIter.Next()) {
- const Handle(NIS_InteractiveObject)& anObj = anIter.Value();
- if (anObj.IsNull() == Standard_False)
- if (anObj->IsDisplayed()) {
- // Pass the object through the SelectFilter if available
- if (mySelectFilter.IsNull() == Standard_False)
- if (mySelectFilter->IsOk (anObj.operator->()) == Standard_False)
- continue;
- // Check the intersection with the box
- const Bnd_B3f& aBox = anObj->GetBox();
- if (aBox.IsIn (theBox, theTrf)) {
- mapObj.Add (anObj->ID());
- aResult = Standard_True;
- } else if (aBox.IsOut (theBox, theTrf) == Standard_False)
- if (anObj->Intersect (theBox, theTrfInv, isFullyIncluded))
- {
- mapObj.Add (anObj->ID());
- aResult = Standard_True;
- }
- }
- }
- }
- return aResult;
-}
-
-//=======================================================================
-//function : selectObjects
-//purpose :
-//=======================================================================
-
-Standard_Boolean NIS_InteractiveContext::selectObjects
- (TColStd_PackedMapOfInteger &mapObj,
- const NCollection_List<gp_XY> &thePolygon,
- const Bnd_B2f &thePolygonBox,
- const gp_Trsf &theTrfInv,
- const Standard_Boolean isFullyIn) const
-{
- Standard_Boolean aResult (Standard_False);
-
- if (mySelectionMode != Mode_NoSelection) {
- NCollection_SparseArray <Handle(NIS_InteractiveObject)>::ConstIterator
- anIter(myObjects);
-
- for (; anIter.More(); anIter.Next()) {
- const Handle(NIS_InteractiveObject)& anObj = anIter.Value();
-
- if (anObj.IsNull() == Standard_False)
- if (anObj->IsDisplayed()) {
- // Pass the object through the SelectFilter if available
- if (mySelectFilter.IsNull() == Standard_False)
- if (mySelectFilter->IsOk (anObj.operator->()) == Standard_False)
- continue;
-
- // Comvert 3d box to 2d one
- const Bnd_B3f &aBox = anObj->GetBox();
- Bnd_B2f aB2d;
- Standard_Real aX[2];
- Standard_Real aY[2];
- Standard_Real aZ[2];
- gp_XYZ aBoxVtx;
- Standard_Integer i;
-
- aBox.CornerMin().Coord(aX[0], aY[0], aZ[0]);
- aBox.CornerMax().Coord(aX[1], aY[1], aZ[1]);
-
- for (i = 0; i < 8; i++) {
- aBoxVtx.SetX(aX[(i & 1) ? 1 : 0]);
- aBoxVtx.SetY(aY[(i & 2) ? 1 : 0]);
- aBoxVtx.SetZ(aZ[(i & 4) ? 1 : 0]);
- theTrfInv.Transforms(aBoxVtx);
- aB2d.Add(gp_XY(aBoxVtx.X(), aBoxVtx.Y()));
- }
-
- // Check the intersection with the box
- if (thePolygonBox.IsOut(aB2d) == Standard_False) {
- if (anObj->Intersect(thePolygon, theTrfInv, isFullyIn)) {
- mapObj.Add (anObj->ID());
- aResult = Standard_True;
- }
- }
- }
- }
- }
- return aResult;
-}
-
-//=======================================================================
-//function : deselectObj
-//purpose :
-//=======================================================================
-
-void NIS_InteractiveContext::deselectObj
- (const Handle(NIS_InteractiveObject)& theObj,
- const Standard_Integer theID)
-{
- if (theObj.IsNull() == Standard_False) {
- const Handle(NIS_Drawer)& aDrawer = theObj->GetDrawer();
- if (theObj->IsTransparent()) {
- myMapObjects[NIS_Drawer::Draw_Transparent].Add(theID);
- aDrawer->SetUpdated(NIS_Drawer::Draw_Transparent);
- } else if (theObj->myBaseType == NIS_Drawer::Draw_Top) {
- myMapObjects[NIS_Drawer::Draw_Top].Add(theID);
- aDrawer->SetUpdated(NIS_Drawer::Draw_Top);
- } else {
- myMapObjects[NIS_Drawer::Draw_Normal].Add(theID);
- aDrawer->SetUpdated(NIS_Drawer::Draw_Normal);
- }
- aDrawer->SetUpdated(NIS_Drawer::Draw_Hilighted);
- theObj->myDrawType = theObj->myBaseType;
- }
-}
-
-//=======================================================================
-//function : selectObj
-//purpose :
-//=======================================================================
-
-void NIS_InteractiveContext::selectObj
- (const Handle(NIS_InteractiveObject)& theObj,
- const Standard_Integer theID)
-{
- if (theObj.IsNull() == Standard_False) {
- const Handle(NIS_Drawer)& aDrawer = theObj->GetDrawer();
- if (theObj->IsTransparent()) {
- myMapObjects[NIS_Drawer::Draw_Transparent].Remove(theID);
- aDrawer->SetUpdated(NIS_Drawer::Draw_Transparent);
- } else if (theObj->myDrawType == NIS_Drawer::Draw_Top) {
- myMapObjects[NIS_Drawer::Draw_Top].Remove(theID);
- aDrawer->SetUpdated(NIS_Drawer::Draw_Top);
- } else {
- myMapObjects[NIS_Drawer::Draw_Normal].Remove(theID);
- aDrawer->SetUpdated(NIS_Drawer::Draw_Normal);
- }
- aDrawer->SetUpdated(NIS_Drawer::Draw_Hilighted);
- theObj->myDrawType = NIS_Drawer::Draw_Hilighted;
- }
-}
-
-//=======================================================================
-//function : drawerForDisplay
-//purpose :
-//=======================================================================
-
-const Handle(NIS_Drawer)& NIS_InteractiveContext::drawerForDisplay
- (const Handle(NIS_InteractiveObject)& theObj,
- const Handle(NIS_Drawer)& theDrawer)
-{
- Handle(NIS_Drawer) aDrawer;
- if (theDrawer.IsNull() == Standard_False) {
- if (theDrawer->myCtx != this)
- Standard_NoSuchObject::Raise ("NIS_InteractiveContext::Display (0)");
- aDrawer = theDrawer;
- } else {
- const Handle(NIS_Drawer)& anObjDrawer = theObj->GetDrawer();
- if (anObjDrawer.IsNull() == Standard_False)
- return anObjDrawer;
- aDrawer = theObj->DefaultDrawer(0L);
- aDrawer->myCtx = this;
- }
- return theObj->SetDrawer (aDrawer, Standard_False);
-}
-
-//=======================================================================
-//function : objectIdForDisplay
-//purpose :
-//=======================================================================
-
-void NIS_InteractiveContext::objectForDisplay
- (Handle(NIS_InteractiveObject)& theObj,
- const NIS_Drawer::DrawType theDrawType)
-{
- if (theObj->ID() == 0) {
- // Create a new ID for this object
- Handle(NIS_InteractiveObject) anObj;
- theObj->Clone(myAllocator, anObj);
- theObj = anObj;
- anObj->myID = ++myLastObjectId;
- myObjects.SetValue (myLastObjectId, anObj);
- myMapObjects[theDrawType].Add(anObj->myID);
- anObj->myDrawType = theDrawType;
- }
-}
-
-//=======================================================================
-//function : compactObjects
-//purpose :
-//=======================================================================
-
-Handle(NIS_Allocator) NIS_InteractiveContext::compactObjects()
-{
- Handle(NIS_Allocator) aNewAlloc;
-
- NCollection_List<Handle(NIS_View)>::Iterator anIterV;
- // Check if the memory used by objects has to be compacted.
- const Standard_Size nAllocated = myAllocator->NAllocated();
-
- if (nAllocated > 1024*1024) {
- const Standard_Size nFreed = myAllocator->NFreed();
- if ((nFreed * 5) / 3 > nAllocated || nFreed > 20*1024*1024)
- {
- for (anIterV.Init(myViews); anIterV.More(); anIterV.Next()) {
- const Handle(NIS_View)& aView = anIterV.Value();
- if (aView.IsNull() == Standard_False) {
- aView->myDynHilighted.Nullify();
- aView->GetDetected().Clear();
- }
- }
- // Compact the memory: clone all objects to a new allocator, release
- // the old allocator instance.
- aNewAlloc = new NIS_Allocator;
- NCollection_SparseArray<Handle(NIS_InteractiveObject)>::Iterator
- anIter(myObjects);
- for (; anIter.More(); anIter.Next()) {
- if (anIter.Value().IsNull() == Standard_False) {
- Handle(NIS_InteractiveObject)& aNewObj = anIter.ChangeValue();
- const Handle(NIS_InteractiveObject) anObj = aNewObj;
- aNewObj.Nullify();
- anObj->CloneWithID(aNewAlloc, aNewObj);
- }
- }
- }
- }
- return aNewAlloc;
-}
-
-//=======================================================================
-//function : markAllDrawersUpdated
-//purpose :
-//=======================================================================
-
-void markAllDrawersUpdated (const NCollection_Map<Handle(NIS_Drawer)>& lstDrv)
-{
- NCollection_Map<Handle(NIS_Drawer)>::Iterator anIterD (lstDrv);
- for (; anIterD.More(); anIterD.Next()) {
- const Handle(NIS_Drawer)& aDrawer = anIterD.Value();
- if (aDrawer.IsNull() == Standard_False) {
- aDrawer->SetUpdated (NIS_Drawer::Draw_Normal,
- NIS_Drawer::Draw_Top,
- NIS_Drawer::Draw_Transparent,
- NIS_Drawer::Draw_Hilighted);
- }
- }
-}
+++ /dev/null
-// Created on: 2007-07-06
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2007-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#ifndef NIS_InteractiveContext_HeaderFile
-#define NIS_InteractiveContext_HeaderFile
-
-#include <Handle_NIS_InteractiveObject.hxx>
-#include <Handle_NIS_View.hxx>
-#include <NCollection_Map.hxx>
-#include <NCollection_SparseArray.hxx>
-#include <NIS_Allocator.hxx>
-#include <NIS_Drawer.hxx>
-#include <NIS_SelectFilter.hxx>
-
-// undefine WinAPI macros
-#ifdef GetObject
- #undef GetObject
-#endif
-
-class NIS_View;
-class Bnd_B3f;
-class Bnd_B2f;
-
-/**
- * InteractiveContext is the central NIS structure that stores and manages
- * all NIS_InteractiveObject instances as well as the Drawers for their visualisation.
- * There may be one or more Views referred by an InteractiveContext instance.
- * Also there may be one or more InteractiveContext instances referring the same View.
- * However the latter case is not typical (see NIS_View description).
- * To add or remove a View in a Context, use methods AttachView() and DetachView().
- *
- * @section nis_interactivecontext_mgtobjects Management of objects
- * The main purpose of class NIS_InteractiveContext is allocation and
- * management of NIS_InteractiveObject instances.
- * <p>An InteractiveObject should be added to the Context by a call to method
- * Display() or DisplayOnTop(). After that (not before) it becomes possible to:
- * <ul>
- * <li>change the presentation of the InteractiveObject (e.g., modify the color)</li>
- * <li>make the InteractiveObject visible or invisible, selectable or unselectable;</li>
- * <li>set Transparency;</li>
- * <li>select InteractiveObject interactively, including the hilighting and the dynamic hilighting.</li>
- * </ul>
- * Methods that add/remove/display/hide NIS_InteractiveObject instances have
- * the optional parameter 'isUpdateViews'. When it is set to True (default),
- * the modification of the object brings about an immediate update of its
- * presentation (the corresponding Drawer flagged to recompute presentations).
- * Normally you do not have to worry about this parameter leaving it assigned to
- * the default value; use the alternative value 'Standard_False' only for
- * very special purposes, like animation -- when many updates should be
- * synchronized in time. For other methods like changing the transparency or
- * color definition there is no parameter 'isUpdateViews', all changes mark
- * the corresponding drawers immediately.
- * <p>Typical scheme of usage:
- * @code
- * const Handle(NIS_InteractiveContext) aContext = new NIS_InteractiveContext;
- * const Handle(NIS_View) aView = new NIS_View(...);
- * aContext->AttachView (aView);
- * ....
- * for (; ;) {
- * const Handle(MyIOClass) anObject = new MyIOClass();
- * aContext->Display (anObject);
- * anObject->SetColor(...); // method of class MyIOClass
- * ...
- * }
- * @endcode
- * @section nis_interactivecontext_display Method Display()
- * This method performs three important tasks, when called the first time for
- * an object:
- * <ul>
- * <li>Copy its argument to the memory pool that is managed by the internal
- * Allocator of NIS_InteractiveContext. Then <b>the new instance of
- * object</b> is returned back in the same argument (in-out parameter);</li>
- * <li>Store the copied instance in the internal vector of objects, so that
- * the displayed object receives its ID (sequential address in the vector);
- * </li>
- * <li>Create a Drawer instance if necessary; attach the displayed interactive
- * object to this instance (or to a relevant and already existing Drawer)
- * </li>
- * </ul>
- * Thus any methods dealing with Drawer-related properties like color, line
- * width, polygon offset, etc. can only be called following the necessary call
- * of method Display().
- * <p>
- * Subsequent calls to Display() just revert previous calls of Erase() without
- * any re-initialization of interactive object or its drawer.
- *
- * @section nis_interactivecontext_memory Using the memory
- * As described in the sections above, all interactive objects should completely
- * reside in the special memory pool managed by the InteractiveContext instance.
- * This is a fast memory (NCollection_IncAllocator is used) but it has the
- * drawback: when you destroy an object using method Remove() it is detached
- * from NIS_InteractiveContext and its presentation is removed from all Views.
- * But the memory allocated for that removed object is not released and it
- * cannot be reused by new interactive objects. In time there may appear too
- * many "dead" objects to hinder or even crash the application.
- * <p>
- * This problem is resolved by automatic keeping the record of the total size
- * of both used and unused memory, in the instance of NIS_Allocator. When the
- * amount of unused memory becomes too big then the method compactObjects()
- * creates a new NIS_Allocator instance and copies there all interactive
- * objects that are 'alive' then releasing the previous memory pool. All
- * object IDs and their drawers remain intact, so nothing is changed except
- * the greater amount of available memory in the system.
- * <p>
- * This mechanism works when either UpdateViews() or RebuildViews() is called
- * from time to time, only these two methods can call compactObjects().
- */
-
-class NIS_InteractiveContext : public Standard_Transient
-{
- public:
- typedef enum {
- Mode_NoSelection = 0, ///< Seelction is totally disabled
- Mode_Normal, ///< Selected are added to or removed from list
- Mode_Additive, ///< Selected are added to the list of selected
- Mode_Exclusive ///< Selected are removed from the list
- } SelectionMode;
-
- public:
- // ---------- PUBLIC METHODS ----------
-
-
- /**
- * Empty constructor.
- */
- Standard_EXPORT NIS_InteractiveContext ();
-
- /**
- * Destructor.
- */
- Standard_EXPORT virtual ~NIS_InteractiveContext ();
-
- ///@name Management of Views
- //@{
- /**
- * Associate this Context with the given View.
- */
- Standard_EXPORT void AttachView (const Handle(NIS_View)& theView);
-
- /**
- * Stop the association of the Context with the given View.
- */
- Standard_EXPORT void DetachView (const Handle(NIS_View)& theView);
- //@}
-
- /**
- * Query the InteractiveObject instance by its ID.
- */
- Standard_EXPORT const Handle(NIS_InteractiveObject)&
- GetObject (const Standard_Integer theID) const;
-
- /**
- * Query the total number of InteractiveObject instances. This number can be
- * smaller than the greatest object ID, therefore you should not iterate till
- * this number using GetObject; use class NIS_ObjectsIterator instead.
- */
- inline Standard_Integer
- NbObjects ()
-// { return myObjects.Length()-1; }
- { return (myMapObjects[0].Extent() + myMapObjects[1].Extent() +
- myMapObjects[2].Extent()) + myMapObjects[3].Extent(); }
-
- /**
- * Query the total number of Drawers instances.
- */
- inline Standard_Integer
- NbDrawers ()
- { return myDrawers.Size(); }
-
- /**
- * Access to Drawers, can be used for specific operations where it is not
- * desirale to iterate InteractiveObjects.
- */
- inline NCollection_Map<Handle(NIS_Drawer)>::Iterator
- GetDrawers () const
- { return NCollection_Map<Handle(NIS_Drawer)>::Iterator(myDrawers); }
-
- // ================ BEGIN Mangement of Objects ================
- ///@name Management of Objects
- //@{
-
- /**
- * Make the given interactive object visible in the current context.
- * If the object is not yet added to this context, it is added. Therefore
- * this method should follow the creation of an InteractiveObject instance
- * before it can be displayed.
- * @param theObj
- * <tt>[in/out]</tt>Interactive object instance. If the object is displayed
- * for the first time then the output value will be a new (cloned) object.
- * @param theDrawer
- * If this parameter is NULL, the default drawer is used for theObj, defined
- * by the object type. Otherwise the given Drawer (must be present in this
- * context) is used for theObj. Use the parameter to change the presentation
- * of theObj.
- * @param isUpdateViews
- * If True, the drawer receives isUpdate flag, then it will recompute
- * the presentations when Redraw event happens. You can leave the parameter
- * to False if you have to make a number of similar calls, then you would
- * call UpdateViews() in the end.
- */
- Standard_EXPORT void Display (Handle(NIS_InteractiveObject)& theObj,
- const Handle(NIS_Drawer)& theDrawer = NULL,
- const Standard_Boolean isUpdateViews
- = Standard_True);
-
- /**
- * Make the given interactive object visible on top of other objects in
- * the current context.
- * If the object is not yet added to this context, it is added. Therefore
- * this method should follow the creation of an InteractiveObject instance
- * before it can be displayed.
- * @param theObj
- * Interactive object instance.
- * @param theDrawer
- * If this parameter is NULL, the default drawer is used for theObj, defined
- * by the object type. Otherwise the given Drawer (must be present in this
- * context) is used for theObj. Use the parameter to change the presentation
- * of theObj.
- * @param isUpdateViews
- * If True, the drawer receives isUpdate flag, then it will recompute
- * the presentations when Redraw event happens. You can leave the parameter
- * to False if you have to make a number of similar calls, then you would
- * call UpdateViews() in the end.
- */
- Standard_EXPORT void DisplayOnTop (Handle(NIS_InteractiveObject)& theObj,
- const Handle(NIS_Drawer)& theDrawer = NULL,
- const Standard_Boolean isUpdateViews
- = Standard_True);
-
- /**
- * Make the given object invisible in the current InteractiveContext.
- * @param theObj
- * Interactive object instance. Must be already added to this context.
- * @param isUpdateViews
- * If True, the drawer receives isUpdate flag, then it will recompute
- * the presentations when Redraw event happens. You can leave the parameter
- * to False if you have to make a number of similar calls, then you would
- * call UpdateViews() in the end.
- */
- Standard_EXPORT void Erase (const Handle(NIS_InteractiveObject)& theObj,
- const Standard_Boolean isUpdateViews
- = Standard_True);
-
- /**
- * Remove the given object from its Interactive context.
- * @param theObj
- * Interactive object instance. Must be already added to this context.
- * @param isUpdateViews
- * If True, the drawer receives isUpdate flag, then it will recompute
- * the presentations when Redraw event happens. You can leave the parameter
- * to False if you have to make a number of similar calls, then you would
- * call UpdateViews() in the end.
- */
- Standard_EXPORT void Remove (const Handle(NIS_InteractiveObject)& theObj,
- const Standard_Boolean isUpdateViews
- = Standard_True);
-
- /**
- * Make all stored InteractiveObject instances visible, equivalent to
- * calling method Display() for all contained objects.
- */
- Standard_EXPORT void DisplayAll ();
-
- /**
- * Make all stored InteractiveObject instances invisible, equivalent to
- * calling method Erase() for all contained objects.
- */
- Standard_EXPORT void EraseAll ();
-
- /**
- * Clean the context of its contained objects. Drawers are destroyed
- * and all presentations become empty.
- */
- Standard_EXPORT void RemoveAll ();
-
- /**
- * This method signals that the presenation should be refreshed in all updated
- * Drawers and in all Views. Calls Redraw() of each view from inside.
- */
- Standard_EXPORT void UpdateViews ();
-
- /**
- * Similar to UpdateViews but forces all presentations to be rebuilt whether
- * the drawers are marked as updated or not.
- */
- Standard_EXPORT void RebuildViews();
-
- /**
- * Find the bounding box of all Objects displayed (visible) in the given View.
- * @param theBox
- * <tt>[out]</tt> Bounding box, updated (not reinitialized!) by the object
- * boxes.
- * @param theView
- * View instance where the objects are displayed.
- */
- Standard_EXPORT void GetBox (Bnd_B3f& theBox,
- const NIS_View * theView) const;
-
- //@}
- // ================ END Mangement of Objects ================
-
- // ================ BEGIN Selection API ================
- ///@name Selection API
- //@{
-
- /**
- * Query the current selection filter. Use the method SetFilter to install it.
- * By default returns a NULL handle.
- */
- inline const Handle(NIS_SelectFilter)&
- GetFilter () const
- { return mySelectFilter; }
-
- /**
- * Install a selection filter.
- */
- inline void SetFilter (const Handle(NIS_SelectFilter)& theFilter)
- { mySelectFilter = theFilter; }
-
- /**
- * Query the current selection mode.
- */
- inline SelectionMode GetSelectionMode () const
- { return mySelectionMode; }
-
- /**
- * Set the selection mode.
- */
- inline void SetSelectionMode (const SelectionMode theMode)
- { mySelectionMode = theMode; }
-
- /**
- * Set or unset the selected state of the object, also changing its hilight status.
- * If mySelectionMode == Mode_NoSelection this method does nothing (returns False always).
- * If the given object is NULL (e.g., if the mouse was clicked on empty area),
- * then the current selection is cleared (modes Normal and Additive only).
- * The selection algorithm with respect to the given object is defined by the current selection mode:
- * <ul>
- * <li>Mode_Normal - the selection state is toggled</li>
- * <li>Mode_Additive - the object is always added to the selection</li>
- * <li>Mode_Exclusive - the object is always removed from the selection</li>
- * </ul>
- * This method does not update the views.
- * @param O
- * Object to be selected or deselected
- * @param isMultiple
- * If True, then the objects are not automatically deselected.
- * @return
- * True if the selection status has been changed, False if nothing changed
- */
- Standard_EXPORT Standard_Boolean
- ProcessSelection(const Handle(NIS_InteractiveObject)& O,
- const Standard_Boolean isMultiple
- = Standard_False);
-
- /**
- * Process the selection of multiple objects. Equivalent to the other
- * ProcessSelection method, on a set of objects. Particularly, the current
- * selection mode is respected.
- * @param map
- * Container of IDs of objects to be processed
- * @param isMultiple
- * If True, then the objects are not automatically deselected.
- */
- Standard_EXPORT void ProcessSelection(const TColStd_PackedMapOfInteger& map,
- const Standard_Boolean isMultiple
- = Standard_False);
-
- /**
- * Set or unset the selected state of the object, also changing its hilight status.
- * This method does not update the views.
- * @param theObj
- * Object to be selected or deselected
- * @param isSelected
- * true if the object should be selected, False - if deselected.
- * @return
- * True if the selection status has been changed, False if noithing changed
- */
- Standard_EXPORT Standard_Boolean
- SetSelected (const Handle(NIS_InteractiveObject)& theObj,
- const Standard_Boolean isSelected
- = Standard_True);
-
- /**
- * Set the selection. Previously selected objects are deselected if they
- * are not included in the given map.
- * @param map
- * Container of IDs of objects to be selected
- * @param isAdded
- * If True, the given IDs are added to the current selection (nothing is
- * deselected). If False (default) - the previous selection is forgotten.
- */
- Standard_EXPORT void SetSelected (const TColStd_PackedMapOfInteger& map,
- const Standard_Boolean isAdded
- = Standard_False);
-
- /**
- * Query if the given object is selected.
- */
- Standard_EXPORT Standard_Boolean
- IsSelected (const Handle(NIS_InteractiveObject)& theOb);
-
- /**
- * Reset all previous selection.
- */
- Standard_EXPORT void ClearSelected ();
-
- /**
- * Query the set of selected objects.
- * @return
- * Map of integer IDs of objects.
- */
- inline const TColStd_PackedMapOfInteger&
- GetSelected ()
- { return myMapObjects[NIS_Drawer::Draw_Hilighted]; }
-
- /**
- * Define objects that can be selected by no means (isSelectable = false),
- * or make the objects selectable (isSelectable = true).
- * @param IDs
- * Container of IDs of objects to be set as selectable or not selectable
- * @param isSelectable
- * If False, the given IDs are made non-selectable by SetSelected methods,
- * If True, the given IDs are made selectable.
- */
- Standard_EXPORT void SetSelectable (const TColStd_PackedMapOfInteger& IDs,
- const Standard_Boolean isSelectable);
-
- /**
- * Return True if the object can be selected (processing by SetSelected
- * methods), or False if can not be.
- * @return
- * Selectable state of the object.
- */
- inline Standard_Boolean IsSelectable (const Standard_Integer objID) const
- { return (myMapNonSelectableObjects.Contains( objID ) == Standard_False); }
-
- /**
- * Set or reset the flag that tells to NIS_Drawer to create shared DrawList.
- * The default mode (in Constructor) is True.
- */
- inline void SetShareDrawList (Standard_Boolean isShare)
- { myIsShareDrawList = isShare; }
-
- //@}
- // ====== END Selection API ================
-
- protected:
- //! Structure referencing one detected (picked) interactive entity.
- struct DetectedEnt
- {
- Standard_Real Dist; //!< Distance on the view direction
- NIS_InteractiveObject* PObj; //!< Pointer to interactive object
- };
-
- // ---------- PROTECTED METHODS ----------
-
- Standard_EXPORT void redraw (const Handle(NIS_View)& theView,
- const NIS_Drawer::DrawType theType);
-
- /**
- * Detect the object selected by the given ray.
- * @param theSel
- * <tt>[out]</tt> The selected object that has the lowest ray distance.
- * @param theDet
- * <tt>[out]</tt> Sorted list of all detected objects with ray distances
- * @param theAxis
- * Selection ray
- * @param theOver
- * Thickness of the selecting ray
- * @param isOnlySelectable
- * If False, any displayed object can be picked, otherwise only selectable
- * ones.
- * @return
- * The ray distance of the intersection point between the ray and theSel.
- */
- Standard_EXPORT Standard_Real
- selectObject (Handle(NIS_InteractiveObject)& theSel,
- NCollection_List<DetectedEnt>& theDet,
- const gp_Ax1& theAxis,
- const Standard_Real theOver,
- const Standard_Boolean isOnlySelectable
- = Standard_True) const;
-
- /**
- * Build a list of objects that are inside or touched by an oriented box.
- * @param mapObj
- * <tt>[out]</tt> Container of object IDs, updated by detected objects.
- * @param theBox
- * 3D box of selection
- * @param theTrf
- * Position/Orientation of the box (for box-box intersections)
- * @param theTrfInv
- * Inverted Position/Orientation of the box (for box-object intersections)
- * @param isFullyIn
- * True if only those objects are processed that are fully inside the
- * selection rectangle. False if objects fully or partially included in
- * the rectangle are processed.
- * @return
- * True if at least one object was selected.
- */
- Standard_EXPORT Standard_Boolean
- selectObjects (TColStd_PackedMapOfInteger& mapObj,
- const Bnd_B3f& theBox,
- const gp_Trsf& theTrf,
- const gp_Trsf& theTrfInv,
- const Standard_Boolean isFullyIn)const;
-
- /**
- * Build a list of objects that are inside or touched by a polygon.
- * @param mapObj
- * <tt>[out]</tt> Container of object IDs, updated by detected objects.
- * @param thePolygon
- * the list of vertices of a free-form closed polygon without
- * self-intersections. The last point should not coincide with the first
- * point of the list. Any two neighbor points should not be confused.
- * @param thePolygonBox
- * 2D box of selection polygon
- * @param theTrfInv
- * Inverted Position/Orientation of the plane where thePolygon is defined
- * (for polygon-object intersections)
- * @param isFullyIn
- * True if only those objects are processed that are fully inside the
- * selection polygon. False if objects fully or partially included in
- * the polygon are processed.
- * @return
- * True if at least one object was selected.
- */
- Standard_EXPORT Standard_Boolean
- selectObjects (TColStd_PackedMapOfInteger &mapObj,
- const NCollection_List<gp_XY> &thePolygon,
- const Bnd_B2f &thePolygonBox,
- const gp_Trsf &theTrfInv,
- const Standard_Boolean isFullyIn) const;
-
-private:
- void deselectObj (const Handle(NIS_InteractiveObject)&,
- const Standard_Integer);
-
- void selectObj (const Handle(NIS_InteractiveObject)&,
- const Standard_Integer);
-
- const Handle(NIS_Drawer)&
- drawerForDisplay (const Handle(NIS_InteractiveObject)&,
- const Handle(NIS_Drawer)&);
-
- void objectForDisplay (Handle(NIS_InteractiveObject)&,
- const NIS_Drawer::DrawType);
-
- Handle(NIS_Allocator)
- compactObjects ();
-
- private:
- // ---------- PRIVATE FIELDS ----------
-
- /**
- * Allocator for all data associated with objects.
- */
- Handle(NIS_Allocator) myAllocator;
-
- /**
- * The last added object ID.
- */
- Standard_Integer myLastObjectId;
- /**
- * Container of InteractiveObject instances.
- */
- NCollection_SparseArray <Handle(NIS_InteractiveObject)>
- myObjects;
-
- /**
- * List of Views.
- */
- NCollection_List <Handle(NIS_View)> myViews;
-
- /**
- * Container of Drawers. There should be one or more Drawers for each type of
- * contained InteractiveObject.
- */
- NCollection_Map <Handle(NIS_Drawer)> myDrawers;
-
- /**
- * Three maps indicating the state of contained objects:
- * - #0 - normally presented objects
- * - #1 - top objects
- * - #2 - hilighted objects (i.e., selected)
- * - #3 - transparent objects
- * Each object can have only one entry in these maps.
- */
- TColStd_PackedMapOfInteger myMapObjects[4];
-
- /**
- * Objects contained in this map are ignored by SetSelected methods,
- * these objects are not selectable.
- */
- TColStd_PackedMapOfInteger myMapNonSelectableObjects;
-
- /**
- * Instance of selection filter used for interactive selections.
- */
- Handle(NIS_SelectFilter) mySelectFilter;
-
- /**
- * Current mode of selection.
- */
- SelectionMode mySelectionMode;
-
- /**
- * Flag that allows to use single draw list for all views.
- */
- Standard_Boolean myIsShareDrawList;
-
- friend class NIS_View;
- friend class NIS_Drawer;
- friend class NIS_InteractiveObject;
- friend class NIS_ObjectsIterator;
-
- public:
-// Declaration of CASCADE RTTI
-DEFINE_STANDARD_RTTI (NIS_InteractiveContext)
-};
-
-// Definition of HANDLE object using Standard_DefineHandle.hxx
-DEFINE_STANDARD_HANDLE (NIS_InteractiveContext, Standard_Transient)
-
-
-#endif
+++ /dev/null
-// Created on: 2007-07-07
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2007-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <NIS_InteractiveObject.hxx>
-#include <NIS_InteractiveContext.hxx>
-#include <Standard_NullValue.hxx>
-
-IMPLEMENT_STANDARD_HANDLE (NIS_InteractiveObject, Standard_Transient)
-IMPLEMENT_STANDARD_RTTIEXT (NIS_InteractiveObject, Standard_Transient)
-
-//=======================================================================
-//function : ~NIS_InteractiveObject()
-//purpose : Destructor
-//=======================================================================
-
-NIS_InteractiveObject::~NIS_InteractiveObject ( )
-{
- if (myID != 0 && myDrawer.IsNull() == Standard_False)
- myDrawer->removeObject( this, Standard_False);
-}
-
-//=======================================================================
-//function : SetDrawer
-//purpose :
-//=======================================================================
-
-const Handle(NIS_Drawer)& NIS_InteractiveObject::SetDrawer
- (const Handle(NIS_Drawer)& theDrawer,
- const Standard_Boolean setUpdated)
-{
- NIS_InteractiveContext * aCtx = theDrawer->GetContext();
- if (myDrawer.IsNull() == Standard_False) {
- if (aCtx == 0L)
- {
- aCtx = myDrawer->GetContext();
- theDrawer->myCtx = aCtx;
- }
- else
- {
- Standard_NullValue_Raise_if
- (myDrawer->GetContext() != 0L && aCtx != myDrawer->GetContext(),
- "NIS_InteractiveObject::SetDrawer: different drawer context");
- }
- }
-
- Standard_NullValue_Raise_if
- (aCtx == 0L, "NIS_InteractiveObject::SetDrawer: NULL drawer context");
- // Add (if necessary) the new drawer to the Context
- if (theDrawer->myIniId == 0)
- theDrawer->myIniId = myID;
- const Handle(NIS_Drawer)& aDrawer = aCtx->myDrawers.Added (theDrawer);
- if (myDrawer != aDrawer)
- {
- // Move the Object from the old drawer to the new one.
- if (myDrawer.IsNull() == Standard_False)
- myDrawer->removeObject(this, Standard_True);
- myDrawer = aDrawer;
-
- myDrawer->addObject(this, aCtx->myIsShareDrawList, Standard_True);
- }
- if (setUpdated)
- myDrawer->SetUpdated (NIS_Drawer::Draw_Normal,
- NIS_Drawer::Draw_Top,
- NIS_Drawer::Draw_Transparent,
- NIS_Drawer::Draw_Hilighted);
- return aDrawer;
-}
-
-//=======================================================================
-//function : SetTransparency
-//purpose :
-//=======================================================================
-
-void NIS_InteractiveObject::SetTransparency (const Standard_Real theValue)
-{
- Standard_Integer aValue =
- static_cast<Standard_Integer> (theValue * MaxTransparency);
- if (aValue != static_cast<Standard_Integer>(myTransparency))
- {
- if (aValue <= 0)
- myTransparency = 0;
- else if (aValue >= 1000)
- myTransparency = 1000u;
- else
- myTransparency = static_cast<unsigned int> (aValue);
-
- if (myDrawer.IsNull() == Standard_False && myID != 0) {
- const Handle(NIS_Drawer) aDrawer = DefaultDrawer(0L);
- aDrawer->Assign (GetDrawer());
- aDrawer->myTransparency = Transparency();
- SetDrawer (aDrawer, Standard_False);
-
- NIS_InteractiveContext * aCtx = myDrawer->GetContext();
- Standard_NullValue_Raise_if
- (aCtx == 0L, "NIS_InteractiveObject::SetTransparency: "
- "NULL drawer context");
- if (IsTransparent()) {
- if (myDrawType == NIS_Drawer::Draw_Normal) {
- aCtx->myMapObjects[NIS_Drawer::Draw_Transparent].Add(myID);
- aCtx->myMapObjects[NIS_Drawer::Draw_Normal].Remove(myID);
- myDrawType = NIS_Drawer::Draw_Transparent;
- }
- myDrawer->SetUpdated (NIS_Drawer::Draw_Normal);
- } else {
- if (myDrawType == NIS_Drawer::Draw_Transparent) {
- aCtx->myMapObjects[NIS_Drawer::Draw_Normal].Add(myID);
- aCtx->myMapObjects[NIS_Drawer::Draw_Transparent].Remove(myID);
- myDrawType = NIS_Drawer::Draw_Normal;
- }
- myDrawer->SetUpdated (NIS_Drawer::Draw_Transparent);
- }
- setDrawerUpdate();
- }
- }
-}
-
-//=======================================================================
-//function : GetBox
-//purpose :
-//=======================================================================
-
-const Bnd_B3f& NIS_InteractiveObject::GetBox ()
-{
- if (myIsUpdateBox)
- {
- myIsUpdateBox = Standard_False;
- computeBox();
- }
- return myBox;
-}
-
-//=======================================================================
-//function : Clone
-//purpose :
-//=======================================================================
-
-void NIS_InteractiveObject::Clone (const Handle(NCollection_BaseAllocator)&,
- Handle(NIS_InteractiveObject)& theDest) const
-{
- if (theDest.IsNull() == Standard_False)
- {
- theDest->myID = 0;
- theDest->myDrawer = myDrawer;
- theDest->myDrawType = myDrawType;
- theDest->myBaseType = myBaseType;
- theDest->myIsHidden = myIsHidden;
- theDest->myIsDynHilighted = myIsDynHilighted;
- theDest->myIsUpdateBox = myIsUpdateBox;
- theDest->myTransparency = myTransparency;
- if (myIsUpdateBox == Standard_False)
- theDest->myBox = myBox;
- theDest->myAttributePtr = myAttributePtr;
- }
-}
-
-//=======================================================================
-//function : CloneWithID
-//purpose :
-//=======================================================================
-
-void NIS_InteractiveObject::CloneWithID
- (const Handle(NCollection_BaseAllocator)& theAlloc,
- Handle(NIS_InteractiveObject)& theDest)
-{
- Clone(theAlloc, theDest);
- theDest->myID = myID;
- myDrawer.Nullify();
-}
-
-//=======================================================================
-//function : Intersect
-//purpose :
-//=======================================================================
-
-Standard_Boolean NIS_InteractiveObject::Intersect (const Bnd_B3f&,
- const gp_Trsf&,
- const Standard_Boolean) const
-{
- return Standard_True;
-}
-
-//=======================================================================
-//function : Intersect
-//purpose :
-//=======================================================================
-
-Standard_Boolean NIS_InteractiveObject::Intersect
- (const NCollection_List<gp_XY>& ,
- const gp_Trsf& ,
- const Standard_Boolean ) const
-{
- return Standard_True;
-}
-
-//=======================================================================
-//function : IsSelectable
-//purpose : Query if the Object is selectable.
-//=======================================================================
-
-Standard_Boolean NIS_InteractiveObject::IsSelectable () const
-{
- Standard_Boolean aResult(Standard_False);
- if (myDrawer.IsNull() == Standard_False)
- aResult = myDrawer->GetContext()->IsSelectable (myID);
- return aResult;
-}
-
-//=======================================================================
-//function : SetSelectable
-//purpose : Set or change the selectable state of the Object.
-//=======================================================================
-
-void NIS_InteractiveObject::SetSelectable (const Standard_Boolean isSel) const
-{
- if (myDrawer.IsNull() == Standard_False) {
- NIS_InteractiveContext * aCtx = myDrawer->GetContext();
- if (isSel)
- aCtx->myMapNonSelectableObjects.Remove (myID);
- else {
- aCtx->myMapNonSelectableObjects.Add (myID);
- if (myDrawType == NIS_Drawer::Draw_Hilighted)
- {
- aCtx->myMapObjects[NIS_Drawer::Draw_Hilighted].Remove(myID);
- aCtx->deselectObj (this, myID);
- }
- }
- }
-}
+++ /dev/null
-// Created on: 2007-07-06
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2007-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#ifndef NIS_InteractiveObject_HeaderFile
-#define NIS_InteractiveObject_HeaderFile
-
-#include <NIS_Drawer.hxx>
-#include <Bnd_B3f.hxx>
-
-/**
- * Abstract base type for presentable and selectable object in NIS architecture.
- * @section InteractiveObject_class
- * An InteractiveObject has the attributes:
- * <ul>
- * <li>Integer ID that is unique within the Interactive Context that hosts
- * this Object. This ID is 0 if the Object is not yet attached to an
- * InteractiveContext</li>
- * <li>3D Bounding box</li>
- * <li>Presentable state of the Object: Normal, Hilighted or Transparent.</li>
- * <li>Visibility state (shown/hidden)</li>
- * <li>Selectability (selectable/non-selectable)</li>
- * <li>Transparency level (0 to 1 in 1/1000 steps) - for transparent state</li>
- * </ul>
- * Because the class is abstract, it does not define any color, material and
- * other visual aspect - all relevant aspects should be defined in derived
- * classes and their Drawers.
- *
- * @section nis_interactiveobject_drawer Drawers for NIS_InteractiveObject
- * Every InteractiveObject type should have an associated NIS_Drawer type; a
- * new instance of this associated drawer must be returned by the virtual method
- * DefaultDrawer(). The drawer is responsible for the correct calculation of
- * the presentation in every possible state (normal, hilighted, etc.); usually
- * the associated drawer instance contains all relevant visual aspects.
- * <p>
- * Association with a Drawer instance is performed by method SetDrawer(). This
- * method should not be called by any custom code, it is used internally by
- * NIS algorithms (in NIS_InteractiveContext::Display() for instance). If you
- * develop your own InteractiveObject type, you will need to call SetDrawer
- * whenever you change the visual aspect, for example:
- * @code
- * void MyIOClass::SetColor (const Quantity_Color& theColor);
- * {
- * const Handle(MyIOClassDrawer) aDrawer =
- * static_cast<MyIOClassDrawer*>(DefaultDrawer(0L));
- * // copy the current visual aspects and other attributes to the new Drawer
- * aDrawer->Assign (GetDrawer());
- * // replace the Drawer
- * aDrawer->myColor = theColor;
- * SetDrawer (aDrawer);
- * }
- * @endcode
- * Please keep in mind that with this scheme you should not store the color in
- * MyIOClass type, because it is already stored in its Drawer.
- *
- * @section nis_interactiveobject_selection Interactive selection
- * Interactive selection is made in class NIS_InteractiveContext, methods
- * selectObjects(). These methods call the virtual API of interactive object,
- * that consists of 3 methods:
- * <ul>
- * <li>Intersect (theAxis, theOver) : find the intersection point with a 3D ray,
- * the method returns the coordinate of intersection point on the ray.
- * Parameter theOver provides the tolerance for intersection of thin
- * geometries (lines, vertices)</li>
- * <li>Intersect (theBox, theTrsf, isFullIn) : check if the interactive object
- * intersects with a 3D box. Transformation 'theTrf' is the <b>inverse</b>
- * box transformation, so it is applied to the interactive object rather
- * than to the 3D box (3D box stays axis-aligned during intersection
- * test). Parameter IsFullIn defines the condition for the result: if
- * True then the whole interactive object must be contained inside the box,
- * otherwise it is sufficient if only a portion (e.g., a point) is inside.
- * This method is used for interactive rectangle selection.</li>
- * <li>Intersect (thePolygon, theTrsf, isFullIn) : similar to the previous
- * method, but using a polygonal prism instead of box, for selection by
- * closed curve or polygon.</li>
- * </ul>
- *
- * @section nis_interactiveobject_memory Memory management
- * All data used in the scope of NIS_InteractiveObject subtype should be either
- * its explicit fields or pointers to memory managed by a special NIS_Allocator
- * instance that belongs to NIS_InteractiveContext. This is strictly required
- * because NIS_InteractiveContext should completely manage all its objects,
- * meaning that it destroys/reallocates them automatically. To support that,
- * the virtual method Clone() should be correctly defined for every interactive
- * object subtype. Supposing that MyIOClass inherits MyBaseIOBase :
- * @code
- * void MyIOCalss::Clone (const Handle(NCollection_BaseAllocator)& theAlloc,
- * Handle(NIS_InteractiveObject)& theDest) const
- * {
- * Handle(MyIOClass) aNewObj;
- * if (theDest.IsNull()) {
- * aNewObj = new MyIOClass();
- * theDest = aNewObj;
- * } else {
- * aNewObj = reinterpret_cast<MyIOClass*> (theDest.operator->());
- * aNewObj->myAlloc = theAlloc;
- * }
- * MyIOBase::Clone(theAlloc, theDest);
- * aNewObj->myDataField = myDataField;
- * memcpy(myNewObj->myDataArray, myDataArray, nBytes);
- * ...
- * }
- * @endcode
- *
- * @section nis_interactiveobject_attribute Attribute
- * An instance of this class can have an associated value (Attribute) that is
- * stored as a pointer. It can accommodate an integer/float/boolean value or
- * a pointer to some structure. This attribute is NOT automatically destroyed
- * with the InteractiveObject.
- */
-
-class NIS_InteractiveObject : public Standard_Transient
-{
- public:
- // ---------- PUBLIC METHODS ----------
-
-
- /**
- * Empty constructor. Creates an object that is not attached to drawer.
- */
- inline NIS_InteractiveObject ()
- : myID (0),
- myDrawType (NIS_Drawer::Draw_Normal),
- myBaseType (NIS_Drawer::Draw_Normal),
- myIsHidden (Standard_True),
- myIsDynHilighted (Standard_False),
- myIsUpdateBox (Standard_True),
- myTransparency (0),
- myAttributePtr (0L)
- {}
-
- /**
- * Destructor.
- */
- Standard_EXPORT virtual ~NIS_InteractiveObject ();
-
- /**
- * Query the ID of the Object in its Context.
- */
- inline Standard_Integer ID () const
- { return Standard_Integer (myID); }
-
- /**
- * Query the type of presentation.
- */
- inline NIS_Drawer::DrawType
- DrawType () const
- { return myDrawType; }
-
- /**
- * Replace the drawer. This method must not be called for Object that
- * has not yet been added to a Context (thus has empty drawer).
- * It is possible to have unassigned myDrawer or a DefaultDrawer as the
- * parameter value (but not both). The Context where we work is taken
- * from theDrawer first, then (if NULL) -- from myDrawer.
- * This method matches theDrawer with the available Drawers in the Context
- * and adds if no match is found.
- * @return
- * Reference to the finally stored or found Drawer instance inside
- * the Context.
- */
- Standard_EXPORT const Handle(NIS_Drawer)&
- SetDrawer (const Handle(NIS_Drawer)& theDrawer,
- const Standard_Boolean setUpdated
- = Standard_True);
-
- /**
- * Query the current drawer.
- */
- inline const Handle(NIS_Drawer)&
- GetDrawer () const
- { return myDrawer; }
-
- /**
- * Create a default drawer instance. In the upper-level call (in subclass)
- * it is always called with NULL parameter. Then it should call the same
- * method of the superclass (except for NIS_InteractiveObject superclass type)
- * with the created Drawer instance as parameter.
- * @see NIS_Triangulated as example.
- */
- Standard_EXPORT virtual NIS_Drawer *
- DefaultDrawer (NIS_Drawer * theDrv) const = 0;
-
- /**
- * Query a 3D bounding box of the object.
- */
- Standard_EXPORT const Bnd_B3f&
- GetBox ();
-
- /**
- * Query the Transparent state.
- */
- inline Standard_Boolean IsTransparent () const
- { return myTransparency > 0; }
-
- /**
- * Query the Hidden state
- */
- inline Standard_Boolean IsHidden () const
- { return myIsHidden; }
-
- /**
- * Query the Displayed state - opposite to IsHidden().
- */
- inline Standard_Boolean IsDisplayed () const
- { return !myIsHidden; }
-
- /**
- * Query the Dynamic Hilight state
- */
- inline Standard_Boolean IsDynHilighted() const
- { return myIsDynHilighted; }
-
- /**
- * Query if the Object is selectable.
- */
- Standard_EXPORT virtual Standard_Boolean
- IsSelectable () const;
-
- /**
- * Set or change the selectable state of the Object.
- * @param isSel
- * True (default) - the Object will be selectable, False - it will be
- * ignored by selection/hilighting algorithms.
- */
- Standard_EXPORT virtual void
- SetSelectable (const Standard_Boolean isSel
- = Standard_True) const;
-
- /**
- * Query the Transparency factor.
- */
- inline Standard_ShortReal Transparency () const
- { return static_cast<Standard_ShortReal>(myTransparency) / MaxTransparency; }
-
- /**
- * Set the Transparency factor.
- */
- Standard_EXPORT void SetTransparency (const Standard_Real theValue = 0.6);
-
- /**
- * Present the Object as opaque (Normal draw type).
- */
- inline void UnsetTransparency ()
- { SetTransparency (0.); }
-
- /**
- * Create a copy of theObject except its ID.
- * @param theAll
- * Allocator where the Dest should store its private data.
- * @param theDest
- * <tt>[in-out]</tt> The target object where the data are copied.
- */
- Standard_EXPORT virtual void
- Clone (const Handle(NCollection_BaseAllocator)& theAll,
- Handle(NIS_InteractiveObject)& theDest) const;
-
- /**
- * The same as Clone() but also copies the ID.
- */
- Standard_EXPORT void CloneWithID (const Handle(NCollection_BaseAllocator)&,
- Handle(NIS_InteractiveObject)&);
-
- /**
- * Intersect the InteractiveObject geometry with a line/ray.
- * @param theAxis
- * The line or ray in 3D space.
- * @param theOver
- * Half-thickness of the selecting line.
- * @return
- * If the return value is more than 0.1*RealLast() then no intersection is
- * detected. Otherwise returns the coordinate of thePnt on the ray. May be
- * negative.
- */
- Standard_EXPORT virtual Standard_Real
- Intersect (const gp_Ax1& theAxis,
- const Standard_Real theOver)const = 0;
-
- /**
- * Intersect the InteractiveObject geometry with an oriented box.
- * The default implementation (in this abstract class) always returns True,
- * signalling that every object pre-selected by its bounding box is
- * automatically selected. The specializations should define a more correct behaviour.
- * The algorithm should transform the InteractiveObject geometry using the
- * parameter theTrf and then reject it with box theBox, like:
- * @code
- * gp_Pnt aPnt = ..... // aPnt is part of our geometry.
- * if (!theBox.IsOut (aPnt.Transformed(theTrf)))
- * return Standard_True;
- * @endcode
- * @param theBox
- * 3D box of selection
- * @param theTrf
- * Position/Orientation of the box. It coincides with theTrfInv that is
- * passed to NIS_InteractiveObject::selectObjects().
- * @param isFull
- * True if full inclusion is required (full inside the tested box) for
- * the positive result, False - if only partial inclusion give a result.
- * @return
- * True if the InteractiveObject geometry intersects the box or is inside it
- */
- Standard_EXPORT virtual Standard_Boolean
- Intersect (const Bnd_B3f& theBox,
- const gp_Trsf& theTrf,
- const Standard_Boolean isFull) const;
-
- /**
- * Intersect the InteractiveObject geometry with a selection polygon.
- * The default implementation (in this abstract class) always returns True,
- * signalling that every object pre-selected by its bounding box is
- * automatically selected. The specializations should define a more correct behaviour.
- * The algorithm should transform the InteractiveObject geometry using the
- * parameter theTrf and then reject it with polygon.
- * @param thePolygon
- * the list of vertices of a free-form closed polygon without
- * self-intersections. The last point should not coincide with the first
- * point of the list. Any two neighbor points should not be confused.
- * @param theTrf
- * Position/Orientation of the polygon. It coincides with theTrfInv that is
- * passed to NIS_InteractiveContext::selectObjects().
- * @param isFull
- * True if full inclusion is required (full inside the tested box) for
- * the positive result, False - if only partial inclusion give a result.
- * @return
- * True if the InteractiveObject geometry intersects the polygon or is inside it
- */
- Standard_EXPORT virtual Standard_Boolean
- Intersect (const NCollection_List<gp_XY> &thePolygon,
- const gp_Trsf &theTrf,
- const Standard_Boolean isFull) const;
-
- /**
- * Set the pointer to custom (arbitrary) data associated with the Object.
- */
- inline void SetAttribute (void * theAttributePtr)
- { myAttributePtr = theAttributePtr; }
-
- /**
- * Query the associated custom (arbitrary) attribute pointer.
- */
- inline void * GetAttribute () const
- { return myAttributePtr; }
-
- protected:
- // ---------- PROTECTED METHODS ----------
-
- inline void setDrawerUpdate () const
- { myDrawer->SetUpdated (myDrawType); }
-
- /**
- * Create a 3D bounding box of the object.
- */
- Standard_EXPORT virtual void
- computeBox () = 0;
-
- inline Standard_Boolean isUpdateBox () const
- { return myIsUpdateBox; }
-
- inline void setIsUpdateBox (const Standard_Boolean isUpdate)
- { myIsUpdateBox = isUpdate; }
-
- private:
- // ---------- PRIVATE (PROHIBITED) METHODS ----------
-
- NIS_InteractiveObject (const NIS_InteractiveObject& theOther);
- NIS_InteractiveObject& operator = (const NIS_InteractiveObject& theOther);
-
- private:
- // ---------- PRIVATE FIELDS ----------
-
- Handle(NIS_Drawer) myDrawer;
- Standard_Integer myID;
- NIS_Drawer::DrawType myDrawType : 3;
- NIS_Drawer::DrawType myBaseType : 3;
- Standard_Boolean myIsHidden : 1;
- Standard_Boolean myIsDynHilighted: 1;
-
- Standard_Boolean myIsUpdateBox : 1;
- unsigned int myTransparency : 10;
- static const unsigned int MaxTransparency = 1000;
-
-protected:
- Bnd_B3f myBox;
- void * myAttributePtr;
-
-
- friend class NIS_InteractiveContext;
- friend class NIS_Drawer;
-
- public:
-// Declaration of CASCADE RTTI
-DEFINE_STANDARD_RTTI (NIS_InteractiveObject)
-};
-
-#include <Handle_NIS_InteractiveObject.hxx>
-
-#endif
+++ /dev/null
-// Created on: 2007-09-03
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2007-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <NIS_ObjectsIterator.hxx>
-#include <NIS_InteractiveContext.hxx>
-
-//=======================================================================
-//function : NIS_ObjectsIterator()
-//purpose : Constructor
-//=======================================================================
-
-void NIS_ObjectsIterator::Initialize
- (const Handle(NIS_InteractiveContext)& theCtx)
-{
- if (theCtx.IsNull())
- myIter = NCollection_SparseArray <Handle(NIS_InteractiveObject)>::Iterator();
- else
- for (myIter.Init (theCtx->myObjects); myIter.More(); myIter.Next())
- if (myIter.Value().IsNull() == Standard_False)
- break;
-}
-
-//=======================================================================
-//function : Next
-//purpose :
-//=======================================================================
-
-void NIS_ObjectsIterator::Next ()
-{
- for (myIter.Next(); myIter.More(); myIter.Next())
- if (myIter.Value().IsNull() == Standard_False)
- break;
-}
-
-//=======================================================================
-//function : Value
-//purpose :
-//=======================================================================
-
-const Handle(NIS_InteractiveObject)& NIS_ObjectsIterator::Value() const
-{
- if (More())
- return myIter.Value();
- static const Handle(NIS_InteractiveObject) aNullObj;
- return aNullObj;
-}
+++ /dev/null
-// Created on: 2007-09-02
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2007-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#ifndef NIS_ObjectsIterator_HeaderFile
-#define NIS_ObjectsIterator_HeaderFile
-
-#include <NCollection_SparseArray.hxx>
-#include <Handle_NIS_InteractiveObject.hxx>
-
-class Handle(NIS_InteractiveContext);
-
-/**
- * Iterator of objects contained in a NIS_InteractiveContext instance. The
- * iteration is always in the ascending sense of object ID. Examples:
- * @code
- * // Erase all objects in the Context
- * NIS_ObjectsIterator anIter (myContext);
- * for (; anIter.More(); anIter.Next())
- * myContext->Erase (anIter.Value(), Standard_False);
- *
- * // Set object attributes to their IDs (hardly useful outside the example)
- * anIter.Initialize (myContext);
- * Handle(NIS_InteractiveObject) anObj;
- * while (!(anObj = anIter.Value().IsNull())) {
- * anObj->SetAttribute (static_cast<void *> (anObj->ID()));
- * anIter.Next();
- * }
- * @endcode
- */
-
-class NIS_ObjectsIterator
-{
- public:
- // ---------- PUBLIC METHODS ----------
-
-
- /**
- * Empty Constructor.
- */
- inline NIS_ObjectsIterator () {}
-
- /**
- * Constructor.
- * @param theCtx
- * Interactive context that is to be iterated for all objects.
- */
- inline NIS_ObjectsIterator (const Handle(NIS_InteractiveContext)& theCtx)
- { Initialize (theCtx); }
-
- /**
- * Reset the Iterator to start the iterations of objects.
- * @param theCtx
- * Interactive context that is to be iterated for all objects.
- */
- Standard_EXPORT void Initialize
- (const Handle(NIS_InteractiveContext)& theCtx);
-
- /**
- * Query if the Iterator has an object (not yet finished the iteration
- * process).
- */
- inline Standard_Boolean More () const
- { return myIter.More(); }
-
- /**
- * Returns the current object at the iteration pointer. If the iteration is
- * over (More() == False) this method returns NULL Handle.
- */
- Standard_EXPORT const Handle(NIS_InteractiveObject)&
- Value () const;
-
- /**
- * Step forward to the next valid InteractiveObject instance.
- */
- Standard_EXPORT void Next ();
-
- protected:
- // ---------- PROTECTED FIELDS ----------
-
- NCollection_SparseArray <Handle(NIS_InteractiveObject)>::ConstIterator myIter;
-
-};
-
-#endif
+++ /dev/null
-// Created on: 2007-08-20
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2007-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <NIS_SelectFilter.hxx>
-
-IMPLEMENT_STANDARD_HANDLE (NIS_SelectFilter, Standard_Transient)
-IMPLEMENT_STANDARD_RTTIEXT (NIS_SelectFilter, Standard_Transient)
-
-//=======================================================================
-//function : ActsOn
-//purpose :
-//=======================================================================
-
-Standard_Boolean NIS_SelectFilter::ActsOn (const Handle(Standard_Type)&) const
-{
- return Standard_True;
-}
-
-
+++ /dev/null
-// Created on: 2007-08-20
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2007-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#ifndef NIS_SelectFilter_HeaderFile
-#define NIS_SelectFilter_HeaderFile
-
-#include <Standard_DefineHandle.hxx>
-#include <Standard_Transient.hxx>
-
-class NIS_InteractiveObject;
-class Handle(Standard_Type);
-
-/**
- * Interface for selection filters. It can be used in NIS_InteractiveContext by methods SetFilter and GetFilter.
- * Unlike in AIS, only one filter can be installed in InteractiveContext.
- * If you need more than one filter instance to work together, create a composite
- * NIS_SelectFilter specialization that would hold a list of simpler Filter instances.
- */
-class NIS_SelectFilter : public Standard_Transient
-{
- public:
- // ---------- PUBLIC METHODS ----------
-
-
- /**
- * Empty constructor.
- */
- inline NIS_SelectFilter () {}
-
- /**
- * Indicate that the given NIS_InteractiveObject passes the Filter.
- * @return
- * True - theObject is kept in the Selection, False - excluded from it.
- */
- virtual Standard_Boolean
- IsOk (const NIS_InteractiveObject * theObject) const = 0;
-
- /**
- * Check if the type of InteractiveObject is allowed for selection.
- * Default implementation returns always True.
- * @return
- * True if objects of the given Type should be checked, False if such
- * objects are excluded from Selection before any checking.
- */
- Standard_EXPORT virtual Standard_Boolean
- ActsOn (const Handle(Standard_Type)& theType) const;
-
-
- protected:
- // ---------- PROTECTED METHODS ----------
-
-
-
-
- public:
-// Declaration of CASCADE RTTI
-DEFINE_STANDARD_RTTI (NIS_SelectFilter)
-};
-
-// Definition of HANDLE object using Standard_DefineHandle.hxx
-DEFINE_STANDARD_HANDLE (NIS_SelectFilter, Standard_Transient)
-
-#endif
+++ /dev/null
-// Created on: 2008-03-20
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2008-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <NIS_Surface.hxx>
-#include <NIS_SurfaceDrawer.hxx>
-#include <NIS_Triangulated.hxx>
-#include <BRepMesh_IncrementalMesh.hxx>
-#include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
-#include <BRep_PolygonOnTriangulation.hxx>
-#include <BRep_TEdge.hxx>
-#include <BRep_Tool.hxx>
-#include <Geom_Surface.hxx>
-#include <NCollection_Map.hxx>
-#include <Poly_PolygonOnTriangulation.hxx>
-#include <Poly_Triangulation.hxx>
-#include <Precision.hxx>
-#include <TColgp_Array1OfPnt2d.hxx>
-#include <TopExp.hxx>
-#include <TopExp_Explorer.hxx>
-#include <TopLoc_Location.hxx>
-#include <TopTools_MapOfShape.hxx>
-#include <TopoDS.hxx>
-#include <TopoDS_Face.hxx>
-#include <TopoDS_Edge.hxx>
-#include <TShort_Array1OfShortReal.hxx>
-#include <gp_Ax1.hxx>
-
-IMPLEMENT_STANDARD_HANDLE (NIS_Surface, NIS_InteractiveObject)
-IMPLEMENT_STANDARD_RTTIEXT(NIS_Surface, NIS_InteractiveObject)
-
-//=======================================================================
-//function : IsEqual
-//purpose : Compare two triangulations, for NCollection_Map interface.
-//=======================================================================
-
-inline Standard_Boolean IsEqual(const Handle(Poly_Triangulation)& theT0,
- const Handle(Poly_Triangulation)& theT1)
-{
- return (theT0 == theT1);
-}
-
-//=======================================================================
-//function : NIS_Surface
-//purpose :
-//=======================================================================
-
-NIS_Surface::NIS_Surface(const Handle(NCollection_BaseAllocator)& theAlloc)
- : myAlloc (theAlloc),
- mypNodes (NULL),
- mypNormals (NULL),
- mypTriangles (NULL),
- mypEdges (NULL),
- myNNodes (0),
- myNTriangles (0),
- myNEdges (0),
- myIsWireframe(0)
-{
- if (myAlloc.IsNull())
- myAlloc = NCollection_BaseAllocator::CommonBaseAllocator();
-}
-
-//=======================================================================
-//function : NIS_Surface
-//purpose :
-//=======================================================================
-
-NIS_Surface::NIS_Surface (const Handle(Poly_Triangulation)& theTri,
- const Handle(NCollection_BaseAllocator)& theAlloc)
- : myAlloc (theAlloc),
- mypNodes (NULL),
- mypNormals (NULL),
- mypEdges (NULL),
- myNNodes (0),
- myNTriangles (0),
- myNEdges (0),
- myIsWireframe(0)
-{
- if (myAlloc.IsNull())
- myAlloc = NCollection_BaseAllocator::CommonBaseAllocator();
- if (theTri.IsNull() == Standard_False)
- {
- // Alocate arrays of entities
- myNNodes = 3 * theTri->NbTriangles();
- myNTriangles = theTri->NbTriangles();
- mypNodes = static_cast<Standard_ShortReal*>
- (myAlloc->Allocate(sizeof(Standard_ShortReal) * 3 * myNNodes));
- mypNormals = static_cast<Standard_ShortReal *>
- (myAlloc->Allocate(sizeof(Standard_ShortReal) * 3 * myNNodes));
- mypTriangles = static_cast<Standard_Integer*>
- (myAlloc->Allocate(sizeof(Standard_Integer) * 3 * myNTriangles));
-
- // Copy the data from the original triangulation.
- Standard_Integer i, iN(0), iT(0);
- const Poly_Array1OfTriangle& arrTri = theTri->Triangles();
- const TColgp_Array1OfPnt& arrNodes = theTri->Nodes();
- for (i = arrTri.Lower(); i <= arrTri.Upper(); i++) {
- Standard_Integer iNode[3];
- arrTri(i).Get(iNode[0], iNode[1], iNode[2]);
- gp_XYZ aNorm = ((arrNodes(iNode[1]).XYZ() - arrNodes(iNode[0]).XYZ()) ^
- (arrNodes(iNode[2]).XYZ() - arrNodes(iNode[0]).XYZ()));
- const Standard_Real aMagn = aNorm.Modulus();
- if (aMagn > Precision::Confusion())
- aNorm /= aMagn;
- else
- aNorm.SetCoord(0., 0., 1.);
- mypNodes[iN+0] = static_cast<Standard_ShortReal>(arrNodes(iNode[0]).X());
- mypNodes[iN+1] = static_cast<Standard_ShortReal>(arrNodes(iNode[0]).Y());
- mypNodes[iN+2] = static_cast<Standard_ShortReal>(arrNodes(iNode[0]).Z());
- mypNodes[iN+3] = static_cast<Standard_ShortReal>(arrNodes(iNode[1]).X());
- mypNodes[iN+4] = static_cast<Standard_ShortReal>(arrNodes(iNode[1]).Y());
- mypNodes[iN+5] = static_cast<Standard_ShortReal>(arrNodes(iNode[1]).Z());
- mypNodes[iN+6] = static_cast<Standard_ShortReal>(arrNodes(iNode[2]).X());
- mypNodes[iN+7] = static_cast<Standard_ShortReal>(arrNodes(iNode[2]).Y());
- mypNodes[iN+8] = static_cast<Standard_ShortReal>(arrNodes(iNode[2]).Z());
- mypNormals[iN+0] = static_cast<Standard_ShortReal>(aNorm.X());
- mypNormals[iN+1] = static_cast<Standard_ShortReal>(aNorm.Y());
- mypNormals[iN+2] = static_cast<Standard_ShortReal>(aNorm.Z());
- mypNormals[iN+3] = static_cast<Standard_ShortReal>(aNorm.X());
- mypNormals[iN+4] = static_cast<Standard_ShortReal>(aNorm.Y());
- mypNormals[iN+5] = static_cast<Standard_ShortReal>(aNorm.Z());
- mypNormals[iN+6] = static_cast<Standard_ShortReal>(aNorm.X());
- mypNormals[iN+7] = static_cast<Standard_ShortReal>(aNorm.Y());
- mypNormals[iN+8] = static_cast<Standard_ShortReal>(aNorm.Z());
- mypTriangles[iT+0] = iT+0;
- mypTriangles[iT+1] = iT+1;
- mypTriangles[iT+2] = iT+2;
- iN += 9;
- iT += 3;
- }
- }
-}
-
-//=======================================================================
-//function : NIS_Surface
-//purpose : Constructor
-//=======================================================================
-
-NIS_Surface::NIS_Surface (const TopoDS_Shape& theShape,
- const Standard_Real theDeflection,
- const Handle(NCollection_BaseAllocator)& theAlloc)
- : myAlloc (theAlloc),
- mypNodes (NULL),
- mypNormals (NULL),
- mypTriangles (NULL),
- mypEdges (NULL),
- myNNodes (0),
- myNTriangles (0),
- myNEdges (0),
- myIsWireframe (0)
-{
- if (myAlloc.IsNull())
- myAlloc = NCollection_BaseAllocator::CommonBaseAllocator();
- Init (theShape, theDeflection);
-}
-
-//=======================================================================
-//function : Init
-//purpose : Initialize the instance with a TopoDS_Shape.
-//=======================================================================
-
-void NIS_Surface::Init (const TopoDS_Shape& theShape,
- const Standard_Real theDeflection)
-{
- TopLoc_Location aLoc, aLocSurf;
-
- // Count the nodes and triangles in faces
- NCollection_Map<Handle(Poly_Triangulation)> mapTri;
- TopExp_Explorer fexp (theShape, TopAbs_FACE);
- for (; fexp.More(); fexp.Next())
- {
- const TopoDS_Face& aFace = TopoDS::Face(fexp.Current());
-
- const Handle(Poly_Triangulation)& aTriangulation
- = BRep_Tool::Triangulation (aFace, aLoc);
-
- if (aTriangulation.IsNull())
- BRepMesh_IncrementalMesh aMeshTool(aFace, theDeflection);
-
- if (aTriangulation.IsNull() == Standard_False)
- {
- myNNodes += aTriangulation->NbNodes();
- myNTriangles += aTriangulation->NbTriangles();
- mapTri.Add(aTriangulation);
- }
- }
-
- // Create map of edges, to build wireframe for all edges.
- TopTools_MapOfShape mapEdges;
- TopExp_Explorer eexp (theShape, TopAbs_EDGE);
- for (; eexp.More(); eexp.Next())
- {
- const TopoDS_Shape& anEdge = eexp.Current();
- mapEdges.Add(anEdge);
- }
-
- // Allocate arrays of entities
- if (myNNodes && myNTriangles) {
- mypNodes = static_cast<Standard_ShortReal *>
- (myAlloc->Allocate(sizeof(Standard_ShortReal) * 3 * myNNodes));
- mypNormals = static_cast<Standard_ShortReal *>
- (myAlloc->Allocate(sizeof(Standard_ShortReal) * 3 * myNNodes));
- mypTriangles = static_cast<Standard_Integer *>
- (myAlloc->Allocate(sizeof(Standard_Integer) * 3 * myNTriangles));
- mypEdges = static_cast<Standard_Integer **>
- (myAlloc->Allocate(sizeof(Standard_Integer *) * mapEdges.Extent()));
- myNEdges = 0;
-
- // The second loop: copy all nodes and triangles face-by-face
- const Standard_Real eps2 = Precision::SquareConfusion();
- Standard_Integer nNodes (0), nTriangles (0);
- for (fexp.ReInit(); fexp.More(); fexp.Next())
- {
- const TopoDS_Face& aFace = TopoDS::Face(fexp.Current());
- const Handle(Geom_Surface)& aSurf = BRep_Tool::Surface(aFace, aLocSurf);
- const Handle(Poly_Triangulation)& aTriangulation =
- BRep_Tool::Triangulation(aFace, aLoc);
- if (aTriangulation.IsNull() == Standard_False)
- {
- // Prepare transformation
- Standard_Integer i, aNodeInd(nNodes)/*, aNTriangles = 0*/;
- const gp_Trsf& aTrf = aLoc.Transformation();
- const gp_Trsf& aTrfSurf = aLocSurf.Transformation();
- Standard_Boolean isReverse = (aFace.Orientation() == TopAbs_REVERSED);
-
- // Store all nodes of the current face in the data model
- const TColgp_Array1OfPnt& tabNode = aTriangulation->Nodes();
- const TColgp_Array1OfPnt2d& tabUV = aTriangulation->UVNodes();
- for (i = tabNode.Lower(); i <= tabNode.Upper(); i++)
- {
- Standard_Real t[3];
- tabNode(i).Transformed(aTrf).Coord (t[0], t[1], t[2]);
- // write node to mesh data
- mypNodes[3*aNodeInd + 0] = static_cast<Standard_ShortReal>(t[0]);
- mypNodes[3*aNodeInd + 1] = static_cast<Standard_ShortReal>(t[1]);
- mypNodes[3*aNodeInd + 2] = static_cast<Standard_ShortReal>(t[2]);
-
- gp_Vec aD1U, aD1V;
- gp_Pnt aP;
- gp_XYZ aNorm(0., 0., 0.);
-
- if (aTriangulation->HasNormals()) {
- // Retrieve the normal direction from the triangulation
- aNorm.SetCoord(aTriangulation->Normals().Value(3*i-2),
- aTriangulation->Normals().Value(3*i-1),
- aTriangulation->Normals().Value(3*i-0));
- } else if (aSurf.IsNull() == Standard_False)
- {
- // Compute the surface normal at the Node.
- aSurf->D1(tabUV(i).X(), tabUV(i).Y(), aP, aD1U, aD1V);
- aNorm = (aD1U.Crossed(aD1V)).XYZ();
- }
-
- if (isReverse)
- aNorm.Reverse();
- const Standard_Real aMod = aNorm.SquareModulus();
- if (aMod > eps2) {
- gp_Dir aDirNorm(aNorm);
- aDirNorm.Transform(aTrfSurf);
- aDirNorm.Coord (t[0], t[1], t[2]);
- } else {
- t[0] = 0.;
- t[1] = 0.;
- t[2] = 1.;
- }
- mypNormals[3*aNodeInd + 0] = static_cast<Standard_ShortReal>(t[0]);
- mypNormals[3*aNodeInd + 1] = static_cast<Standard_ShortReal>(t[1]);
- mypNormals[3*aNodeInd + 2] = static_cast<Standard_ShortReal>(t[2]);
-
- aNodeInd++;
- }
- const Standard_Integer nNodes1 = nNodes - 1;
- // Store all triangles of the current face in the data model
- const Poly_Array1OfTriangle& tabTri = aTriangulation->Triangles();
- for (i = tabTri.Lower(); i <= tabTri.Upper(); i++)
- {
- Standard_Integer aN[3];
- tabTri(i).Get (aN[0], aN[1], aN[2]);
- Standard_Integer * pTriangle = &mypTriangles[nTriangles*3];
- pTriangle[0] = aN[0] + nNodes1;
- if (isReverse) {
- pTriangle[1] = aN[2] + nNodes1;
- pTriangle[2] = aN[1] + nNodes1;
- } else {
- pTriangle[1] = aN[1] + nNodes1;
- pTriangle[2] = aN[2] + nNodes1;
- }
- const Standard_ShortReal aVec0[3] = {
- mypNodes[3*pTriangle[1]+0] - mypNodes[3*pTriangle[0]+0],
- mypNodes[3*pTriangle[1]+1] - mypNodes[3*pTriangle[0]+1],
- mypNodes[3*pTriangle[1]+2] - mypNodes[3*pTriangle[0]+2]
- };
- const Standard_ShortReal aVec1[3] = {
- mypNodes[3*pTriangle[2]+0] - mypNodes[3*pTriangle[0]+0],
- mypNodes[3*pTriangle[2]+1] - mypNodes[3*pTriangle[0]+1],
- mypNodes[3*pTriangle[2]+2] - mypNodes[3*pTriangle[0]+2]
- };
- const Standard_ShortReal aVecP[3] = {
- aVec0[1] * aVec1[2] - aVec0[2] * aVec1[1],
- aVec0[2] * aVec1[0] - aVec0[0] * aVec1[2],
- aVec0[0] * aVec1[1] - aVec0[1] * aVec1[0]
- };
- if (aVecP[0]*aVecP[0] + aVecP[1]*aVecP[1] + aVecP[2]*aVecP[2] > eps2)
- nTriangles++;
- }
- // Store all edge polygons on the current face.
- for (eexp.Init(aFace, TopAbs_EDGE); eexp.More(); eexp.Next())
- {
- const TopoDS_Edge& anEdge = TopoDS::Edge(eexp.Current());
- if (mapEdges.Remove(anEdge)) {
- const Handle(Poly_PolygonOnTriangulation)& aPolygon =
- BRep_Tool::PolygonOnTriangulation(anEdge, aTriangulation, aLoc);
- if (aPolygon.IsNull() == Standard_False) {
- const TColStd_Array1OfInteger& arrNode = aPolygon->Nodes();
- // Allocate memory to store the current polygon indices.
- Standard_Integer aLen = arrNode.Length();
- Standard_Integer * pEdge = static_cast<Standard_Integer *>
- (myAlloc->Allocate(sizeof(Standard_Integer) * (aLen + 1)));
- const gp_Pnt* pLast = &tabNode(arrNode(arrNode.Lower()));
- pEdge[1] = arrNode(arrNode.Lower()) + nNodes1;
- Standard_Integer iPNode(arrNode.Lower() + 1), iENode(1);
- for (; iPNode <= arrNode.Upper(); iPNode++)
- {
- const Standard_Integer aN(arrNode(iPNode));
- if (pLast->SquareDistance(tabNode(aN)) < eps2)
- {
- aLen--;
- } else {
- pLast = &tabNode(aN);
- pEdge[++iENode] = aN + nNodes1;
- }
- }
- // Do not save very short polygons
- if (aLen > 1) {
- pEdge[0] = aLen;
- mypEdges[myNEdges++] = pEdge;
- }
- }
- }
- }
- nNodes += tabNode.Length();
- }
- }
- myNTriangles = nTriangles;
- }
- if (GetDrawer().IsNull() == Standard_False)
- {
- setDrawerUpdate();
- }
- setIsUpdateBox(Standard_True);
-}
-
-//=======================================================================
-//function : ~NIS_Surface
-//purpose : Destructor
-//=======================================================================
-
-NIS_Surface::~NIS_Surface ()
-{
- Clear();
-}
-
-//=======================================================================
-//function : Clear
-//purpose :
-//=======================================================================
-
-void NIS_Surface::Clear ()
-{
- if (myNNodes) {
- myNNodes = 0;
- myAlloc->Free(mypNodes);
- myAlloc->Free(mypNormals);
- }
- if (myNTriangles) {
- myNTriangles = 0;
- myAlloc->Free(mypTriangles);
- }
- if (mypEdges) {
- for (Standard_Integer i = 0; i < myNEdges; i++) {
- myAlloc->Free(mypEdges[i]);
- }
- myNEdges = 0;
- myAlloc->Free(mypEdges);
- }
- if (GetDrawer().IsNull() == Standard_False) {
- GetDrawer()->SetUpdated(NIS_Drawer::Draw_Normal,
- NIS_Drawer::Draw_Top,
- NIS_Drawer::Draw_Transparent,
- NIS_Drawer::Draw_Hilighted);
- }
- myBox.Clear();
-}
-
-//=======================================================================
-//function : DefaultDrawer
-//purpose :
-//=======================================================================
-
-NIS_Drawer * NIS_Surface::DefaultDrawer (NIS_Drawer * theDrawer) const
-{
- NIS_SurfaceDrawer * aDrawer =
- theDrawer ? static_cast<NIS_SurfaceDrawer *>(theDrawer)
- : new NIS_SurfaceDrawer (Quantity_NOC_SLATEBLUE4);
- aDrawer->SetBackColor (Quantity_NOC_DARKGREEN);
- aDrawer->myIsWireframe = myIsWireframe;
- return aDrawer;
-}
-
-//=======================================================================
-//function : SetColor
-//purpose : Set the normal color for presentation.
-//=======================================================================
-
-void NIS_Surface::SetColor (const Quantity_Color& theColor)
-{
- const Handle(NIS_SurfaceDrawer) aDrawer =
- static_cast<NIS_SurfaceDrawer *>(DefaultDrawer(0L));
- aDrawer->Assign (GetDrawer());
- aDrawer->myColor[NIS_Drawer::Draw_Normal] = theColor;
- aDrawer->myColor[NIS_Drawer::Draw_Top] = theColor;
- aDrawer->myColor[NIS_Drawer::Draw_Transparent] = theColor;
- SetDrawer (aDrawer);
-}
-
-//=======================================================================
-//function : SetBackColor
-//purpose : Set the normal color for presentation of back side of triangles.
-//=======================================================================
-
-void NIS_Surface::SetBackColor (const Quantity_Color& theColor)
-{
- const Handle(NIS_SurfaceDrawer) aDrawer =
- static_cast<NIS_SurfaceDrawer *>(DefaultDrawer(0L));
- aDrawer->Assign (GetDrawer());
- aDrawer->myBackColor = theColor;
- SetDrawer (aDrawer);
-}
-
-//=======================================================================
-//function : SetPolygonOffset
-//purpose :
-//=======================================================================
-
-void NIS_Surface::SetPolygonOffset (const Standard_Real theValue)
-{
- const Handle(NIS_SurfaceDrawer) aDrawer =
- static_cast<NIS_SurfaceDrawer *>(DefaultDrawer(0L));
- aDrawer->Assign (GetDrawer());
- aDrawer->myPolygonOffset = static_cast<Standard_ShortReal>(theValue);
- SetDrawer (aDrawer);
-}
-
-//=======================================================================
-//function : SetDisplayMode
-//purpose : Set the display mode: Shading or Wireframe.
-//=======================================================================
-
-void NIS_Surface::SetDisplayMode (const NIS_Surface::DisplayMode theMode)
-{
- Standard_Boolean isUpdate(Standard_False);
- if (myIsWireframe) {
- if (theMode != Wireframe) {
- myIsWireframe = Standard_False;
- isUpdate = Standard_True;
- }
- } else {
- if (theMode == Wireframe) {
- myIsWireframe = Standard_True;
- isUpdate = Standard_True;
- }
- }
- if (isUpdate && !GetDrawer().IsNull()) {
- const Handle(NIS_SurfaceDrawer) aDrawer =
- static_cast<NIS_SurfaceDrawer *>(DefaultDrawer(0L));
- aDrawer->Assign (GetDrawer());
- aDrawer->myIsWireframe = myIsWireframe;
- SetDrawer(aDrawer);
- }
-}
-
-//=======================================================================
-//function : GetDisplayMode
-//purpose : Query the current display mode: Shading or Wireframe.
-//=======================================================================
-
-NIS_Surface::DisplayMode NIS_Surface::GetDisplayMode () const
-{
- return myIsWireframe ? Wireframe : Shading;
-}
-
-//=======================================================================
-//function : Clone
-//purpose :
-//=======================================================================
-
-void NIS_Surface::Clone (const Handle(NCollection_BaseAllocator)& theAlloc,
- Handle(NIS_InteractiveObject)& theDest) const
-{
- Handle(NIS_Surface) aNewObj;
- if (theDest.IsNull()) {
- aNewObj = new NIS_Surface(theAlloc);
- theDest = aNewObj;
- } else {
- aNewObj = reinterpret_cast<NIS_Surface*> (theDest.operator->());
- aNewObj->myAlloc = theAlloc;
- }
- NIS_InteractiveObject::Clone(theAlloc, theDest);
- aNewObj->myNNodes = myNNodes;
- if (myNNodes > 0) {
- // copy nodes and normals
- const Standard_Size nBytes = myNNodes*3*sizeof(Standard_ShortReal);
- aNewObj->mypNodes = (Standard_ShortReal *)theAlloc->Allocate(nBytes);
- aNewObj->mypNormals = (Standard_ShortReal *)theAlloc->Allocate(nBytes);
- memcpy(aNewObj->mypNodes, mypNodes, nBytes);
- memcpy(aNewObj->mypNormals, mypNormals, nBytes);
- }
- aNewObj->myNTriangles = myNTriangles;
- if (myNTriangles > 0) {
- const Standard_Size nBytes = sizeof(Standard_Integer) * 3 * myNTriangles;
- aNewObj->mypTriangles = (Standard_Integer *)theAlloc->Allocate(nBytes);
- memcpy(aNewObj->mypTriangles, mypTriangles, nBytes);
- }
- aNewObj->myNEdges = myNEdges;
- if (myNEdges > 0) {
- aNewObj->mypEdges = static_cast<Standard_Integer **>
- (theAlloc->Allocate(sizeof(Standard_Integer *) * myNEdges));
- for (Standard_Integer i = 0; i < myNEdges; i++) {
- const Standard_Integer * pEdge = mypEdges[i];
- const Standard_Size nBytes = sizeof(Standard_Integer) * (pEdge[0] + 1);
- aNewObj->mypEdges[i] =
- static_cast<Standard_Integer *> (theAlloc->Allocate(nBytes));
- memcpy(aNewObj->mypEdges[i], pEdge, nBytes);
- }
- }
- aNewObj->myIsWireframe = myIsWireframe;
-}
-
-//=======================================================================
-//function : Intersect
-//purpose :
-//=======================================================================
-
-Standard_Real NIS_Surface::Intersect (const gp_Ax1& theAxis,
- const Standard_Real theOver) const
-{
- Standard_Real aResult (RealLast());
- Standard_Real start[3], dir[3];
- theAxis.Location().Coord(start[0], start[1], start[2]);
- theAxis.Direction().Coord(dir[0], dir[1], dir[2]);
- double anInter;
-
- if (myIsWireframe == Standard_False)
- for (Standard_Integer i = 0; i < myNTriangles; i++) {
- const Standard_Integer * pTri = &mypTriangles[3*i];
- if (NIS_Triangulated::tri_line_intersect (start, dir,
- &mypNodes[3*pTri[0]],
- &mypNodes[3*pTri[1]],
- &mypNodes[3*pTri[2]],
- &anInter))
- if (anInter < aResult)
- aResult = anInter;
- }
- else {
- const Standard_Real anOver2 = theOver*theOver;
- for (Standard_Integer iEdge = 0; iEdge < myNEdges; iEdge++) {
- const Standard_Integer * anEdge = mypEdges[iEdge];
- const Standard_Integer nNodes = anEdge[0];
- for (Standard_Integer i = 1; i < nNodes; i++) {
- // Node index is incremented for the head of polygon indice array
- if (NIS_Triangulated::seg_line_intersect (theAxis.Location().XYZ(),
- theAxis.Direction().XYZ(),
- anOver2,
- &mypNodes[3*anEdge[i+0]],
- &mypNodes[3*anEdge[i+1]],
- &anInter))
- if (anInter < aResult)
- aResult = anInter;
- }
- }
- }
-
- return aResult;
-}
-
-//=======================================================================
-//function : Intersect
-//purpose :
-//=======================================================================
-
-Standard_Boolean NIS_Surface::Intersect (const Bnd_B3f& theBox,
- const gp_Trsf& theTrf,
- const Standard_Boolean isFullIn) const
-{
- Standard_Boolean aResult (isFullIn);
-
- if (myIsWireframe == Standard_False) {
- if (myNTriangles > 0) {
- for (Standard_Integer iNode = 0; iNode < myNNodes*3; iNode+=3) {
- gp_XYZ aPnt (static_cast<Standard_Real>(mypNodes[iNode+0]),
- static_cast<Standard_Real>(mypNodes[iNode+1]),
- static_cast<Standard_Real>(mypNodes[iNode+2]));
- theTrf.Transforms(aPnt);
- if (theBox.IsOut (aPnt) == isFullIn) {
- aResult = !isFullIn;
- break;
- }
- }
- }
- } else {
- for (Standard_Integer iEdge = 0; iEdge < myNEdges; iEdge++) {
- const Standard_Integer * anEdge = mypEdges[iEdge];
- const Standard_Integer nNodes = anEdge[0];
- for (Standard_Integer i = 1; i < nNodes; i++) {
- // index is incremented by 1 for the head number in the array
- gp_Pnt aPnt[2] = {
- gp_Pnt(static_cast<Standard_Real>(mypNodes[3*anEdge[i+0]+0]),
- static_cast<Standard_Real>(mypNodes[3*anEdge[i+0]+1]),
- static_cast<Standard_Real>(mypNodes[3*anEdge[i+0]+2])),
- gp_Pnt(static_cast<Standard_Real>(mypNodes[3*anEdge[i+1]+0]),
- static_cast<Standard_Real>(mypNodes[3*anEdge[i+1]+1]),
- static_cast<Standard_Real>(mypNodes[3*anEdge[i+1]+2]))
- };
- aPnt[0].Transform(theTrf);
- aPnt[1].Transform(theTrf);
- if (isFullIn) {
- if (NIS_Triangulated::seg_box_included (theBox, aPnt) == 0) {
- aResult = Standard_False;
- break;
- }
- } else {
- if (NIS_Triangulated::seg_box_intersect (theBox, aPnt)) {
- aResult = Standard_True;
- break;
- }
- }
- }
- }
- }
- return aResult;
-}
-
-//=======================================================================
-//function : Intersect
-//purpose : Selection by polygon
-//=======================================================================
-
-Standard_Boolean NIS_Surface::Intersect
- (const NCollection_List<gp_XY> &thePolygon,
- const gp_Trsf &theTrf,
- const Standard_Boolean isFullIn) const
-{
- Standard_Boolean aResult (isFullIn);
-
- if (myIsWireframe == Standard_False) {
- if (myNTriangles > 0) {
- for (Standard_Integer iNode = 0; iNode < myNNodes*3; iNode+=3) {
- gp_XYZ aPnt (static_cast<Standard_Real>(mypNodes[iNode+0]),
- static_cast<Standard_Real>(mypNodes[iNode+1]),
- static_cast<Standard_Real>(mypNodes[iNode+2]));
- theTrf.Transforms(aPnt);
- gp_XY aP2d(aPnt.X(), aPnt.Y());
-
- if (!NIS_Triangulated::IsIn(thePolygon, aP2d)) {
- if (isFullIn) {
- aResult = Standard_False;
- break;
- }
- } else {
- if (isFullIn == Standard_False) {
- aResult = Standard_True;
- break;
- }
- }
- }
- }
- } else {
- for (Standard_Integer iEdge = 0; iEdge < myNEdges; iEdge++) {
- const Standard_Integer * anEdge = mypEdges[iEdge];
- const Standard_Integer nNodes = anEdge[0];
- for (Standard_Integer i = 1; i < nNodes; i++) {
- // index is incremented by 1 for the head number in the array
- gp_Pnt aPnt[2] = {
- gp_Pnt(static_cast<Standard_Real>(mypNodes[3*anEdge[i+0]+0]),
- static_cast<Standard_Real>(mypNodes[3*anEdge[i+0]+1]),
- static_cast<Standard_Real>(mypNodes[3*anEdge[i+0]+2])),
- gp_Pnt(static_cast<Standard_Real>(mypNodes[3*anEdge[i+1]+0]),
- static_cast<Standard_Real>(mypNodes[3*anEdge[i+1]+1]),
- static_cast<Standard_Real>(mypNodes[3*anEdge[i+1]+2]))
- };
- aPnt[0].Transform(theTrf);
- aPnt[1].Transform(theTrf);
- const gp_XY aP2d[2] = { gp_XY(aPnt[0].X(), aPnt[0].Y()),
- gp_XY(aPnt[1].X(), aPnt[1].Y()) };
- if (isFullIn) {
- if (NIS_Triangulated::seg_polygon_included (thePolygon, aP2d) == 0) {
- aResult = Standard_False;
- break;
- }
- } else {
- if (NIS_Triangulated::seg_polygon_intersect (thePolygon, aP2d)) {
- aResult = Standard_True;
- break;
- }
- }
- }
- }
- }
- return aResult;
-}
-
-//=======================================================================
-//function : computeBox
-//purpose :
-//=======================================================================
-
-void NIS_Surface::computeBox ()
-{
- NIS_Triangulated::ComputeBox(myBox, myNNodes, mypNodes, 3);
-
- const Handle(NIS_SurfaceDrawer)& aDrawer =
- static_cast<const Handle(NIS_SurfaceDrawer)&> (GetDrawer());
-
- if (aDrawer.IsNull() == Standard_False) {
- const gp_Trsf& aTrsf = aDrawer->GetTransformation();
- myBox = myBox.Transformed(aTrsf);
- }
-}
+++ /dev/null
-// Created on: 2008-03-19
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2008-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#ifndef NIS_Surface_HeaderFile
-#define NIS_Surface_HeaderFile
-
-#include <NIS_InteractiveObject.hxx>
-#include <NCollection_BaseAllocator.hxx>
-#include <gp_XYZ.hxx>
-
-class Quantity_Color;
-class Handle(Poly_Triangulation);
-class TopoDS_Shape;
-
-/**
- * Presentation of a meshed surface.
- * Consists of 4 arrays: Nodes, Triangles, Normals and Edges. Normals are
- * defined in nodes, so the number of stored normals is strictly the number of
- * nodes. Edges is an array of pointers: each pointer starts an array of
- * node indices that define a single edge (i.e., a polygon that can be closed or
- * open, no matter). The first number in the edge is the number of nodes in it.
- * <p>
- * Instances of this class can be initialized either atomically (setting every
- * node and triangle and edge) or from a TopoDS_Shape object. In side the
- * TopoDS_Shape only triangulations in faces are used; edges are taken from
- * PolygonOnTriangulation also belonging to faces.
- * <p>
- * This class is conceived as replacement of AIS_Shape; both wireframe and
- * shading modes are available for dynamic switching.
- */
-
-class NIS_Surface : public NIS_InteractiveObject
-{
-public:
- enum DisplayMode {
- Shading,
- Wireframe
- };
-
- /**
- * Constructor
- */
- Standard_EXPORT NIS_Surface(const Handle(Poly_Triangulation)& theTri,
- const Handle(NCollection_BaseAllocator)&
- theAlloc =0L);
- /**
- * Constructor. Creates the presentation of all faces in 'theShape' object.
- * @param theShape
- * Source geometry. It should contain triangulations inside.
- * @param theDeflection
- * Absolute deflection for meshing 'theShape' if such meshing is needed.
- * @param theAl
- * Allocator used for nodes and triangles in this presentation.
- */
- Standard_EXPORT NIS_Surface(const TopoDS_Shape& theShape,
- const Standard_Real theDeflection,
- const Handle(NCollection_BaseAllocator)& theAl=0L);
-
- /**
- * Destructor
- */
- Standard_EXPORT virtual ~NIS_Surface ();
-
- /**
- * Initialize the instance with a TopoDS_Shape. Used in constructor but can
- * be called any time to redefine the geometry.
- */
- Standard_EXPORT void Init (const TopoDS_Shape& theShape,
- const Standard_Real theDefl);
-
- /**
- * Deallocate all internal data structures.
- */
- Standard_EXPORT void Clear ();
-
- /**
- * Query the number of nodes.
- */
- inline Standard_Integer NNodes () const { return myNNodes; }
-
- /**
- * Query the number of triangles.
- */
- inline Standard_Integer NTriangles () const { return myNTriangles;}
-
- /**
- * Query the number of edges for wireframe display.
- */
- inline Standard_Integer NEdges () const { return myNEdges; }
-
- /**
- * Query the node by its index.
- * @return
- * pointer to array of 3 Standard_ShortReal values (X,Y,Z coordinates)
- */
- inline const Standard_ShortReal*
- Node (const Standard_Integer theIndex) const
- {
- return &mypNodes[theIndex * 3];
- }
-
- /**
- * Query the triangle by its index.
- * @return
- * pointer to array of 3 Standard_Integer values (nodes 0, 1, 2)
- */
- inline const Standard_Integer*
- Triangle (const Standard_Integer theIndex) const
- {
- return &mypTriangles[theIndex * 3];
- }
-
- /**
- * Access to array of integers that represents an Edge.
- * @return
- * Pointer to array where the 0th element is the number of nodes in the edge
- * and the elements starting from the 1st are node indices.
- */
- inline const Standard_Integer*
- Edge (const Standard_Integer theIndex) const
- {
- return mypEdges[theIndex];
- }
-
- /**
- * Query the normal vector at the given triangulation node (by index)
- * @return
- * pointer to array of 3 Standard_ShortReal values (X,Y,Z coordinates)
- */
- inline const Standard_ShortReal*
- Normal (const Standard_Integer theIndex) const
- {
- return &mypNormals[theIndex * 3];
- }
-
- /**
- * Create a default drawer instance.
- */
- Standard_EXPORT virtual NIS_Drawer *
- DefaultDrawer (NIS_Drawer *) const;
-
- /**
- * Set the normal color for presentation.
- * @param theColor
- * New color to use for the presentation.
- */
- Standard_EXPORT void SetColor (const Quantity_Color& theColor);
-
- /**
- * Set the color for presentation of the back side of triangles.
- * @param theColor
- * New color to use for the presentation.
- */
- Standard_EXPORT void SetBackColor (const Quantity_Color& theColor);
-
- /**
- * Set the offset for the presentation.
- * @param theValue
- * New offset to use for the presentation.
- */
- Standard_EXPORT void SetPolygonOffset (const Standard_Real theValue);
-
- /**
- * Set the display mode: Shading or Wireframe.
- * The default mode is Shading.
- */
- Standard_EXPORT void SetDisplayMode (const DisplayMode theMode);
-
- /**
- * Query the current display mode: Shading or Wireframe.
- */
- Standard_EXPORT DisplayMode
- GetDisplayMode () const;
-
- /**
- * Create a copy of theObject except its ID.
- * @param theAll
- * Allocator where the Dest should store its private data.
- * @param theDest
- * <tt>[in-out]</tt> The target object where the data are copied. If
- * passed NULL then the target should be created.
- */
- Standard_EXPORT virtual void
- Clone (const Handle(NCollection_BaseAllocator)& theAll,
- Handle(NIS_InteractiveObject)& theDest) const;
-
- /**
- * Intersect the surface shading/wireframe geometry with a line/ray.
- * @param theAxis
- * The line or ray in 3D space.
- * @param theOver
- * Half-thickness of the selecting line - ignored.
- * @return
- * If the return value is more than 0.1*RealLast() then no intersection is
- * detected. Otherwise returns the coordinate of the nearest intersection
- * on the ray. May be negative.
- */
- Standard_EXPORT virtual Standard_Real
- Intersect (const gp_Ax1& theAxis,
- const Standard_Real theOver) const;
-
- /**
- * Intersect the surface shading/wireframe geometry with an oriented box.
- * @param theBox
- * 3D box of selection
- * @param theTrf
- * Position/Orientation of the box.
- * @param isFull
- * True if full inclusion is required, False - if partial.
- * @return
- * True if the InteractiveObject geometry intersects the box or is inside it
- */
- Standard_EXPORT virtual Standard_Boolean
- Intersect (const Bnd_B3f& theBox,
- const gp_Trsf& theTrf,
- const Standard_Boolean isFull)const;
-
- /**
- * Intersect the surface shading/wireframe geometry with a selection polygon.
- * @param thePolygon
- * the list of vertices of a free-form closed polygon without
- * self-intersections. The last point should not coincide with the first
- * point of the list. Any two neighbor points should not be confused.
- * @param theTrf
- * Position/Orientation of the polygon.
- * @param isFullIn
- * True if full inclusion is required, False - if partial.
- * @return
- * True if the InteractiveObject geometry intersects the polygon or is
- * inside it
- */
- Standard_EXPORT virtual Standard_Boolean Intersect
- (const NCollection_List<gp_XY> &thePolygon,
- const gp_Trsf &theTrf,
- const Standard_Boolean isFullIn) const;
-
-protected:
-
- /**
- * Allocator for method Clone().
- */
- Standard_EXPORT NIS_Surface (const Handle(NCollection_BaseAllocator)& theAl);
-
- /**
- * Create a 3D bounding box of the object.
- */
- Standard_EXPORT virtual void computeBox ();
-
- /**
- * Compute normal to the surface at the node with the given index.
- * Returns true if the vertex is artificial at this node.
- */
- Standard_Boolean computeNormal (Standard_Integer theIndex,
- gp_XYZ& theNormal) const;
-
-private:
- Handle(NCollection_BaseAllocator) myAlloc;
- //! Array of nodes in triangles
- Standard_ShortReal * mypNodes;
- //! Array of normals (TriNodes)
- Standard_ShortReal * mypNormals;
- //! Array of triangles (node indices)
- Standard_Integer * mypTriangles;
- //! Array of edges, each edge is an array of indices prefixed by N nodes
- Standard_Integer ** mypEdges;
- //! Number of nodes in triangles
- Standard_Integer myNNodes;
- Standard_Integer myNTriangles;
- Standard_Integer myNEdges;
- Standard_Boolean myIsWireframe;
-
-public:
-// Declaration of CASCADE RTTI
-DEFINE_STANDARD_RTTI (NIS_Surface)
-};
-
-// Definition of HANDLE object using Standard_DefineHandle.hxx
-DEFINE_STANDARD_HANDLE (NIS_Surface, NIS_InteractiveObject)
-
-#endif
+++ /dev/null
-// Created on: 2008-03-20
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2008-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <NIS_SurfaceDrawer.hxx>
-#include <NIS_Surface.hxx>
-#include <NIS_InteractiveObject.hxx>
-#include <Standard_ProgramError.hxx>
-
-#include <OpenGl_GlCore11.hxx>
-
-static void setColor(GLenum theFace,
- Quantity_Parameter * theAmbient,
- const Standard_Real theSpecularity,
- GLint theShininess);
-
-IMPLEMENT_STANDARD_HANDLE (NIS_SurfaceDrawer, NIS_Drawer)
-IMPLEMENT_STANDARD_RTTIEXT (NIS_SurfaceDrawer, NIS_Drawer)
-
-//=======================================================================
-//function : NIS_SurfaceDrawer()
-//purpose : Constructor
-//=======================================================================
-
-NIS_SurfaceDrawer::NIS_SurfaceDrawer
- (const Quantity_Color &theNormal,
- const Quantity_Color &theHilight,
- const Quantity_Color &theDynHilight)
- : myBackColor (theNormal),
- myPolygonOffset (0.f),
- myIsWireframe (Standard_False)
-{
- myColor[Draw_Normal] = theNormal;
- myColor[Draw_Top] = theNormal;
- myColor[Draw_Transparent] = theNormal;
- myColor[Draw_Hilighted] = theHilight;
- myColor[Draw_DynHilighted] = theDynHilight;
-}
-
-//=======================================================================
-//function : SetColor
-//purpose :
-//=======================================================================
-
-void NIS_SurfaceDrawer::SetColor(const Quantity_Color &theColor)
-{
- myColor[Draw_Normal] = theColor;
- myColor[Draw_Top] = theColor;
- myColor[Draw_Transparent] = theColor;
-}
-
-//=======================================================================
-//function : Assign
-//purpose :
-//=======================================================================
-
-void NIS_SurfaceDrawer::Assign (const Handle(NIS_Drawer)& theOther)
-{
- if (theOther.IsNull() == Standard_False) {
- NIS_Drawer::Assign (theOther);
- const Handle(NIS_SurfaceDrawer)& anOther =
- static_cast <const Handle(NIS_SurfaceDrawer)&> (theOther);
- myColor[Draw_Normal] = anOther->myColor[Draw_Normal];
- myColor[Draw_Top] = anOther->myColor[Draw_Top];
- myColor[Draw_Transparent] = anOther->myColor[Draw_Transparent];
- myColor[Draw_Hilighted] = anOther->myColor[Draw_Hilighted];
- myColor[Draw_DynHilighted] = anOther->myColor[Draw_DynHilighted];
- myBackColor = anOther->myBackColor;
- myPolygonOffset = anOther->myPolygonOffset;
- myIsWireframe = anOther->myIsWireframe;
- }
-}
-
-//=======================================================================
-//function : IsEqual
-//purpose : Comparison of two Drawers (for Map impementation)
-//=======================================================================
-
-Standard_Boolean NIS_SurfaceDrawer::IsEqual
- (const Handle(NIS_Drawer)& theOther)const
-{
- static const Standard_Real anEpsilon2 (1e-7);
- Standard_Boolean aResult (Standard_False);
- const Handle(NIS_SurfaceDrawer) anOther =
- Handle(NIS_SurfaceDrawer)::DownCast (theOther);
- if (NIS_Drawer::IsEqual(theOther))
- aResult = (anOther->myColor[Draw_Normal]
- .SquareDistance (myColor[Draw_Normal]) < anEpsilon2 &&
- anOther->myColor[Draw_Hilighted]
- .SquareDistance (myColor[Draw_Hilighted]) < anEpsilon2 &&
- anOther->myColor[Draw_DynHilighted]
- .SquareDistance (myColor[Draw_DynHilighted]) < anEpsilon2 &&
- anOther->myBackColor.SquareDistance(myBackColor) < anEpsilon2 &&
- fabs(anOther->myPolygonOffset - myPolygonOffset) < 0.999 &&
- myIsWireframe == anOther->myIsWireframe);
- if (aResult) {
- // Arbitrary point for test
- gp_XYZ aPnt[2] = {
- gp_XYZ(113., -31.3, 29.19),
- gp_XYZ(113., -31.3, 29.19)
- };
- anOther->myTrsf.Transforms(aPnt[0]);
- myTrsf.Transforms(aPnt[1]);
- if ((aPnt[0] - aPnt[1]).SquareModulus() > anEpsilon2)
- aResult = Standard_False;
- }
- return aResult;
-}
-
-//=======================================================================
-//function : redraw
-//purpose :
-//=======================================================================
-
-void NIS_SurfaceDrawer::redraw (const DrawType theType,
- const Handle(NIS_View)& theView)
-{
- glMatrixMode( GL_MODELVIEW );
- glPushMatrix();
-
- GLdouble aMatrix[16] = {
- myTrsf.Value(1,1), myTrsf.Value(2,1), myTrsf.Value(3,1), 0.,
- myTrsf.Value(1,2), myTrsf.Value(2,2), myTrsf.Value(3,2), 0.,
- myTrsf.Value(1,3), myTrsf.Value(2,3), myTrsf.Value(3,3), 0.,
- myTrsf.Value(1,4), myTrsf.Value(2,4), myTrsf.Value(3,4), 1.
- };
-
- glMultMatrixd( aMatrix );
-
- NIS_Drawer::redraw(theType, theView);
-
- glPopMatrix();
-}
-
-//=======================================================================
-//function : BeforeDraw
-//purpose :
-//=======================================================================
-
-void NIS_SurfaceDrawer::BeforeDraw (const DrawType theType,
- const NIS_DrawList&)
-{
- glEnable(GL_LIGHTING);
- // glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
- glEnableClientState (GL_VERTEX_ARRAY);
- if (myIsWireframe == Standard_False) {
- glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
- glEnable(GL_POLYGON_OFFSET_FILL);
- glShadeModel(GL_SMOOTH);
- }
-
- Quantity_Parameter aValueCol[4] = {0., 0., 0., 1.};
- Quantity_TypeOfColor bidTC (Quantity_TOC_RGB);
- GLfloat aLineWidth (1.f);
- GLfloat anOffset = myPolygonOffset;
- static const GLfloat gColorN[4] = {0.f, 0.f, 0.f, 1.f};
-
- switch (theType) {
- case Draw_DynHilighted:
- aLineWidth = 3.f;
- myColor[theType].Values (aValueCol[0], aValueCol[1], aValueCol[2], bidTC);
- setColor(GL_FRONT_AND_BACK, &aValueCol[0], 0.1, 5);
- glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, &gColorN[0]);
- glLineWidth (aLineWidth);
- if (myIsWireframe == Standard_False)
- glPolygonOffset(1.f, -(anOffset + 11.f));
- return;
- case Draw_Hilighted:
- anOffset += 10.f;
- case Draw_Normal:
- case Draw_Top:
- case Draw_Transparent:
- if (myIsWireframe == Standard_False) {
- glPolygonOffset(1.f, -anOffset);
- glEnableClientState (GL_NORMAL_ARRAY);
- }
- myColor[theType].Values (aValueCol[0], aValueCol[1], aValueCol[2], bidTC);
- aValueCol[3] = 1. - myTransparency;
- if (theType == Draw_Transparent) {
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- // don't write triangles into depth test
- glDepthMask(GL_FALSE);
- }
- break;
- default:
- return;
- }
- // glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0);
- if (theType == Draw_Hilighted ||
- myBackColor.SquareDistance(myColor[Draw_Normal]) < 1.e-7)
- {
- setColor(GL_FRONT_AND_BACK, &aValueCol[0], 0.5, 10);
- } else {
- setColor(GL_FRONT, &aValueCol[0], 0.4, 10);
- myBackColor.Values (aValueCol[0], aValueCol[1], aValueCol[2], bidTC);
- setColor(GL_BACK, &aValueCol[0], 0.8, 5);
- }
- glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, &gColorN[0]);
- glLineWidth (aLineWidth);
-}
-
-//=======================================================================
-//function : AfterDraw
-//purpose :
-//=======================================================================
-
-void NIS_SurfaceDrawer::AfterDraw (const DrawType theType,
- const NIS_DrawList&)
-{
- glDisable(GL_LIGHTING);
- glDisableClientState(GL_VERTEX_ARRAY);
- switch (theType) {
- case Draw_Transparent:
- glDisable(GL_BLEND);
- glDepthMask(GL_TRUE);
- case Draw_Hilighted:
- case Draw_Normal:
- case Draw_Top:
- if (myIsWireframe == Standard_False)
- glDisableClientState(GL_NORMAL_ARRAY);
- default:;
- }
- if (myIsWireframe == Standard_False)
- glDisable(GL_POLYGON_OFFSET_FILL);
-}
-
-//=======================================================================
-//function : Draw
-//purpose :
-//=======================================================================
-
-void NIS_SurfaceDrawer::Draw (const Handle(NIS_InteractiveObject)& theObj,
- const DrawType theType,
- const NIS_DrawList&)
-{
- // Assertion for the type of the drawn object
- Standard_ProgramError_Raise_if (! theObj->IsKind(STANDARD_TYPE(NIS_Surface)),
- "NIS_Surface::Draw: irrelevant object type");
-
- const NIS_Surface * pObject =
- static_cast <const NIS_Surface *> (theObj.operator->());
- glVertexPointer (3, GL_FLOAT, 0, pObject->Node(0));
-
- // In Highlited mode the shape must be shown as wireframe
- Standard_Boolean isWireframe(myIsWireframe);
- if (isWireframe == Standard_False && theType == Draw_DynHilighted)
- if (pObject->NEdges() > 0)
- isWireframe = Standard_True;
-
- if (isWireframe)
- {
- for (Standard_Integer i = 0; i < pObject->NEdges(); i++) {
- const GLint * pEdge = static_cast<const GLint *> (pObject->Edge(i));
- glDrawElements (GL_LINE_STRIP, pEdge[0], GL_UNSIGNED_INT, &pEdge[1]);
- }
- } else {
- if (pObject->NTriangles()) {
- if (theType != Draw_DynHilighted)
- glNormalPointer (GL_FLOAT, 0, pObject->Normal(0));
- glDrawElements (GL_TRIANGLES, pObject->NTriangles()*3,
- GL_UNSIGNED_INT, pObject->Triangle(0));
- }
- }
-}
-
-//=======================================================================
-//function : setColor
-//purpose :
-//=======================================================================
-
-void setColor(GLenum theFace,
- Quantity_Parameter * theAmbient,
- const Standard_Real theSpecularity,
- GLint theShininess)
-{
- GLfloat aSpec = static_cast<GLfloat>(theSpecularity);
- GLfloat aValueCol[4] = {
- GLfloat(theAmbient[0]),
- GLfloat(theAmbient[1]),
- GLfloat(theAmbient[2]),
- GLfloat(theAmbient[3])
- };
- glMaterialfv(theFace, GL_AMBIENT_AND_DIFFUSE, &aValueCol[0]);
- aValueCol[0] = aSpec * (aValueCol[0] - 1.f) + 1.f;
- aValueCol[1] = aSpec * (aValueCol[1] - 1.f) + 1.f;
- aValueCol[2] = aSpec * (aValueCol[2] - 1.f) + 1.f;
- aValueCol[3] = 1.f;
- glMaterialfv(theFace, GL_SPECULAR, &aValueCol[0]);
- glMateriali(theFace, GL_SHININESS, theShininess);
-}
-
+++ /dev/null
-// Created on: 2008-03-20
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2008-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#ifndef NIS_SurfaceDrawer_HeaderFile
-#define NIS_SurfaceDrawer_HeaderFile
-
-#include <NIS_Drawer.hxx>
-#include <gp_Trsf.hxx>
-#include <Quantity_Color.hxx>
-
-class NIS_Surface;
-
-/**
- * Drawer for interactive object type NIS_Surface.
- */
-
-class NIS_SurfaceDrawer : public NIS_Drawer
-{
- public:
- // ---------- PUBLIC METHODS ----------
-
- /**
- * Constructor.
- */
- Standard_EXPORT NIS_SurfaceDrawer(const Quantity_Color &theNormal,
- const Quantity_Color &theHilight
- = Quantity_NOC_GRAY65,
- const Quantity_Color &theDynHilight
- = Quantity_NOC_CYAN1);
-
- /**
- * Sets the color of the drawer.
- */
- Standard_EXPORT void SetColor (const Quantity_Color &theColor);
-
- /**
- * Define the color used for the back side of rendered triangles.
- * By default this color is the same as the 'Normal' color.
- */
- inline void SetBackColor (const Quantity_Color& theColor)
- {
- myBackColor = theColor;
- }
-
- /**
- * Sets the transformation to the drawer.
- */
- inline void SetTransformation (const gp_Trsf &theTrsf)
- {
- myTrsf = theTrsf;
- }
-
- /**
- * Returns the transformation to the drawer.
- */
- inline const gp_Trsf& GetTransformation () const
- {
- return myTrsf;
- }
-
- /**
- * Sets the surface offset
- */
- inline void SetPolygonOffset (const Standard_Real theOffset)
- {
- myPolygonOffset = static_cast<Standard_ShortReal>(theOffset);
- }
-
- /**
- * Get the surface offset.
- */
- inline Standard_Real GetPolygonOffset () const
- {
- return static_cast<Standard_Real>(myPolygonOffset);
- }
-
- /**
- * Copy the relevant information from another instance of Drawer.
- * raises exception if theOther has incompatible type (test IsKind).
- */
- Standard_EXPORT virtual void Assign (const Handle(NIS_Drawer)& theOther);
-
- /**
- * Called before execution of Draw(), once per group of interactive objects.
- */
- Standard_EXPORT virtual void BeforeDraw(const DrawType theType,
- const NIS_DrawList& theDrawList);
-
- /**
- * Called after execution of Draw(), once per group of interactive objects.
- */
- Standard_EXPORT virtual void AfterDraw(const DrawType theType,
- const NIS_DrawList& theDrawList);
-
- /**
- * Main function: display the given interactive object in the given view.
- */
- Standard_EXPORT virtual void Draw (const Handle(NIS_InteractiveObject)&,
- const DrawType theType,
- const NIS_DrawList& theDrawList);
-
- /**
- * Matching two instances, for Map interface.
- */
- Standard_EXPORT virtual Standard_Boolean
- IsEqual (const Handle(NIS_Drawer)& theOth)const;
-
- protected:
- Standard_EXPORT virtual void redraw (const DrawType theType,
- const Handle(NIS_View)& theView);
-
-
-private:
- Quantity_Color myColor[5];
- Quantity_Color myBackColor;
- gp_Trsf myTrsf;
- Standard_ShortReal myPolygonOffset;
- Standard_Boolean myIsWireframe;
-
- friend class NIS_Surface;
-
- public:
-// Declaration of CASCADE RTTI
-DEFINE_STANDARD_RTTI (NIS_SurfaceDrawer)
-};
-
-// Definition of HANDLE object using Standard_DefineHandle.hxx
-DEFINE_STANDARD_HANDLE (NIS_SurfaceDrawer, NIS_Drawer)
-
-#endif
+++ /dev/null
-// Created on: 2007-07-17
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2007-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <NIS_Triangulated.hxx>
-#include <NIS_TriangulatedDrawer.hxx>
-#include <NIS_InteractiveContext.hxx>
-#include <gp_Ax1.hxx>
-#include <Precision.hxx>
-
-IMPLEMENT_STANDARD_HANDLE (NIS_Triangulated, NIS_InteractiveObject)
-IMPLEMENT_STANDARD_RTTIEXT (NIS_Triangulated, NIS_InteractiveObject)
-
-static Standard_Real aTolConf = Precision::Confusion() * 0.0001;
-
-/**
- * Checking the given value if it is considerably greater than zero.
- */
-static inline Standard_Boolean IsPositive (const Standard_Real theVal)
-{
- return (theVal > aTolConf);
-}
-
-/**
- * Compute the size in bytes of an index array.
- */
-static inline Standard_Size NBytesInd (const Standard_Integer nInd,
- const unsigned int theIndType)
-{
- Standard_Size nBytes = static_cast<Standard_Size>(nInd);
- if (theIndType) {
- nBytes *= 2;
- if (theIndType > 1u)
- nBytes *= 2;
- }
- return nBytes;
-}
-
-//=======================================================================
-//function : NIS_Triangulated()
-//purpose : Constructor
-//=======================================================================
-
-NIS_Triangulated::NIS_Triangulated
- (const Standard_Integer nNodes,
- const Standard_Boolean is2D,
- const Handle(NCollection_BaseAllocator)& theAlloc)
- : myAlloc (0L),
- myType (Type_None),
- mypNodes (0L),
- mypTriangles (0L),
- mypLines (0L),
- mypPolygons (0L),
- myNNodes (0),
- myNTriangles (0),
- myNLineNodes (0),
- myNPolygons (0u),
- myIsDrawPolygons (Standard_False),
- myIsCloned (Standard_False),
- myIndexType (2u),
- myNodeCoord (is2D ? 2 : 3),
- myPolygonType (static_cast<unsigned int>(Polygon_Default))
-{
-
- if (theAlloc.IsNull())
- myAlloc = NCollection_BaseAllocator::CommonBaseAllocator().operator->();
- else
- myAlloc = theAlloc.operator->();
- allocateNodes (nNodes);
-}
-
-//=======================================================================
-//function : Clear
-//purpose : Reset all internal data members and structures
-//=======================================================================
-
-void NIS_Triangulated::Clear ()
-{
- if (myNNodes) {
- myNNodes = 0;
- myAlloc->Free(mypNodes);
- mypNodes = 0L;
- }
- if (myNTriangles) {
- myNTriangles = 0;
- myAlloc->Free(mypTriangles);
- mypTriangles = 0L;
- }
- if (myNLineNodes) {
- myNLineNodes = 0;
- myAlloc->Free( mypLines);
- mypLines = 0L;
- }
- if (myNPolygons) {
- for (unsigned int i = 0; i < myNPolygons; i++)
- myAlloc->Free(mypPolygons[i]);
- myAlloc->Free(mypPolygons);
- myNPolygons = 0u;
- mypPolygons = 0L;
- }
- myType = Type_None;
- myIsDrawPolygons = Standard_False;
- myPolygonType = static_cast<unsigned int>(Polygon_Default);
- if (GetDrawer().IsNull() == Standard_False) {
- GetDrawer()->SetUpdated(NIS_Drawer::Draw_Normal,
- NIS_Drawer::Draw_Top,
- NIS_Drawer::Draw_Transparent,
- NIS_Drawer::Draw_Hilighted);
- }
-}
-
-//=======================================================================
-//function : SetPolygonsPrs
-//purpose :
-//=======================================================================
-
-void NIS_Triangulated::SetPolygonsPrs (const Standard_Integer nPolygons,
- const Standard_Integer nNodes)
-{
- if (nPolygons <= 0)
- myType &= ~Type_Polygons;
- else {
- myType |= Type_Polygons;
- if (myNPolygons) {
- for (unsigned int i = 0; i < myNPolygons; i++)
- myAlloc->Free(mypPolygons[i]);
- myAlloc->Free(mypPolygons);
- }
- myNPolygons = static_cast<unsigned int>(nPolygons);
- mypPolygons = static_cast<Standard_Integer **>
- (myAlloc->Allocate(sizeof(Standard_Integer *)*nPolygons));
- allocateNodes (nNodes);
- }
-}
-
-//=======================================================================
-//function : SetTriangulationPrs
-//purpose :
-//=======================================================================
-
-void NIS_Triangulated::SetTriangulationPrs (const Standard_Integer nTri,
- const Standard_Integer nNodes)
-{
- if (nTri <= 0)
- myType &= ~Type_Triangulation;
- else {
- myType |= Type_Triangulation;
- if (myNTriangles)
- myAlloc->Free(mypTriangles);
- allocateNodes (nNodes);
-
- myNTriangles = nTri;
- const Standard_Size nBytes = NBytesInd(3 * nTri, myIndexType);
- mypTriangles = static_cast<Standard_Integer *> (myAlloc->Allocate(nBytes));
- }
-}
-
-//=======================================================================
-//function : SetLinePrs
-//purpose :
-//=======================================================================
-
-void NIS_Triangulated::SetLinePrs (const Standard_Integer nPoints,
- const Standard_Boolean isClosed,
- const Standard_Integer nNodes)
-{
- if (nPoints <= 0)
- myType &= ~(Type_Loop | Type_Line);
- else {
- myType |= Type_Line;
- if (isClosed)
- myType |= Type_Loop;
- if (myNLineNodes)
- myAlloc->Free(mypLines);
- myType &= ~Type_Segments;
- allocateNodes (nNodes);
-
- myNLineNodes = nPoints;
- const Standard_Size nBytes = NBytesInd(nPoints, myIndexType);
- mypLines = static_cast<Standard_Integer *> (myAlloc->Allocate(nBytes));
- }
-}
-
-//=======================================================================
-//function : SetSegmentPrs
-//purpose :
-//=======================================================================
-
-void NIS_Triangulated::SetSegmentPrs (const Standard_Integer nSegments,
- const Standard_Integer nNodes)
-{
- if (nSegments <= 0)
- myType &= ~(Type_Loop | Type_Segments);
- else {
- myType |= Type_Segments;
- if (myNLineNodes)
- myAlloc->Free(mypLines);
- myType &= ~(Type_Line | Type_Loop);
- allocateNodes (nNodes);
-
- myNLineNodes = nSegments*2;
- const Standard_Size nBytes = NBytesInd(myNLineNodes, myIndexType);
- mypLines = static_cast<Standard_Integer *> (myAlloc->Allocate(nBytes));
- }
-}
-
-//=======================================================================
-//function : ~NIS_Triangulated
-//purpose : Destructor
-//=======================================================================
-
-NIS_Triangulated::~NIS_Triangulated ()
-{
- Clear();
-}
-
-//=======================================================================
-//function : DefaultDrawer
-//purpose :
-//=======================================================================
-
-NIS_Drawer * NIS_Triangulated::DefaultDrawer (NIS_Drawer * theDrawer) const
-{
- NIS_TriangulatedDrawer * aDrawer =
- theDrawer ? static_cast<NIS_TriangulatedDrawer *>(theDrawer)
- : new NIS_TriangulatedDrawer (Quantity_NOC_RED);
- aDrawer->myIsDrawPolygons = myIsDrawPolygons;
- aDrawer->myPolygonType = myPolygonType;
- return aDrawer;
-}
-
-//=======================================================================
-//function : ComputeBox
-//purpose :
-//=======================================================================
-
-void NIS_Triangulated::ComputeBox (Bnd_B3f& theBox,
- const Standard_Integer nNodes,
- const Standard_ShortReal* pNodes,
- const Standard_Integer nCoord)
-{
- theBox.Clear();
- if (nNodes > 0) {
- Standard_ShortReal aBox[6] = {
- pNodes[0], pNodes[1], 0.,
- pNodes[0], pNodes[1], 0.
- };
- if (nCoord > 2) {
- aBox[2] = pNodes[2];
- aBox[5] = pNodes[2];
- }
- for (Standard_Integer i = 1; i < nNodes; i++) {
- const Standard_ShortReal * pNode = &pNodes[i * nCoord];
- if (aBox[0] > pNode[0])
- aBox[0] = pNode[0];
- else if (aBox[3] < pNode[0])
- aBox[3] = pNode[0];
- if (aBox[1] > pNode[1])
- aBox[1] = pNode[1];
- else if (aBox[4] < pNode[1])
- aBox[4] = pNode[1];
- if (nCoord > 2) {
- if (aBox[2] > pNode[2])
- aBox[2] = pNode[2];
- else if (aBox[5] < pNode[2])
- aBox[5] = pNode[2];
- }
- }
- theBox.Add (gp_XYZ (Standard_Real(aBox[0]),
- Standard_Real(aBox[1]),
- Standard_Real(aBox[2])));
- theBox.Add (gp_XYZ (Standard_Real(aBox[3]),
- Standard_Real(aBox[4]),
- Standard_Real(aBox[5])));
- }
-}
-
-//=======================================================================
-//function : computeBox
-//purpose :
-//=======================================================================
-
-void NIS_Triangulated::computeBox ()
-{
- ComputeBox (myBox, myNNodes, mypNodes, myNodeCoord);
-}
-
-//=======================================================================
-//function : SetNode
-//purpose :
-//=======================================================================
-
-void NIS_Triangulated::SetNode (const Standard_Integer ind,
- const gp_XYZ& thePnt)
-{
- if (ind >= myNNodes)
- Standard_OutOfRange::Raise ("NIS_Triangulated::SetNode");
- Standard_ShortReal * pNode = &mypNodes[myNodeCoord * ind];
- pNode[0] = Standard_ShortReal(thePnt.X());
- pNode[1] = Standard_ShortReal(thePnt.Y());
- if (myNodeCoord > 2)
- pNode[2] = Standard_ShortReal(thePnt.Z());
- setIsUpdateBox(Standard_True);
-}
-
-//=======================================================================
-//function : SetNode
-//purpose :
-//=======================================================================
-
-void NIS_Triangulated::SetNode (const Standard_Integer ind,
- const gp_XY& thePnt)
-{
- if (ind >= myNNodes)
- Standard_OutOfRange::Raise ("NIS_Triangulated::SetNode");
- Standard_ShortReal * pNode = &mypNodes[myNodeCoord * ind];
- pNode[0] = Standard_ShortReal(thePnt.X());
- pNode[1] = Standard_ShortReal(thePnt.Y());
- if (myNodeCoord > 2)
- pNode[2] = 0.f;
- setIsUpdateBox(Standard_True);
-}
-
-//=======================================================================
-//function : SetTriangle
-//purpose :
-//=======================================================================
-
-void NIS_Triangulated::SetTriangle (const Standard_Integer ind,
- const Standard_Integer iNode0,
- const Standard_Integer iNode1,
- const Standard_Integer iNode2)
-{
- if (ind >= myNTriangles)
- Standard_OutOfRange::Raise ("NIS_Triangulated::SetTriangle");
- switch (myIndexType) {
- case 0: // 8bit
- {
- unsigned char * pTri =
- reinterpret_cast<unsigned char *>(mypTriangles) + (3 * ind);
- pTri[0] = static_cast<unsigned char>(iNode0);
- pTri[1] = static_cast<unsigned char>(iNode1);
- pTri[2] = static_cast<unsigned char>(iNode2);
- }
- break;
- case 1: // 16bit
- {
- unsigned short * pTri =
- reinterpret_cast<unsigned short *>(mypTriangles) + (3 * ind);
- pTri[0] = static_cast<unsigned short>(iNode0);
- pTri[1] = static_cast<unsigned short>(iNode1);
- pTri[2] = static_cast<unsigned short>(iNode2);
- }
- break;
- default: // 32bit
- {
- Standard_Integer * pTri = &mypTriangles[3*ind];
- pTri[0] = iNode0;
- pTri[1] = iNode1;
- pTri[2] = iNode2;
- }
- }
-}
-
-//=======================================================================
-//function : SetLineNode
-//purpose :
-//=======================================================================
-
-void NIS_Triangulated::SetLineNode (const Standard_Integer ind,
- const Standard_Integer iNode)
-{
- if (ind >= myNLineNodes)
- Standard_OutOfRange::Raise ("NIS_Triangulated::SetTriangle");
- switch (myIndexType) {
- case 0: // 8bit
- {
- unsigned char * pInd =
- reinterpret_cast<unsigned char *>(mypLines) + ind;
- pInd[0] = static_cast<unsigned char>(iNode);
- }
- break;
- case 1: // 16bit
- {
- unsigned short * pInd =
- reinterpret_cast<unsigned short *>(mypLines) + ind;
- pInd[0] = static_cast<unsigned short>(iNode);
- }
- break;
- default: // 32bit
- mypLines[ind] = iNode;
- }
-}
-
-//=======================================================================
-//function : SetPolygonNode
-//purpose :
-//=======================================================================
-
-void NIS_Triangulated::SetPolygonNode (const Standard_Integer indPoly,
- const Standard_Integer ind,
- const Standard_Integer iNode)
-{
- if (indPoly >= static_cast<Standard_Integer>(myNPolygons))
- Standard_OutOfRange::Raise ("NIS_Triangulated::SetPolygonNode");
-
- Standard_Integer * aPoly = mypPolygons[indPoly];
- switch (myIndexType) {
- case 0: // 8bit
- {
- unsigned char aNNode = * (reinterpret_cast<unsigned char *>(aPoly));
- if (static_cast<unsigned char>(ind) >= aNNode)
- Standard_OutOfRange::Raise ("NIS_Triangulated::SetPolygonNode");
-
- unsigned char * pInd =
- reinterpret_cast<unsigned char *>(aPoly) + ind + 1;
- pInd[0] = static_cast<unsigned char>(iNode);
- }
- break;
- case 1: // 16bit
- {
- unsigned short aNNode = * (reinterpret_cast<unsigned short *>(aPoly));
- if (static_cast<unsigned short>(ind) >= aNNode)
- Standard_OutOfRange::Raise ("NIS_Triangulated::SetPolygonNode");
-
- unsigned short * pInd =
- reinterpret_cast<unsigned short *>(aPoly) + ind + 1;
- pInd[0] = static_cast<unsigned short>(iNode);
- }
- break;
- default: // 32bit
- if (ind >= aPoly[0])
- Standard_OutOfRange::Raise ("NIS_Triangulated::SetPolygonNode");
- aPoly[ind + 1] = iNode;
- }
-}
-
-//=======================================================================
-//function : NPolygonNodes
-//purpose :
-//=======================================================================
-Standard_Integer NIS_Triangulated::NPolygonNodes
- (const Standard_Integer indPoly)const
-{
- Standard_Integer aResult(0);
- if (indPoly >= static_cast<Standard_Integer>(myNPolygons))
- Standard_OutOfRange::Raise ("NIS_Triangulated::PolygonNode");
- Standard_Integer * aPoly = mypPolygons[indPoly];
- switch (myIndexType) {
- case 0: // 8bit
- {
- unsigned char aNNode = * (reinterpret_cast<unsigned char *>(aPoly));
- aResult = static_cast<Standard_Integer>(aNNode);
- }
- break;
- case 1: // 16bit
- {
- unsigned short aNNode = * (reinterpret_cast<unsigned short *>(aPoly));
- aResult = static_cast<Standard_Integer>(aNNode);
- }
- break;
- default: // 32bit
- {
- aResult = aPoly[0];
- }
- }
- return aResult;
-}
-
-//=======================================================================
-//function : PolygonNode
-//purpose :
-//=======================================================================
-
-Standard_Integer NIS_Triangulated::PolygonNode
- (const Standard_Integer indPoly,
- const Standard_Integer ind)const
-{
- Standard_Integer aResult(-1);
- if (indPoly >= static_cast<Standard_Integer>(myNPolygons))
- Standard_OutOfRange::Raise ("NIS_Triangulated::PolygonNode");
- const Standard_Integer * aPoly = mypPolygons[indPoly];
- switch (myIndexType) {
- case 0: // 8bit
- {
- const unsigned char * pInd =
- reinterpret_cast<const unsigned char *>(aPoly);
- if (static_cast<unsigned char>(ind) >= pInd[0])
- Standard_OutOfRange::Raise ("NIS_Triangulated::PolygonNode");
-
- aResult = static_cast<Standard_Integer>(pInd[ind + 1]);
- }
- break;
- case 1: // 16bit
- {
- const unsigned short * pInd =
- reinterpret_cast<const unsigned short *>(aPoly);
- if (static_cast<unsigned short>(ind) >= pInd[0])
- Standard_OutOfRange::Raise ("NIS_Triangulated::PolygonNode");
-
- aResult = static_cast<Standard_Integer>(pInd[ind + 1]);
- }
- break;
- default: // 32bit
- {
- if (ind >= aPoly[0])
- Standard_OutOfRange::Raise ("NIS_Triangulated::PolygonNode");
- aResult = aPoly[ind + 1];
- }
- }
- return aResult;
-}
-
-//=======================================================================
-//function : SetPolygon
-//purpose :
-//=======================================================================
-
-void NIS_Triangulated::SetPolygon (const Standard_Integer ind,
- const Standard_Integer theSz)
-{
- if (ind >= static_cast<Standard_Integer>(myNPolygons))
- Standard_OutOfRange::Raise ("NIS_Triangulated::SetPolygon");
- switch (myIndexType) {
- case 0: // 8bit
- {
- unsigned char * anArray = static_cast <unsigned char *>
- (myAlloc->Allocate (sizeof(unsigned char) * (theSz+1)));
- mypPolygons[ind] = reinterpret_cast<Standard_Integer *> (anArray);
- anArray[0] = static_cast<unsigned char>(theSz);
- }
- break;
- case 1: // 16bit
- {
- unsigned short * anArray = static_cast <unsigned short *>
- (myAlloc->Allocate (sizeof(unsigned short) * (theSz+1)));
- mypPolygons[ind] = reinterpret_cast<Standard_Integer *> (anArray);
- anArray[0] = static_cast<unsigned short>(theSz);
- }
- break;
- default: // 32bit
- {
- Standard_Integer * anArray = static_cast <Standard_Integer *>
- (myAlloc->Allocate (sizeof(Standard_Integer) * (theSz+1)));
- mypPolygons[ind] = anArray;
- anArray[0] = theSz;
- }
- }
-}
-
-//=======================================================================
-//function : SetDrawPolygons
-//purpose :
-//=======================================================================
-
-void NIS_Triangulated::SetDrawPolygons (const Standard_Boolean isDrawPolygons)
-{
- if (GetDrawer().IsNull())
- myIsDrawPolygons = isDrawPolygons;
- else {
- if (myIsDrawPolygons != isDrawPolygons) {
- const Handle(NIS_TriangulatedDrawer) aDrawer =
- static_cast<NIS_TriangulatedDrawer *>(DefaultDrawer(0L));
- aDrawer->Assign (GetDrawer());
- aDrawer->myIsDrawPolygons = isDrawPolygons;
- SetDrawer (aDrawer);
- myIsDrawPolygons = isDrawPolygons;
- }
- }
-}
-
-//=======================================================================
-//function : SetPolygonType
-//purpose : Set the type of polygon rendering
-//=======================================================================
-
-void NIS_Triangulated::SetPolygonType
- (const NIS_Triangulated::PolygonType theType)
-{
- if (GetDrawer().IsNull())
- myPolygonType = static_cast<unsigned int>(theType);
- else {
- if (myPolygonType != static_cast<unsigned int>(theType)) {
- const Handle(NIS_TriangulatedDrawer) aDrawer =
- static_cast<NIS_TriangulatedDrawer *>(DefaultDrawer(0L));
- aDrawer->Assign (GetDrawer());
- aDrawer->myPolygonType = theType;
- SetDrawer (aDrawer);
- myPolygonType = static_cast<unsigned int>(theType);
- }
- }
-}
-
-//=======================================================================
-//function : SetColor
-//purpose : Set the normal color for presentation.
-//=======================================================================
-
-void NIS_Triangulated::SetColor (const Quantity_Color& theColor)
-{
- const Handle(NIS_TriangulatedDrawer) aDrawer =
- static_cast<NIS_TriangulatedDrawer *>(DefaultDrawer(0L));
- aDrawer->Assign (GetDrawer());
- aDrawer->myColor[NIS_Drawer::Draw_Normal] = theColor;
- aDrawer->myColor[NIS_Drawer::Draw_Top] = theColor;
- aDrawer->myColor[NIS_Drawer::Draw_Transparent] = theColor;
- SetDrawer (aDrawer);
-}
-
-//=======================================================================
-//function : GetColor
-//purpose : Get Normal, Transparent or Hilighted color of the presentation.
-//=======================================================================
-
-Quantity_Color NIS_Triangulated::GetColor
- (const NIS_Drawer::DrawType theDrawType) const
-{
- Handle(NIS_TriangulatedDrawer) aDrawer =
- Handle(NIS_TriangulatedDrawer)::DownCast( GetDrawer() );
- if (aDrawer.IsNull() == Standard_False)
- {
- return aDrawer->myColor[theDrawType];
- }
- return Quantity_Color(); // return null color object
-}
-
-//=======================================================================
-//function : SetHilightColor
-//purpose : Set the color for hilighted presentation.
-//=======================================================================
-
-void NIS_Triangulated::SetHilightColor (const Quantity_Color& theColor)
-{
- const Handle(NIS_TriangulatedDrawer) aDrawer =
- static_cast<NIS_TriangulatedDrawer *>(DefaultDrawer(0L));
- aDrawer->Assign (GetDrawer());
- aDrawer->myColor[NIS_Drawer::Draw_Hilighted] = theColor;
- SetDrawer (aDrawer);
-}
-
-//=======================================================================
-//function : SetDynHilightColor
-//purpose : Set the color for dynamic hilight presentation.
-//=======================================================================
-
-void NIS_Triangulated::SetDynHilightColor(const Quantity_Color& theColor)
-{
- const Handle(NIS_TriangulatedDrawer) aDrawer =
- static_cast<NIS_TriangulatedDrawer *>(DefaultDrawer(0L));
- aDrawer->Assign (GetDrawer());
- aDrawer->myColor[NIS_Drawer::Draw_DynHilighted] = theColor;
- SetDrawer (aDrawer);
-}
-
-//=======================================================================
-//function : SetLineWidth
-//purpose : Set the width of line presentations in pixels.
-//=======================================================================
-
-void NIS_Triangulated::SetLineWidth (const Standard_Real theWidth)
-{
- const Handle(NIS_TriangulatedDrawer) aDrawer =
- static_cast<NIS_TriangulatedDrawer *>(DefaultDrawer(0L));
- aDrawer->Assign (GetDrawer());
- aDrawer->myLineWidth = (Standard_ShortReal) theWidth;
- SetDrawer (aDrawer);
-}
-
-//=======================================================================
-//function : Clone
-//purpose :
-//=======================================================================
-
-void NIS_Triangulated::Clone (const Handle(NCollection_BaseAllocator)& theAlloc,
- Handle(NIS_InteractiveObject)& theDest) const
-{
- Handle(NIS_Triangulated) aNewObj;
- if (theDest.IsNull()) {
- aNewObj = new (theAlloc) NIS_Triangulated(myNNodes, myNodeCoord == 2,
- theAlloc);
- aNewObj->myIsCloned = Standard_True;
- theDest = aNewObj;
- } else {
- aNewObj = reinterpret_cast<NIS_Triangulated*> (theDest.operator->());
- aNewObj->myAlloc = theAlloc.operator->();
- aNewObj->myNNodes = 0;
- aNewObj->allocateNodes(myNNodes);
- }
- NIS_InteractiveObject::Clone(theAlloc, theDest);
- if (myNNodes > 0)
- {
- // copy nodes
- memcpy(aNewObj->mypNodes, mypNodes,
- myNNodes * myNodeCoord * sizeof(Standard_ShortReal));
- // copy triangles
- aNewObj->myNTriangles = myNTriangles;
- if (myNTriangles) {
- const Standard_Size nBytes = NBytesInd(3 * myNTriangles, myIndexType);
- aNewObj->mypTriangles = static_cast<Standard_Integer *>
- (theAlloc->Allocate(nBytes));
- memcpy(aNewObj->mypTriangles, mypTriangles, nBytes);
- }
- // copy lines/segments
- aNewObj->myNLineNodes = myNLineNodes;
- if (myNLineNodes) {
- const Standard_Size nBytes = NBytesInd(myNLineNodes, myIndexType);
- aNewObj->mypLines = static_cast<Standard_Integer *>
- (theAlloc->Allocate(nBytes));
- memcpy(aNewObj->mypLines, mypLines, nBytes);
- }
- // copy polygons
- aNewObj->myNPolygons = myNPolygons;
- if (myNPolygons) {
- const Standard_Size nBytes = sizeof(Standard_Integer *)*myNPolygons;
- aNewObj->mypPolygons = static_cast<Standard_Integer **>
- (theAlloc->Allocate(nBytes));
- for (unsigned int i = 0; i < myNPolygons; i++) {
- const Standard_Integer nNodes = NPolygonNodes(i);
- const Standard_Size nBytes = NBytesInd(nNodes+1, myIndexType);
- aNewObj->mypPolygons[i] = static_cast <Standard_Integer *>
- (theAlloc->Allocate (nBytes));
- memcpy(aNewObj->mypPolygons[i], mypPolygons[i], nBytes);
- }
- }
- }
- aNewObj->myType = myType;
- aNewObj->myIsDrawPolygons = myIsDrawPolygons;
- aNewObj->myIndexType = myIndexType;
- aNewObj->myPolygonType = myPolygonType;
-}
-
-//=======================================================================
-//function : Delete
-//purpose :
-//=======================================================================
-
-void NIS_Triangulated::Delete () const
-{
- if (myIsCloned == Standard_False)
- Standard_Transient::Delete();
- else {
- // Call the destructor and then release the memory occupied by the instance.
- // This is required when the NIS_Triangulated instance is allocated in
- // the same allocator as its internal arrays.
- NIS_Triangulated* pThis = const_cast<NIS_Triangulated*>(this);
- pThis->~NIS_Triangulated();
- myAlloc->Free(pThis);
- }
-}
-
-//=======================================================================
-//function : Intersect
-//purpose :
-//=======================================================================
-
-Standard_Boolean NIS_Triangulated::Intersect
- (const Bnd_B3f& theBox,
- const gp_Trsf& theTrf,
- const Standard_Boolean isFullIn) const
-{
- Standard_Boolean aResult (isFullIn);
-
- if ((myType & Type_Triangulation) && myIsDrawPolygons == Standard_False) {
- unsigned int nbSteps = (unsigned)myNNodes * myNodeCoord;
- for (unsigned int iNode = 0; iNode < nbSteps; iNode += myNodeCoord)
- {
- gp_XYZ aPnt (mypNodes[iNode+0], mypNodes[iNode+1], 0.);
- if (myNodeCoord > 2)
- aPnt.SetZ (mypNodes[iNode+2]);
- theTrf.Transforms (aPnt);
- if (theBox.IsOut (aPnt)) {
- if (isFullIn) {
- aResult = Standard_False;
- break;
- }
- } else {
- if (isFullIn == Standard_False) {
- aResult = Standard_True;
- break;
- }
- }
- }
- }
- if (aResult == isFullIn) {
- if (myType & Type_Segments) {
- for (Standard_Integer i = 0; i < myNLineNodes; i+=2) {
- const gp_Pnt aPnt[2] = {
- nodeAtInd(mypLines, i+0).Transformed(theTrf),
- nodeAtInd(mypLines, i+1).Transformed(theTrf)
- };
- if (isFullIn) {
- if (seg_box_included (theBox, aPnt) == 0) {
- aResult = Standard_False;
- break;
- }
- } else {
- if (seg_box_intersect (theBox, aPnt)) {
- aResult = Standard_True;
- break;
- }
- }
- }
- } else if (myType & Type_Line) {
- for (Standard_Integer i = 1; i < myNLineNodes; i++) {
- const gp_Pnt aPnt[2] = {
- nodeAtInd(mypLines, i-1).Transformed(theTrf),
- nodeAtInd(mypLines, i+0).Transformed(theTrf)
- };
- if (isFullIn) {
- if (seg_box_included (theBox, aPnt) == 0) {
- aResult = Standard_False;
- break;
- }
- } else {
- if (seg_box_intersect (theBox, aPnt)) {
- aResult = Standard_True;
- break;
- }
- }
- }
- if (aResult == isFullIn && (myType & Type_Loop)) {
- const gp_Pnt aPntLast[2] = {
- nodeAtInd(mypLines, myNLineNodes-1).Transformed(theTrf),
- nodeAtInd(mypLines, 0).Transformed(theTrf)
- };
- if (isFullIn) {
- if (seg_box_included (theBox, aPntLast) == 0)
- aResult = Standard_False;
- } else {
- if (seg_box_intersect (theBox, aPntLast))
- aResult = Standard_True;
- }
- }
- } else if ((myType & Type_Polygons) && myIsDrawPolygons) {
- for (unsigned int iPoly = 0; iPoly < myNPolygons; iPoly++) {
- const Standard_Integer * aPoly = mypPolygons[iPoly];
- const Standard_Integer nNodes = NPolygonNodes(iPoly);
- for (Standard_Integer i = 1; i < nNodes; i++) {
- // index is incremented by 1 for the head number in the array
- const gp_Pnt aPnt[2] = {
- nodeAtInd(aPoly, i+0).Transformed(theTrf),
- nodeAtInd(aPoly, i+1).Transformed(theTrf)
- };
- if (isFullIn) {
- if (seg_box_included (theBox, aPnt) == 0) {
- aResult = Standard_False;
- break;
- }
- } else {
- if (seg_box_intersect (theBox, aPnt)) {
- aResult = Standard_True;
- break;
- }
- }
- }
- if (aResult == isFullIn) {
- const gp_Pnt aPntLast[2] = {
- nodeAtInd(aPoly, nNodes).Transformed(theTrf),
- nodeAtInd(aPoly, 1).Transformed(theTrf)
- };
- if (isFullIn) {
- if (seg_box_included (theBox, aPntLast) == 0)
- aResult = Standard_False;
- } else {
- if (seg_box_intersect (theBox, aPntLast))
- aResult = Standard_True;
- }
- }
- }
- }
- }
- return aResult;
-}
-
-//=======================================================================
-//function : Intersect
-//purpose :
-//=======================================================================
-
-Standard_Real NIS_Triangulated::Intersect (const gp_Ax1& theAxis,
- const Standard_Real theOver) const
-{
- Standard_Real aResult (RealLast());
- Standard_Real start[3], dir[3];
- theAxis.Location().Coord(start[0], start[1], start[2]);
- theAxis.Direction().Coord(dir[0], dir[1], dir[2]);
- double anInter;
-
- if ((myType & Type_Triangulation) && (myIsDrawPolygons == Standard_False))
- for (Standard_Integer i = 0; i < myNTriangles; i++) {
- Standard_Boolean isIntersect(Standard_False);
- if (myIndexType == 0) {
- const unsigned char * pTri =
- reinterpret_cast<unsigned char *>(mypTriangles) + (3 * i);
- if (myNodeCoord > 2)
- isIntersect = tri_line_intersect (start, dir,
- &mypNodes[myNodeCoord * pTri[0]],
- &mypNodes[myNodeCoord * pTri[1]],
- &mypNodes[myNodeCoord * pTri[2]],
- &anInter);
- else
- isIntersect = tri2d_line_intersect (start, dir,
- &mypNodes[myNodeCoord * pTri[0]],
- &mypNodes[myNodeCoord * pTri[1]],
- &mypNodes[myNodeCoord * pTri[2]],
- &anInter);
- } else if (myIndexType == 1) {
- const unsigned short * pTri =
- reinterpret_cast<unsigned short *>(mypTriangles) + (3 * i);
- if (myNodeCoord > 2)
- isIntersect = tri_line_intersect (start, dir,
- &mypNodes[myNodeCoord * pTri[0]],
- &mypNodes[myNodeCoord * pTri[1]],
- &mypNodes[myNodeCoord * pTri[2]],
- &anInter);
- else
- isIntersect = tri2d_line_intersect (start, dir,
- &mypNodes[myNodeCoord * pTri[0]],
- &mypNodes[myNodeCoord * pTri[1]],
- &mypNodes[myNodeCoord * pTri[2]],
- &anInter);
- } else {
- const Standard_Integer * pTri = &mypTriangles[3 * i];
- if (myNodeCoord > 2)
- isIntersect = tri_line_intersect (start, dir,
- &mypNodes[myNodeCoord * pTri[0]],
- &mypNodes[myNodeCoord * pTri[1]],
- &mypNodes[myNodeCoord * pTri[2]],
- &anInter);
- else
- isIntersect = tri2d_line_intersect (start, dir,
- &mypNodes[myNodeCoord * pTri[0]],
- &mypNodes[myNodeCoord * pTri[1]],
- &mypNodes[myNodeCoord * pTri[2]],
- &anInter);
- }
- if (isIntersect && anInter < aResult)
- aResult = anInter;
- }
-
- const Standard_Real anOver2 = theOver*theOver;
- if (myType & Type_Segments) {
- Standard_Integer i = 0;
- if (myNodeCoord > 2)
- for (; i < myNLineNodes; i+=2) {
- if (seg_line_intersect (theAxis.Location().XYZ(),
- theAxis.Direction().XYZ(), anOver2,
- nodeArrAtInd(mypLines, i+0),
- nodeArrAtInd(mypLines, i+1),
- &anInter))
- if (anInter < aResult)
- aResult = anInter;
- }
- else
- for (; i < myNLineNodes; i+=2) {
- if (seg2d_line_intersect (theAxis.Location().XYZ(),
- theAxis.Direction().XYZ(), anOver2,
- nodeArrAtInd(mypLines, i+0),
- nodeArrAtInd(mypLines, i+1),
- &anInter))
- if (anInter < aResult)
- aResult = anInter;
- }
- } else if (myType & Type_Line) {
- Standard_Integer i = 1;
- if (myNodeCoord > 2) {
- for (; i < myNLineNodes; i++) {
- if (seg_line_intersect (theAxis.Location().XYZ(),
- theAxis.Direction().XYZ(), anOver2,
- nodeArrAtInd(mypLines, i-1),
- nodeArrAtInd(mypLines, i-0),
- &anInter))
- if (anInter < aResult)
- aResult = anInter;
- }
- if (myType & Type_Loop)
- if (seg_line_intersect (theAxis.Location().XYZ(),
- theAxis.Direction().XYZ(), anOver2,
- nodeArrAtInd(mypLines, myNLineNodes-1),
- nodeArrAtInd(mypLines, 0),
- &anInter))
- if (anInter < aResult)
- aResult = anInter;
- } else {
- for (; i < myNLineNodes; i++) {
- if (seg2d_line_intersect (theAxis.Location().XYZ(),
- theAxis.Direction().XYZ(), anOver2,
- nodeArrAtInd(mypLines, i-1),
- nodeArrAtInd(mypLines, i-0),
- &anInter))
- if (anInter < aResult)
- aResult = anInter;
- }
- if (myType & Type_Loop)
- if (seg2d_line_intersect (theAxis.Location().XYZ(),
- theAxis.Direction().XYZ(), anOver2,
- nodeArrAtInd(mypLines, myNLineNodes-1),
- nodeArrAtInd(mypLines, 0),
- &anInter))
- if (anInter < aResult)
- aResult = anInter;
- }
- }
-
- if ((myType & Type_Polygons) && myIsDrawPolygons) {
- for (unsigned int iPoly = 0; iPoly < myNPolygons; iPoly++) {
- const Standard_Integer * aPoly = mypPolygons[iPoly];
- const Standard_Integer nNodes = NPolygonNodes(iPoly);
- Standard_Integer i = 1;
- if (myNodeCoord > 2) {
- for (; i < nNodes; i++) {
- // Node index is incremented for the head of polygon indice array
- if (seg_line_intersect (theAxis.Location().XYZ(),
- theAxis.Direction().XYZ(), anOver2,
- nodeArrAtInd(aPoly, i+0),
- nodeArrAtInd(aPoly, i+1),
- &anInter))
- if (anInter < aResult)
- aResult = anInter;
- }
- if (seg_line_intersect (theAxis.Location().XYZ(),
- theAxis.Direction().XYZ(), anOver2,
- nodeArrAtInd(aPoly, nNodes),
- nodeArrAtInd(aPoly, 1),
- &anInter))
- if (anInter < aResult)
- aResult = anInter;
- } else {
- for (; i < nNodes; i++) {
- // Node index is incremented for the head of polygon indice array
- if (seg2d_line_intersect (theAxis.Location().XYZ(),
- theAxis.Direction().XYZ(), anOver2,
- nodeArrAtInd(aPoly, i+0),
- nodeArrAtInd(aPoly, i+1),
- &anInter))
- if (anInter < aResult)
- aResult = anInter;
- }
- if (seg2d_line_intersect (theAxis.Location().XYZ(),
- theAxis.Direction().XYZ(), anOver2,
- nodeArrAtInd(aPoly, nNodes),
- nodeArrAtInd(aPoly, 1),
- &anInter))
- if (anInter < aResult)
- aResult = anInter;
- }
- }
- }
- return aResult;
-}
-
-//=======================================================================
-//function : Intersect
-//purpose :
-//=======================================================================
-Standard_Boolean NIS_Triangulated::Intersect
- (const NCollection_List<gp_XY> &thePolygon,
- const gp_Trsf &theTrf,
- const Standard_Boolean isFullIn) const
-{
- Standard_Boolean aResult (isFullIn);
-
- if ((myType & Type_Triangulation) && myIsDrawPolygons == Standard_False) {
- unsigned int nbSteps = (unsigned)myNNodes * myNodeCoord;
- for (unsigned int iNode = 0; iNode < nbSteps; iNode += myNodeCoord)
- {
- gp_XYZ aPnt (mypNodes[iNode+0], mypNodes[iNode+1], 0.);
- if (myNodeCoord > 2)
- aPnt.SetZ (mypNodes[iNode+2]);
- theTrf.Transforms (aPnt);
-
- gp_XY aP2d(aPnt.X(), aPnt.Y());
-
- if (!NIS_Triangulated::IsIn(thePolygon, aP2d)) {
- if (isFullIn) {
- aResult = Standard_False;
- break;
- }
- } else {
- if (isFullIn == Standard_False) {
- aResult = Standard_True;
- break;
- }
- }
- }
- }
- if (aResult == isFullIn) {
- if (myType & Type_Segments) {
- for (Standard_Integer i = 0; i < myNLineNodes; i+=2) {
- const gp_Pnt aPnt[2] = {
- nodeAtInd(mypLines, i+0).Transformed(theTrf),
- nodeAtInd(mypLines, i+1).Transformed(theTrf)
- };
- const gp_XY aP2d[2] = { gp_XY(aPnt[0].X(), aPnt[0].Y()),
- gp_XY(aPnt[1].X(), aPnt[1].Y()) };
-
- if (isFullIn) {
- if (seg_polygon_included (thePolygon, aP2d) == 0) {
- aResult = Standard_False;
- break;
- }
- } else {
- if (seg_polygon_intersect (thePolygon, aP2d)) {
- aResult = Standard_True;
- break;
- }
- }
- }
- } else if (myType & Type_Line) {
- for (Standard_Integer i = 1; i < myNLineNodes; i++) {
- const gp_Pnt aPnt[2] = {
- nodeAtInd(mypLines, i-1).Transformed(theTrf),
- nodeAtInd(mypLines, i+0).Transformed(theTrf)
- };
- const gp_XY aP2d[2] = { gp_XY(aPnt[0].X(), aPnt[0].Y()),
- gp_XY(aPnt[1].X(), aPnt[1].Y()) };
- if (isFullIn) {
- if (seg_polygon_included (thePolygon, aP2d) == 0) {
- aResult = Standard_False;
- break;
- }
- } else {
- if (seg_polygon_intersect (thePolygon, aP2d)) {
- aResult = Standard_True;
- break;
- }
- }
- }
- if (aResult == isFullIn && (myType & Type_Loop)) {
- const gp_Pnt aPntLast[2] = {
- nodeAtInd(mypLines, myNLineNodes-1).Transformed(theTrf),
- nodeAtInd(mypLines, 0).Transformed(theTrf)
- };
- const gp_XY aP2dLast[2] = { gp_XY(aPntLast[0].X(), aPntLast[0].Y()),
- gp_XY(aPntLast[1].X(), aPntLast[1].Y()) };
-
- if (isFullIn) {
- if (seg_polygon_included (thePolygon, aP2dLast) == 0)
- aResult = Standard_False;
- } else {
- if (seg_polygon_intersect (thePolygon, aP2dLast))
- aResult = Standard_True;
- }
- }
- } else if ((myType & Type_Polygons) && myIsDrawPolygons) {
- for (unsigned int iPoly = 0; iPoly < myNPolygons; iPoly++) {
- const Standard_Integer * aPoly = mypPolygons[iPoly];
- const Standard_Integer nNodes = NPolygonNodes(iPoly);
- for (Standard_Integer i = 1; i < nNodes; i++) {
- const gp_Pnt aPnt[2] = {
- nodeAtInd(aPoly, i+0).Transformed(theTrf),
- nodeAtInd(aPoly, i+1).Transformed(theTrf)
- };
- const gp_XY aP2d[2] = { gp_XY(aPnt[0].X(), aPnt[0].Y()),
- gp_XY(aPnt[1].X(), aPnt[1].Y()) };
- if (isFullIn) {
- if (seg_polygon_included (thePolygon, aP2d) == 0) {
- aResult = Standard_False;
- break;
- }
- } else {
- if (seg_polygon_intersect (thePolygon, aP2d)) {
- aResult = Standard_True;
- break;
- }
- }
- }
- if (aResult == isFullIn) {
- const gp_Pnt aPntLast[2] = {
- nodeAtInd(aPoly, nNodes).Transformed(theTrf),
- nodeAtInd(aPoly, 1).Transformed(theTrf)
- };
- const gp_XY aP2dLast[2] = { gp_XY(aPntLast[0].X(), aPntLast[0].Y()),
- gp_XY(aPntLast[1].X(), aPntLast[1].Y()) };
- if (isFullIn) {
- if (seg_polygon_included (thePolygon, aP2dLast) == 0)
- aResult = Standard_False;
- } else {
- if (seg_polygon_intersect (thePolygon, aP2dLast))
- aResult = Standard_True;
- }
- }
- }
- }
- }
- return aResult;
-}
-
-/* =====================================================================
-Function : determinant
-Purpose : Calculate the minor of the given matrix, defined by the columns
- specified by values c1, c2, c3
-Parameters :
-Returns : determinant value
-History :
-======================================================================== */
-
-static double determinant (const double a[3][4],
- const int c1,
- const int c2,
- const int c3)
-{
- return a[0][c1]*a[1][c2]*a[2][c3] +
- a[0][c2]*a[1][c3]*a[2][c1] +
- a[0][c3]*a[1][c1]*a[2][c2] -
- a[0][c3]*a[1][c2]*a[2][c1] -
- a[0][c2]*a[1][c1]*a[2][c3] -
- a[0][c1]*a[1][c3]*a[2][c2];
-}
-
-/* =====================================================================
-Function : tri_line_intersect
-Purpose : Intersect a triangle with a line
-Parameters : start - coordinates of the origin of the line
- dir - coordinates of the direction of the line (normalized)
- V0 - first vertex of the triangle
- V1 - second vertex of the triangle
- V2 - third vertex of the triangle
- tInter - output value, contains the parameter of the intersection
- point on the line (if found). May be NULL pointer
-Returns : int = 1 if intersection found, 0 otherwise
-======================================================================== */
-
-int NIS_Triangulated::tri_line_intersect (const double start[3],
- const double dir[3],
- const float V0[3],
- const float V1[3],
- const float V2[3],
- double * tInter)
-{
- int res = 0;
- const double conf = 1E-15;
-
- const double array[][4] = {
- { -dir[0],
- double(V1[0] - V0[0]), double(V2[0] - V0[0]), start[0] - double(V0[0]) },
- { -dir[1],
- double(V1[1] - V0[1]), double(V2[1] - V0[1]), start[1] - double(V0[1]) },
- { -dir[2],
- double(V1[2] - V0[2]), double(V2[2] - V0[2]), start[2] - double(V0[2]) }
- };
-
- const double d = determinant( array, 0, 1, 2 );
- const double dt = determinant( array, 3, 1, 2 );
-
- if (d > conf) {
- const double da = determinant( array, 0, 3, 2 );
- if (da > -conf) {
- const double db = determinant( array, 0, 1, 3 );
- res = (db > -conf && da+db <= d+conf);
- }
- } else if (d < -conf) {
- const double da = determinant( array, 0, 3, 2 );
- if (da < conf) {
- const double db = determinant( array, 0, 1, 3 );
- res = (db < conf && da+db >= d-conf);
- }
- }
- if (res && tInter)
- *tInter = dt / d;
-
- return res;
-}
-
-/* =====================================================================
-Function : tri2d_line_intersect
-Purpose : Intersect a 2D triangle with a 3D line. Z coordinate of triangle
- : is zero
-Parameters : start - coordinates of the origin of the line
- dir - coordinates of the direction of the line (normalized)
- V0 - first vertex of the triangle
- V1 - second vertex of the triangle
- V2 - third vertex of the triangle
- tInter - output value, contains the parameter of the intersection
- point on the line (if found). May be NULL pointer
-Returns : int = 1 if intersection found, 0 otherwise
-======================================================================== */
-
-int NIS_Triangulated::tri2d_line_intersect (const double start[3],
- const double dir[3],
- const float V0[2],
- const float V1[2],
- const float V2[2],
- double * tInter)
-{
- int res = 0;
- const double conf = 1E-15;
-
- // Parallel case is excluded
- if (dir[2] * dir[2] > conf)
- {
- // Find the 2d intersection of (start, dir) with the plane Z = 0.
- const double p2d[2] = {
- start[0] - dir[0] * start[2] / dir[2],
- start[1] - dir[1] * start[2] / dir[2]
- };
-
- // Classify the 2d intersection using barycentric coordinates
- // (http://www.blackpawn.com/texts/pointinpoly/)
- const double v[][2] = {
- { static_cast<double>(V1[0]-V0[0]), static_cast<double>(V1[1]-V0[1]) },
- { static_cast<double>(V2[0]-V0[0]), static_cast<double>(V2[1]-V0[1]) },
- { static_cast<double>(p2d[0]-V0[0]), static_cast<double>(p2d[1]-V0[1]) }
- };
- const double dot00 = v[0][0]*v[0][0] + v[0][1]*v[0][1];
- const double dot01 = v[0][0]*v[1][0] + v[0][1]*v[1][1];
- const double dot02 = v[0][0]*v[2][0] + v[0][1]*v[2][1];
- const double dot11 = v[1][0]*v[1][0] + v[1][1]*v[1][1];
- const double dot12 = v[1][0]*v[2][0] + v[1][1]*v[2][1];
- const double denom = (dot00 * dot11 - dot01 * dot01);
- if (denom * denom < conf) {
- // Point on the 1st side of the triangle
- res = (dot01 > -conf && dot00 < dot11 + conf);
- } else {
- // Barycentric coordinates of the point
- const double u = (dot11 * dot02 - dot01 * dot12) / denom;
- const double v = (dot00 * dot12 - dot01 * dot02) / denom;
- res = (u > -conf) && (v > -conf) && (u + v < 1. + conf);
- }
- }
- if (res && tInter)
- *tInter = -start[2] / dir[2];
-
- return res;
-}
-
-/* =====================================================================
-Function : seg_line_intersect
-Purpose : Intersect a segment with a line
-Parameters : start - coordinates of the origin of the line
- dir - coordinates of the direction of the line (normalized)
- over2 - maximal square distance between the line and the segment
- for intersection state
- V0 - first vertex of the segment
- V1 - second vertex of the segment
- tInter - output value, contains the parameter of the intersection
- point on the line (if found). May be NULL pointer
-Returns : int = 1 if intersection found, 0 otherwise
-======================================================================== */
-
-int NIS_Triangulated::seg_line_intersect (const gp_XYZ& aStart,
- const gp_XYZ& aDir,
- const double over2,
- const float V0[3],
- const float V1[3],
- double * tInter)
-{
- int res = 0;
- const gp_XYZ aDirSeg (V1[0]-V0[0], V1[1]-V0[1], V1[2]-V0[2]);
- gp_XYZ aDirN = aDirSeg ^ aDir;
- Standard_Real aMod2 = aDirN.SquareModulus();
- if (aMod2 < Precision::Confusion() * 0.001) {
- const gp_XYZ aDelta0 (V0[0]-aStart.X(), V0[1]-aStart.Y(), V0[2]-aStart.Z());
- if ((aDelta0 ^ aDir).SquareModulus() < over2) {
- res = 1;
- const gp_XYZ aDelta1 (V1[0]-aStart.X(),V1[1]-aStart.Y(),V1[2]-aStart.Z());
- if (tInter)
- * tInter = Min (aDelta0 * aDir, aDelta1 * aDir);
- }
- } else {
- // distance between two unlimited lines
- const gp_XYZ aPnt0 (V0[0], V0[1], V0[2]);
- const Standard_Real aDistL = (aDirN * aPnt0) - aDirN * aStart;
- if (aDistL*aDistL < over2 * aMod2) {
- const gp_XYZ aPnt1 (V1[0], V1[1], V1[2]);
- Standard_Real aDist[3] = {
- ((aPnt0 - aStart) ^ aDir).Modulus(),
- ((aPnt1 - aStart) ^ aDir).Modulus(),
- 0.
- };
- // Find the intermediate point by interpolation using the distances from
- // the end points.
- const gp_XYZ aPntI =
- (aPnt0 * aDist[1] + aPnt1 * aDist[0]) / (aDist[0] + aDist[1]);
- aDist[2] = ((aPntI - aStart) ^ aDir).Modulus();
- if (aDist[2] < aDist[0] && aDist[2] < aDist[1]) {
- if (aDist[2]*aDist[2] < over2) {
- res = 1;
- if (tInter)
- * tInter = (aPntI - aStart) * aDir;
- }
- } else if (aDist[0] < aDist[1]) {
- if (aDist[0] * aDist[0] < over2) {
- res = 1;
- if (tInter)
- * tInter = (aPnt0 - aStart) * aDir;
- }
- } else {
- if (aDist[1] * aDist[1] < over2) {
- res = 1;
- if (tInter)
- * tInter = (aPnt1 - aStart) * aDir;
- }
- }
- }
- }
- return res;
-}
-
-/* =====================================================================
-Function : seg2d_line_intersect
-Purpose : Intersect a 2D segment with a 3D line
-Parameters : start - coordinates of the origin of the line
- dir - coordinates of the direction of the line (normalized)
- over2 - maximal square distance between the line and the segment
- for intersection state
- V0 - first vertex of the segment
- V1 - second vertex of the segment
- tInter - output value, contains the parameter of the intersection
- point on the line (if found). May be NULL pointer
-Returns : int = 1 if intersection found, 0 otherwise
-======================================================================== */
-
-int NIS_Triangulated::seg2d_line_intersect (const gp_XYZ& aStart,
- const gp_XYZ& aDir,
- const double over2,
- const float V0[2],
- const float V1[2],
- double * tInter)
-{
- int res = 0;
- const gp_XYZ aDirSeg (V1[0]-V0[0], V1[1]-V0[1], 0.);
- gp_XYZ aDirN = aDirSeg ^ aDir;
- Standard_Real aMod2 = aDirN.SquareModulus();
- if (aMod2 < Precision::Confusion() * 0.001) {
- const gp_XYZ aDelta0 (V0[0]-aStart.X(), V0[1]-aStart.Y(), -aStart.Z());
- if ((aDelta0 ^ aDir).SquareModulus() < over2) {
- res = 1;
- const gp_XYZ aDelta1 (V1[0]-aStart.X(), V1[1]-aStart.Y(), -aStart.Z());
- if (tInter)
- * tInter = Min (aDelta0 * aDir, aDelta1 * aDir);
- }
- } else {
- // distance between two unlimited lines
- const gp_XYZ aPnt0 (V0[0], V0[1], 0.);
- const Standard_Real aDistL = (aDirN * aPnt0) - aDirN * aStart;
- if (aDistL*aDistL < over2 * aMod2) {
- const gp_XYZ aPnt1 (V1[0], V1[1], 0.);
- Standard_Real aDist[3] = {
- ((aPnt0 - aStart) ^ aDir).Modulus(),
- ((aPnt1 - aStart) ^ aDir).Modulus(),
- 0.
- };
- // Find the intermediate point by interpolation using the distances from
- // the end points.
- const gp_XYZ aPntI =
- (aPnt0 * aDist[1] + aPnt1 * aDist[0]) / (aDist[0] + aDist[1]);
- aDist[2] = ((aPntI - aStart) ^ aDir).Modulus();
- if (aDist[2] < aDist[0] && aDist[2] < aDist[1]) {
- if (aDist[2]*aDist[2] < over2) {
- res = 1;
- if (tInter)
- * tInter = (aPntI - aStart) * aDir;
- }
- } else if (aDist[0] < aDist[1]) {
- if (aDist[0] * aDist[0] < over2) {
- res = 1;
- if (tInter)
- * tInter = (aPnt0 - aStart) * aDir;
- }
- } else {
- if (aDist[1] * aDist[1] < over2) {
- res = 1;
- if (tInter)
- * tInter = (aPnt1 - aStart) * aDir;
- }
- }
- }
- }
- return res;
-}
-
-//=======================================================================
-//function : seg_box_intersect
-//purpose :
-//=======================================================================
-
-int NIS_Triangulated::seg_box_intersect (const Bnd_B3f& theBox,
- const gp_Pnt thePnt[2])
-{
- int aResult (1);
- if ((thePnt[1].XYZ() - thePnt[0].XYZ()).SquareModulus()
- < Precision::Confusion() * 0.0001)
- aResult = 0;
- else {
- const gp_Dir aDir (thePnt[1].XYZ() - thePnt[0].XYZ());
- if (theBox.IsOut (gp_Ax1(thePnt[0], aDir), Standard_True) ||
- theBox.IsOut (gp_Ax1(thePnt[1],-aDir), Standard_True))
- aResult = 0;
- }
- return aResult;
-}
-
-//=======================================================================
-//function : seg_box_included
-//purpose :
-//=======================================================================
-
-int NIS_Triangulated::seg_box_included (const Bnd_B3f& theBox,
- const gp_Pnt thePnt[2])
-{
- int aResult (0);
- if ((thePnt[1].XYZ() - thePnt[0].XYZ()).SquareModulus()
- > Precision::Confusion() * 0.0001)
- {
- aResult = (theBox.IsOut(thePnt[0].XYZ()) == Standard_False &&
- theBox.IsOut(thePnt[1].XYZ()) == Standard_False);
- }
- return aResult;
-}
-
-//=======================================================================
-//function : seg_polygon_intersect
-//purpose :
-//=======================================================================
-
-int NIS_Triangulated::seg_polygon_intersect
- (const NCollection_List<gp_XY> &thePolygon,
- const gp_XY thePnt[2])
-{
- Standard_Integer aResult = 0;
-
- if (thePolygon.IsEmpty())
- return aResult;
-
- gp_XY aDir(thePnt[1] - thePnt[0]);
- Standard_Real aDist = aDir.SquareModulus();
-
- if (aDist > aTolConf) {
- aDist = Sqrt(aDist);
- aDir.Divide(aDist); // Normalize direction.
-
- // Intersect the line passed through thePnt[0] and thePnt[1] with thePolygon
- // Line is presented in form Ax + By + C = 0
- Standard_Real aA = aDir.Y();
- Standard_Real aB = -aDir.X();
- Standard_Real aC = -(aA*thePnt[0].X() + aB*thePnt[0].Y());
- gp_XY aSegment[2];
- Standard_Real aSignedD[2];
- Standard_Real aDelta = 0.01;
-
- aSegment[0] = thePolygon.Last();
- aSignedD[0] = aA*aSegment[0].X() + aB*aSegment[0].Y() + aC;
-
- NCollection_List<gp_XY>::Iterator anIter(thePolygon);
-
- for (; anIter.More(); anIter.Next()) {
- aSegment[1] = anIter.Value();
- aSignedD[1] = aA*aSegment[1].X() + aB*aSegment[1].Y() + aC;
-
- // Check if there is an intersection.
- if (Abs(aSignedD[0]) <= aTolConf || Abs(aSignedD[1]) <= aTolConf) {
- Standard_Integer anIndexVtx =
- (Abs(aSignedD[0]) > aTolConf) ? 1 :
- (Abs(aSignedD[1]) > aTolConf) ? 0 : -1;
- if (anIndexVtx != -1) {
- // Check if the point aSegment[1] is inside the segment.
- gp_XY aDP(aSegment[anIndexVtx] - thePnt[0]);
- Standard_Real aParam = aDP.Dot(aDir);
-
- if (aParam >= -aTolConf && aParam <= aDist + aTolConf) {
- // Classify a point on the line that is close to aSegment[1] with
- // respect to the polygon.
- gp_XY aPShift;
-
- if (aParam - aDelta >= 0.) {
- aPShift = thePnt[0] + aDir.Multiplied(aParam - aDelta);
- if (!IsIn(thePolygon, aPShift))
- aResult = 1;
- }
-
- // Try to shift on another direction.
- if (!aResult) {
- if (aParam + aDelta <= aDist) {
- aPShift = thePnt[0] + aDir.Multiplied(aParam + aDelta);
- if (!IsIn(thePolygon, aPShift))
- aResult = 1;
- }
- }
- }
- }
- } else if (aSignedD[0]*aSignedD[1] < 0.) {
- // Compute intersection of the segment with the line.
- gp_XY aDSeg(aSegment[1] - aSegment[0]);
- Standard_Real aSegLen = aDSeg.Modulus();
- Standard_Real aParamOnSeg = aSegLen/(1 + Abs(aSignedD[1]/aSignedD[0]));
- gp_XY aPOnLine
- (aSegment[0] + aDSeg.Multiplied(aParamOnSeg/aSegLen));
-
- // Check if aPOnLine inside the segment thePnt[1] - thePnt[0]
- gp_XY aDP(aPOnLine - thePnt[0]);
- Standard_Real aParam = aDP.Dot(aDir);
-
- if (aParam >= -aTolConf && aParam <= aDist + aTolConf) {
- gp_XY aPShift;
-
- if (aParam - aDelta >= 0.) {
- aPShift = thePnt[0] + aDir.Multiplied(aParam - aDelta);
-
- if (!IsIn(thePolygon, aPShift))
- aResult = 1;
- }
-
- // Try to shift on another direction.
- if (!aResult) {
- if (aParam + aDelta <= aDist) {
- aPShift = thePnt[0] + aDir.Multiplied(aParam + aDelta);
-
- if (!IsIn(thePolygon, aPShift))
- aResult = 1;
- }
- }
- }
- }
-
- if (aResult != 0)
- break;
-
- aSegment[0] = aSegment[1];
- aSignedD[0] = aSignedD[1];
- }
- }
-
- return aResult;
-}
-
-//=======================================================================
-//function : seg_polygon_included
-//purpose :
-//=======================================================================
-
-int NIS_Triangulated::seg_polygon_included
- (const NCollection_List<gp_XY> &thePolygon,
- const gp_XY thePnt[2])
-{
- int aResult = 0;
- int anIntersect = seg_polygon_intersect(thePolygon, thePnt);
-
- if (anIntersect == 0) {
- if (IsIn(thePolygon, thePnt[0]) && IsIn(thePolygon, thePnt[1]))
- aResult = 1;
- }
-
- return aResult;
-}
-
-//=======================================================================
-//function : IsIn
-//purpose :
-//=======================================================================
-
-Standard_Boolean NIS_Triangulated::IsIn
- (const NCollection_List<gp_XY> &thePolygon,
- const gp_XY &thePoint)
-{
- if (thePolygon.IsEmpty())
- return Standard_False;
-
- Standard_Integer aCounter = 0; // intersections counter
- gp_XY aSegment[2];
-
- aSegment[0] = thePolygon.Last();
-
- NCollection_List<gp_XY>::Iterator anIter(thePolygon);
-
- for (; anIter.More(); anIter.Next()) {
- aSegment[1] = anIter.Value();
-
- // Compute projection of the point onto the segment.
- Standard_Real aParam = 0.;
- const gp_XY aDelta = aSegment[1] - aSegment[0];
- const gp_XY aDPP0 = thePoint - aSegment[0];
- const Standard_Real aLen2 = aDelta.SquareModulus();
-
- if (IsPositive(aLen2)) {
- aParam = (aDelta*aDPP0)/aLen2;
-
- if (aParam < 0.)
- aParam = 0.;
- else if (aParam > 1.)
- aParam = 1.;
- }
- // Check if the point lies on the segment
- gp_XY aPOnSeg = aSegment[0]*(1. - aParam) + aSegment[1]*aParam;
- Standard_Real aSqrDist = (thePoint - aPOnSeg).SquareModulus();
-
- if (aSqrDist < aTolConf) {
- // The point is on the contour.
- return Standard_True;
- }
-
- // Compute intersection.
- const Standard_Real aProd(aDPP0 ^ aDelta);
-
- if (IsPositive(thePoint.X() - aSegment[0].X())) {
- if (!IsPositive(thePoint.X() - aSegment[1].X())) {
- if (aProd > 0.)
- aCounter++;
- }
- } else {
- if (IsPositive(thePoint.X() - aSegment[1].X())) {
- if (aProd < 0.)
- aCounter++;
- }
- }
-
- aSegment[0] = aSegment[1];
- }
-
- return (aCounter & 0x1);
-}
-
-//=======================================================================
-//function : allocateNodes
-//purpose :
-//=======================================================================
-
-void NIS_Triangulated::allocateNodes (const Standard_Integer nNodes)
-{
- if (nNodes > 0) {
- if (myNNodes > 0)
- myAlloc->Free(mypNodes);
- myNNodes = nNodes;
- mypNodes = static_cast<Standard_ShortReal*>
- (myAlloc->Allocate(sizeof(Standard_ShortReal) * myNodeCoord * nNodes));
- if (nNodes < 256)
- myIndexType = 0;
- else if (nNodes < 65536)
- myIndexType = 1;
- else
- myIndexType = 2;
- }
-}
-
-//=======================================================================
-//function : NodeAtInd
-//purpose : Get the node pointed by the i-th index in the array.
-//=======================================================================
-
-gp_Pnt NIS_Triangulated::nodeAtInd (const Standard_Integer * theArray,
- const Standard_Integer theInd) const
-{
- if (myIndexType == 0) {
- const unsigned char * pInd =
- reinterpret_cast<const unsigned char *>(theArray);
- return gp_Pnt (mypNodes[myNodeCoord * pInd[theInd] + 0],
- mypNodes[myNodeCoord * pInd[theInd] + 1],
- myNodeCoord < 3 ? 0. :
- mypNodes[myNodeCoord * pInd[theInd] + 2]);
- }
- if (myIndexType == 1) {
- const unsigned short * pInd =
- reinterpret_cast<const unsigned short *>(theArray);
- return gp_Pnt (mypNodes[myNodeCoord * pInd[theInd] + 0],
- mypNodes[myNodeCoord * pInd[theInd] + 1],
- myNodeCoord < 3 ? 0. :
- mypNodes[myNodeCoord * pInd[theInd] + 2]);
- }
- return gp_Pnt (mypNodes[myNodeCoord * theArray[theInd] + 0],
- mypNodes[myNodeCoord * theArray[theInd] + 1],
- myNodeCoord < 3 ? 0. :
- mypNodes[myNodeCoord * theArray[theInd] + 2]);
-}
-
-//=======================================================================
-//function : nodeArrAtInd
-//purpose : Get the node pointed by the i-th index in the array.
-//=======================================================================
-
-float* NIS_Triangulated::nodeArrAtInd (const Standard_Integer * theArray,
- const Standard_Integer theInd) const
-{
- float* pResult = 0L;
- if (myIndexType == 0) {
- const unsigned char * pInd =
- reinterpret_cast<const unsigned char *>(theArray);
- pResult = &mypNodes[myNodeCoord * pInd[theInd]];
- }
- else if (myIndexType == 1) {
- const unsigned short * pInd =
- reinterpret_cast<const unsigned short *>(theArray);
- pResult = &mypNodes[myNodeCoord * pInd[theInd]];
- }
- else {
- pResult = &mypNodes[myNodeCoord * theArray[theInd]];
- }
- return pResult;
-}
+++ /dev/null
-// Created on: 2007-07-17
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2007-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#ifndef NIS_Triangulated_HeaderFile
-#define NIS_Triangulated_HeaderFile
-
-#include <NIS_InteractiveObject.hxx>
-#include <Quantity_Color.hxx>
-
-class Handle(NIS_TriangulatedDrawer);
-class NCollection_BaseAllocator;
-class Handle(NCollection_BaseAllocator);
-class NIS_TriangulatedDrawer;
-
-/**
- * Interactive object that consists of triangles, lines and polygons without
- * normals. Particularly can be used to render planar 2D shapes.
- *
- * @par 2D and 3D model
- * Vertices are stored in an array of float numbers, 2 or 3 numbers per vertex.
- * The number of dimensions is defined in the constructor, see the parameter
- * 'is2D'. When 2D is defined then for all vertices the Z coordinate is 0.
- * To display planar objects in a plane different from XOY you should subclass
- * this type together with the correponding Drawer and store the transformation
- * parameters. In Drawer subclass either in method BeforeDraw() or in method
- * Draw() you would call glTranslate() or glMultMatrix() so that all vertices
- * should be located in their proper positions.
- *
- * @par Compressed storage
- * For efficient memory utilization, indice (triangles, segments, polygons) are
- * 8-bit, 16-bit or 32-bit numbers. The width of this numeric representation is
- * chosen automatically when the total number of nodes is passed in the
- * constructor or in any Set* method. For example, if this number of nodes is
- * smaller than 256 then 8-bit representation is selected. The choice is stored
- * in 'myIndexType' data member.
- */
-
-class NIS_Triangulated : public NIS_InteractiveObject
-{
- protected:
- /**
- * Constants defining the mode (type) of presentation. They allow mixed type,
- * e.g., Triangulation+Line. Line and Segments are not mixable, their mix is
- * treated as Line only.
- */
- enum {
- Type_None = 0,
- Type_Loop = 1, //!< modifier to Line
- Type_Line = 2,
- Type_Segments = 4,
- Type_Triangulation = 8,
- Type_Polygons = 16
- };
-
- public:
- /**
- * Enumerated type of polygon rendering.
- */
- enum PolygonType {
- Polygon_Default = 0, //!< Polygon as LINE, Triangulation as FILL
- Polygon_Line = 1, //!< Both Polygon and Triangulation as LINE
- Polygon_Fill = 2 //!< Both Polygon and Triangulation as FILL
- };
-
- public:
- // ---------- PUBLIC METHODS ----------
-
-
- /**
- * Constructor. Optionally defines the number of nodes that will be allocated
- * (this number may be defined later in methods Set*Prs) as well as the
- * memory allocator where the nodes, lines and triangles will be stored by
- * this instance.
- * @param nNodes
- * Total number of nodes that will be initialized for this object
- * @param is2D
- * If true then the nodes will be 2D in plane Z=0, otherwise normal 3D.
- * @param theAlloc
- * Allocator for internal data
- */
- Standard_EXPORT NIS_Triangulated(const Standard_Integer nNodes = 0,
- const Standard_Boolean is2D = Standard_False,
- const Handle(NCollection_BaseAllocator)&
- theAlloc = 0L);
-
- /**
- * Define the polygonal presentration.
- * @param nPolygons
- * Number of separate polygons. If set to 0, polygons are cancelled
- * @param nNodes
- * Optional: Number of nodes to allocate. If left as 0, the previous nodes
- * allocation is used, otherwise a new allocation is created.
- */
- Standard_EXPORT void SetPolygonsPrs
- (const Standard_Integer nPolygons,
- const Standard_Integer nNodes = 0);
-
- /**
- * Define the triangulated presentration.
- * @param nTriangles
- * Number of triangles. If set to 0, triangulation is cancelled
- * @param nNodes
- * Optional: Number of nodes to allocate. If left as 0, the previous nodes
- * allocation is used, otherwise a new allocation is created.
- */
- Standard_EXPORT void SetTriangulationPrs
- (const Standard_Integer nTriangles,
- const Standard_Integer nNodes = 0);
-
- /**
- * Define the line presentration (polygon through points)
- * @param nPoints
- * Number of nodes defining the line. If set to 0, line is cancelled
- * @param isClosed
- * True if the polygon is closed, so the segment between the first and
- * the last points is created automatically.
- * @param nNodes
- * Optional: Number of nodes to allocate. If left as 0, the previous nodes
- * allocation is used, otherwise a new allocation is created.
- */
- Standard_EXPORT void SetLinePrs
- (const Standard_Integer nPoints,
- const Standard_Boolean isClosed,
- const Standard_Integer nNodes = 0);
-
- /**
- * Define the segments presentration. Each segment is defined by 2 nodes
- * @param nSegments
- * Number of segments. If set to 0, segments presentation is cancelled
- * @param nNodes
- * Optional: Number of nodes to allocate. If left as 0, the previous nodes
- * allocation is used, otherwise a new allocation is created.
- */
- Standard_EXPORT void SetSegmentPrs
- (const Standard_Integer nSegments,
- const Standard_Integer nNodes = 0);
-
- /**
- * Query if there is Triangulation component in the presentation.
- */
- inline Standard_Boolean IsTriangulation () const
- { return (myType & Type_Triangulation) != 0; }
-
- /**
- * Query if there is Polygons component in the presentation.
- */
- inline Standard_Boolean IsPolygons () const
- { return (myType & Type_Polygons) != 0; }
-
- /**
- * Query if there is Line component in the presentation.
- */
- inline Standard_Boolean IsLine (Standard_Boolean& isLoop) const
- { isLoop = (myType & Type_Loop) != 0; return (myType & Type_Line) != 0; }
-
- /**
- * Query if there is Segments component in the presentation.
- */
- inline Standard_Boolean IsSegments () const
- { return (myType & Type_Segments) != 0; }
-
- /**
- * Reset all data memebers and free all allocated memory.
- * Called from the destructor, also can be usedto re-initialize a given
- * Interactive Objects.
- */
- Standard_EXPORT void Clear ();
-
- /**
- * Destructor.
- */
- Standard_EXPORT virtual ~NIS_Triangulated ();
-
- /**
- * Create a default drawer instance.
- */
- Standard_EXPORT virtual NIS_Drawer *
- DefaultDrawer (NIS_Drawer *) const;
-
- /**
- * Define the coordinates of node [ind].
- */
- Standard_EXPORT void SetNode (const Standard_Integer ind,
- const gp_XYZ& thePnt);
-
- /**
- * Define the coordinates of node [ind]. Z coordinate is assigned to 0.
- */
- Standard_EXPORT void SetNode (const Standard_Integer ind,
- const gp_XY& thePnt);
-
- /**
- * Define the triangle [ind] by indices of its three nodes.
- */
- Standard_EXPORT void SetTriangle(const Standard_Integer ind,
- const Standard_Integer iNode0,
- const Standard_Integer iNode1,
- const Standard_Integer iNode2);
-
- /**
- * Allocate a single polygon, should be called for each polygon following
- * the call SetPolygonsPrs(). The polygon can be filled by node indices using
- * the method SetPolygonNode().
- * @param ind
- * Index of the polygon, should be [0..Npolygons-1]
- * @param theSz
- * Number of points (segments) in the polygon.
- */
- Standard_EXPORT void SetPolygon (const Standard_Integer ind,
- const Standard_Integer theSz);
-
- /**
- * Define the line node by index.
- */
- Standard_EXPORT void SetLineNode(const Standard_Integer ind,
- const Standard_Integer iNode);
-
- /**
- * Query the number of nodes.
- */
- inline Standard_Integer NNodes () const
- { return myNNodes; }
-
- /**
- * Query the number of triangles.
- */
- inline Standard_Integer NTriangles() const
- { return myNTriangles; }
-
- /**
- * Query the number of line points.
- */
- inline Standard_Integer NLineNodes() const
- { return myNLineNodes; }
-
- /**
- * Query the number of polygons.
- */
- inline Standard_Integer NPolygons () const
- { return static_cast<Standard_Integer>(myNPolygons); }
-
- /**
- * Query the node by its index.
- * @return
- * pointer to array of 2 or 3 Standard_ShortReal values {X,Y(,Z) coord}
- */
- inline const Standard_ShortReal * Node (const Standard_Integer ind) const
- { return &mypNodes[ind * myNodeCoord]; }
-
- /**
- * Define the node of a polygon by index.
- * @param indPoly
- * Index of the Polygon, should be less than the number of polygons that is
- * defined in SetPolygonsPrs() and can be returned by NPOlygons().
- * @param ind
- * Index of the node in the Polygon. Should be less than the parameter theSz
- * in the corresponding previous SetPolygon() call.
- * @param iNode
- * Index of the node in the given position of the Polygon.
- */
- Standard_EXPORT void SetPolygonNode
- (const Standard_Integer indPoly,
- const Standard_Integer ind,
- const Standard_Integer iNode);
-
- /**
- * Get the node with index 'ind' from the polygon number 'indPoly'.
- */
- Standard_EXPORT Standard_Integer PolygonNode(const Standard_Integer indPoly,
- const Standard_Integer ind)const;
-
- /**
- * Get the number of nodes for the polygon number 'indPoly'.
- */
- Standard_EXPORT Standard_Integer NPolygonNodes
- (const Standard_Integer indPoly)const;
-
- /**
- * Set the boolean flag defining if the polygons or the triangulation
- * should be drawn. This method does not affect the presentation of
- * Line/Segments.
- * @param isDrawPolygons
- * True defines that no triangulation is drawn, only polygons are. False
- * defines that only triangulation is drawn, no polygons.
- */
- Standard_EXPORT void SetDrawPolygons
- (const Standard_Boolean isDrawPolygons);
- /**
- * Set the type of polygon rendering.
- */
- Standard_EXPORT void SetPolygonType
- (const PolygonType theType);
-
- /**
- * Set the normal color for presentation.
- * @param theColor
- * New color to use for the presentation.
- */
- Standard_EXPORT void SetColor (const Quantity_Color& theColor);
-
- /**
- * Get Normal, Transparent or Hilighted color of the presentation.
- * @param theDrawType
- * The draw type, for which the color is retrieved.
- */
- Standard_EXPORT Quantity_Color GetColor
- (const NIS_Drawer::DrawType theDrawType) const;
-
- /**
- * Set the color for hilighted presentation.
- * @param theColor
- * New color to use for the presentation.
- */
- Standard_EXPORT void SetHilightColor (const Quantity_Color& theColor);
-
- /**
- * Set the color for dynamic hilight presentation.
- * @param theColor
- * New color to use for the presentation.
- */
- Standard_EXPORT void SetDynHilightColor(const Quantity_Color& theColor);
-
- /**
- * Set the width of line presentations in pixels.
- * @param theWidth
- * New line width to use for the presentation.
- */
- Standard_EXPORT void SetLineWidth (const Standard_Real theWidth);
-
- /**
- * Create a copy of theObject except its ID.
- * @param theAll
- * Allocator where the Dest should store its private data.
- * @param theDest
- * <tt>[in-out]</tt> The target object where the data are copied. If
- * passed NULL then the target should be created.
- */
- Standard_EXPORT virtual void
- Clone (const Handle(NCollection_BaseAllocator)& theAll,
- Handle(NIS_InteractiveObject)& theDest) const;
-
- /**
- * Intersect the InteractiveObject geometry with a line/ray.
- * @param theAxis
- * The line or ray in 3D space.
- * @param theOver
- * Half-thickness of the selecting line.
- * @return
- * If the return value is more than 0.1*RealLast() then no intersection is
- * detected. Otherwise returns the coordinate of thePnt on the ray. May be
- * negative.
- */
- Standard_EXPORT virtual Standard_Real
- Intersect (const gp_Ax1& theAxis,
- const Standard_Real theOver) const;
-
- /**
- * Intersect the InteractiveObject geometry with an oriented box.
- * @param theBox
- * 3D box of selection
- * @param theTrf
- * Position/Orientation of the box.
- * @param isFull
- * True if full inclusion is required, False - if partial.
- * @return
- * True if the InteractiveObject geometry intersects the box or is inside it
- */
- Standard_EXPORT virtual Standard_Boolean
- Intersect (const Bnd_B3f& theBox,
- const gp_Trsf& theTrf,
- const Standard_Boolean isFull)const;
-
- /**
- * Intersect the InteractiveObject geometry with a selection polygon.
- * @param thePolygon
- * the list of vertices of a free-form closed polygon without
- * self-intersections. The last point should not coincide with the first
- * point of the list. Any two neighbor points should not be confused.
- * @param theTrf
- * Position/Orientation of the polygon.
- * @param isFullIn
- * True if full inclusion is required, False - if partial.
- * @return
- * True if the InteractiveObject geometry intersects the polygon or is
- * inside it
- */
- Standard_EXPORT virtual Standard_Boolean Intersect
- (const NCollection_List<gp_XY> &thePolygon,
- const gp_Trsf &theTrf,
- const Standard_Boolean isFullIn) const;
-
- Standard_EXPORT static int tri_line_intersect (const double start[3],
- const double dir[3],
- const float V0[3],
- const float V1[3],
- const float V2[3],
- double * tInter);
-
- Standard_EXPORT static int tri2d_line_intersect(const double start[3],
- const double dir[3],
- const float V0[2],
- const float V1[2],
- const float V2[2],
- double * tInter);
-
- Standard_EXPORT static int seg_line_intersect (const gp_XYZ& aStart,
- const gp_XYZ& aDir,
- const double over2,
- const float V0[3],
- const float V1[3],
- double * tInter);
-
- Standard_EXPORT static int seg2d_line_intersect(const gp_XYZ& aStart,
- const gp_XYZ& aDir,
- const double over2,
- const float V0[2],
- const float V1[2],
- double * tInter);
-
- Standard_EXPORT static int seg_box_intersect (const Bnd_B3f& theBox,
- const gp_Pnt thePnt[2]);
-
- Standard_EXPORT static int seg_box_included (const Bnd_B3f& theBox,
- const gp_Pnt thePnt[2]);
-
- Standard_EXPORT static int seg_polygon_intersect
- (const NCollection_List<gp_XY> &thePolygon,
- const gp_XY thePnt[2]);
-
- Standard_EXPORT static int seg_polygon_included
- (const NCollection_List<gp_XY> &thePolygon,
- const gp_XY thePnt[2]);
-
- Standard_EXPORT static void ComputeBox (Bnd_B3f& theBox,
- const Standard_Integer nNodes,
- const Standard_ShortReal* pNodes,
- const Standard_Integer nCoord);
-
- /**
- * Classification of thePoint with respect to thePolygon.
- * @param thePolygon
- * the list of vertices of a free-form closed polygon without
- * self-intersections. The last point should not coincide with the first
- * point of the list. Any two neighbor points should not be confused.
- * @param thePoint
- * the point to be classified.
- * @return
- * Standard_True if thePoint in inside thePolygon or lies on its boundary.
- */
- Standard_EXPORT static Standard_Boolean
- IsIn (const NCollection_List<gp_XY> &thePolygon,
- const gp_XY &thePoint);
-
- /**
- * Implements deallocation of the object instance
- */
- Standard_EXPORT virtual void Delete () const;
-
- protected:
-
- /**
- * Allocator-based operator new for dynamic allocations in method Clone()
- */
- DEFINE_STANDARD_ALLOC
- DEFINE_NCOLLECTION_ALLOC
-
- /**
- * Create a 3D bounding box of the object.
- */
- Standard_EXPORT virtual void computeBox ();
-
- /**
- * Create the memory buffer for the declared number of nodes, old nodes
- * are deallocated.
- */
- Standard_EXPORT void allocateNodes (const Standard_Integer nNodes);
-
- /**
- * Get the node pointed by the i-th index in the array.
- */
- Standard_EXPORT gp_Pnt nodeAtInd (const Standard_Integer * theArr,
- const Standard_Integer i) const;
-
- /**
- * Get the node pointed by the i-th index in the array.
- */
- Standard_EXPORT float* nodeArrAtInd (const Standard_Integer * theArr,
- const Standard_Integer i) const;
-
- protected:
- // ---------- PROTECTED FIELDS ----------
-
- NCollection_BaseAllocator * myAlloc; //!< Usually from InteractiveContext
- Standard_Integer myType; //!< Combination of Type_* constants
- Standard_ShortReal * mypNodes;
- Standard_Integer * mypTriangles;
- Standard_Integer * mypLines;
- Standard_Integer ** mypPolygons;
- Standard_Integer myNNodes;
- Standard_Integer myNTriangles;
- Standard_Integer myNLineNodes;
- unsigned int myNPolygons : 24;
- Standard_Boolean myIsDrawPolygons : 1;
- Standard_Boolean myIsCloned : 1; //!< How it is allocated
- unsigned int myIndexType : 2; //!< 0:8bit, 1:16bit, 2:32bit
- unsigned int myNodeCoord : 2; //!< 2 or 3 coordinates
- unsigned int myPolygonType : 2;
-
- public:
-// Declaration of CASCADE RTTI
-DEFINE_STANDARD_RTTI (NIS_Triangulated)
-
- friend class NIS_TriangulatedDrawer;
-};
-
-// Definition of HANDLE object using Standard_DefineHandle.hxx
-DEFINE_STANDARD_HANDLE (NIS_Triangulated, NIS_InteractiveObject)
-
-#endif
+++ /dev/null
-// Created on: 2007-07-19
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2007-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <NIS_TriangulatedDrawer.hxx>
-#include <NIS_InteractiveObject.hxx>
-#include <NIS_Triangulated.hxx>
-#include <Standard_ProgramError.hxx>
-
-#include <OpenGl_GlCore11.hxx>
-
-// Comment this line if you see no hilighting of triangulations due to negative
-// polygon offsets. Disabling this macro means that all offsets will be created
-// in the positive scale.
-
-// But before changing this macro please play with your OpenGL video card
-// settings in the direction of performance improvement. Particularly, I had a
-// good result after checking "Enable write combining" option in NVIDIA 6600.
-
-#define NEGATIVE_POFFSET
-
-IMPLEMENT_STANDARD_HANDLE (NIS_TriangulatedDrawer, NIS_Drawer)
-IMPLEMENT_STANDARD_RTTIEXT (NIS_TriangulatedDrawer, NIS_Drawer)
-
-//=======================================================================
-//function : NIS_TriangulatedDrawer()
-//purpose : Constructor
-//=======================================================================
-
-NIS_TriangulatedDrawer::NIS_TriangulatedDrawer
- (const Quantity_Color theNormal,
- const Quantity_Color theHilight,
- const Quantity_Color theDynHilight)
- : myPolygonAsLineLoop (Standard_False),
- myLineWidth (1.f),
- myIsDrawPolygons (Standard_False),
- myPolygonType (NIS_Triangulated::Polygon_Default)
-{
- myColor[Draw_Normal] = theNormal;
- myColor[Draw_Top] = theNormal;
- myColor[Draw_Transparent] = theNormal;
- myColor[Draw_Hilighted] = theHilight;
- myColor[Draw_DynHilighted] = theDynHilight;
-}
-
-//=======================================================================
-//function : Assign
-//purpose :
-//=======================================================================
-
-void NIS_TriangulatedDrawer::Assign (const Handle(NIS_Drawer)& theOther)
-{
- if (theOther.IsNull() == Standard_False) {
- NIS_Drawer::Assign (theOther);
- const Handle(NIS_TriangulatedDrawer)& anOther =
- static_cast <const Handle(NIS_TriangulatedDrawer)&> (theOther);
- myColor[Draw_Normal] = anOther->myColor[Draw_Normal];
- myColor[Draw_Top] = anOther->myColor[Draw_Top];
- myColor[Draw_Transparent] = anOther->myColor[Draw_Transparent];
- myColor[Draw_Hilighted] = anOther->myColor[Draw_Hilighted];
- myColor[Draw_DynHilighted] = anOther->myColor[Draw_DynHilighted];
- myLineWidth = anOther->myLineWidth;
- myIsDrawPolygons = anOther->myIsDrawPolygons;
- myPolygonType = anOther->myPolygonType;
- }
-}
-
-//=======================================================================
-//function : IsEqual
-//purpose : Comparison of two Drawers (for Map impementation)
-//=======================================================================
-
-Standard_Boolean NIS_TriangulatedDrawer::IsEqual
- (const Handle(NIS_Drawer)& theOther)const
-{
- static const Standard_Real anEpsilon2 (1e-7);
- Standard_Boolean aResult (Standard_False);
- const Handle(NIS_TriangulatedDrawer) anOther =
- Handle(NIS_TriangulatedDrawer)::DownCast (theOther);
- if (NIS_Drawer::IsEqual(theOther))
- aResult = (anOther->myColor[Draw_Normal]
- .SquareDistance (myColor[Draw_Normal]) < anEpsilon2 &&
- anOther->myColor[Draw_Hilighted]
- .SquareDistance (myColor[Draw_Hilighted]) < anEpsilon2 &&
- anOther->myColor[Draw_DynHilighted]
- .SquareDistance (myColor[Draw_DynHilighted]) < anEpsilon2 &&
- (anOther->myLineWidth - myLineWidth) *
- (anOther->myLineWidth - myLineWidth) < 0.01 &&
- anOther->myIsDrawPolygons == myIsDrawPolygons &&
- anOther->myPolygonType == myPolygonType);
- return aResult;
-}
-
-//=======================================================================
-//function : BeforeDraw
-//purpose :
-//=======================================================================
-
-void NIS_TriangulatedDrawer::BeforeDraw (const DrawType theType,
- const NIS_DrawList&)
-{
- Quantity_Parameter aValue[4];
- Quantity_TypeOfColor bidTC (Quantity_TOC_RGB);
- GLfloat aLineWidth (myLineWidth);
- Standard_Integer anOffsetHilighted = 0;
- switch (theType) {
- case Draw_DynHilighted:
- aLineWidth = myLineWidth + 1.f;
-#ifdef NEGATIVE_POFFSET
- anOffsetHilighted = -11;
-#endif
- case Draw_Hilighted:
- switch (myPolygonType) {
- default:
- case NIS_Triangulated::Polygon_Default:
- if (myIsDrawPolygons) {
- case NIS_Triangulated::Polygon_Line:
- glEnable(GL_POLYGON_OFFSET_LINE);
- } else {
- case NIS_Triangulated::Polygon_Fill:
- glEnable(GL_POLYGON_OFFSET_FILL);
- }
- }
- if (theType == Draw_Hilighted)
- {
-#ifdef NEGATIVE_POFFSET
- anOffsetHilighted = -10;
-#else
- anOffsetHilighted = 1;
-#endif
- }
- myColor[theType].Values (aValue[0], aValue[1], aValue[2], bidTC);
- glColor3d (aValue[0], aValue[1], aValue[2]);
- break;
- case Draw_Normal:
- case Draw_Top:
- case Draw_Transparent:
-#ifndef NEGATIVE_POFFSET
- anOffsetHilighted = 11;
-#endif
- myColor[theType].Values (aValue[0], aValue[1], aValue[2], bidTC);
- aValue[3] = 1. - myTransparency;
- if (myTransparency > 0.01) {
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- }
- glColor4d (aValue[0], aValue[1], aValue[2], aValue[3]);
- break;
- default:
- return;
- }
- if (anOffsetHilighted)
- glPolygonOffset(1.f, static_cast<GLfloat>(anOffsetHilighted));
-
-// myColor[theType].Values (aValue[0], aValue[1], aValue[2], bidTC);
-// glColor3d (aValue[0], aValue[1], aValue[2]);
- switch (myPolygonType) {
- default:
- case NIS_Triangulated::Polygon_Default:
- if (myIsDrawPolygons) {
- case NIS_Triangulated::Polygon_Line:
- glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
- } else {
- case NIS_Triangulated::Polygon_Fill:
- glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
- }
- }
- glEnableClientState (GL_VERTEX_ARRAY);
- glLineWidth (aLineWidth);
- glShadeModel(GL_FLAT);
- glDisable(GL_LIGHTING);
-}
-
-//=======================================================================
-//function : AfterDraw
-//purpose :
-//=======================================================================
-
-void NIS_TriangulatedDrawer::AfterDraw (const DrawType theType,
- const NIS_DrawList&)
-{
- switch (theType) {
- case Draw_Hilighted:
- case Draw_DynHilighted:
- switch (myPolygonType) {
- default:
- case NIS_Triangulated::Polygon_Default:
- if (myIsDrawPolygons) {
- case NIS_Triangulated::Polygon_Line:
- glDisable(GL_POLYGON_OFFSET_LINE);
- } else {
- case NIS_Triangulated::Polygon_Fill:
- glDisable(GL_POLYGON_OFFSET_FILL);
- }
- }
- case Draw_Normal:
- case Draw_Top:
- case Draw_Transparent:
- glDisableClientState(GL_VERTEX_ARRAY);
- if (myTransparency > 0.01)
- glDisable(GL_BLEND);
- default:;
- }
- if (myPolygonType == NIS_Triangulated::Polygon_Line ||
- (myPolygonType == NIS_Triangulated::Polygon_Default && myIsDrawPolygons))
- glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
-}
-
-//=======================================================================
-//function : Draw
-//purpose :
-//=======================================================================
-
-void NIS_TriangulatedDrawer::Draw (const Handle(NIS_InteractiveObject)& theObj,
- const DrawType /*theType*/,
- const NIS_DrawList&)
-{
- // Assertion for the type of the drawn object
- Standard_ProgramError_Raise_if (! theObj->IsKind(STANDARD_TYPE(NIS_Triangulated)),
- "NIS_Triangulated::Draw: irrelevant object type");
-
- const NIS_Triangulated * pObject =
- static_cast <const NIS_Triangulated *> (theObj.operator->());
- glVertexPointer (pObject->myNodeCoord, GL_FLOAT, 0, pObject->Node(0));
-
- GLenum aType = GL_UNSIGNED_INT;
- if (pObject->myIndexType == 0)
- aType = GL_UNSIGNED_BYTE;
- else if (pObject->myIndexType == 1)
- aType = GL_UNSIGNED_SHORT;
-
- if (myIsDrawPolygons == Standard_False) {
- if (pObject->IsTriangulation()) {
- glDrawElements (GL_TRIANGLES, pObject->NTriangles()*3,
- aType, pObject->mypTriangles);
- }
- } else {
- if (pObject->IsPolygons()) {
- GLenum aMode = GL_POLYGON;
- if (myPolygonAsLineLoop &&
- (myPolygonType == NIS_Triangulated::Polygon_Line ||
- (myPolygonType == NIS_Triangulated::Polygon_Default &&
- myIsDrawPolygons)))
- aMode = GL_LINE_LOOP;
- const Standard_Integer nPoly = pObject->NPolygons();
- for (Standard_Integer i = 0; i < nPoly; i++) {
- const Standard_Integer nSize = pObject->NPolygonNodes(i);
- void* anArray;
- if (pObject->myIndexType == 0)
- anArray = reinterpret_cast<unsigned char *>(pObject->mypPolygons[i]) + 1;
- else if (pObject->myIndexType == 1)
- anArray = reinterpret_cast<unsigned short *>(pObject->mypPolygons[i]) + 1;
- else
- anArray = pObject->mypPolygons[i] + 1;
- glDrawElements (aMode, nSize, aType, anArray);
- }
- }
- }
- if (pObject->IsSegments())
- glDrawElements (GL_LINES, pObject->NLineNodes(),
- aType, pObject->mypLines);
- else {
- Standard_Boolean isLoop;
- if (pObject->IsLine(isLoop))
- {
- if (isLoop) {
-// glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
- glDrawElements (GL_LINE_LOOP, pObject->NLineNodes(),
- aType, pObject->mypLines);
-// glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
- } else {
- glDrawElements (GL_LINE_STRIP, pObject->NLineNodes(),
- aType, pObject->mypLines);
- }
- }
- }
-
-}
-
+++ /dev/null
-// Created on: 2007-07-19
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2007-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#ifndef NIS_TriangulatedDrawer_HeaderFile
-#define NIS_TriangulatedDrawer_HeaderFile
-
-#include <NIS_Drawer.hxx>
-#include <Quantity_Color.hxx>
-
-class NIS_Triangulated;
-
-/**
- * Drawer for interactive object type NIS_Triangulated.
- */
-
-class NIS_TriangulatedDrawer : public NIS_Drawer
-{
- public:
- // ---------- PUBLIC METHODS ----------
-
- /**
- * Constructor.
- */
- Standard_EXPORT NIS_TriangulatedDrawer(const Quantity_Color theNormal,
- const Quantity_Color theHilight
- = Quantity_NOC_GRAY80,
- const Quantity_Color theDynHilight
- = Quantity_NOC_CYAN1);
-
- /**
- * Copy the relevant information from another instance of Drawer.
- * raises exception if theOther has incompatible type (test IsKind).
- */
- Standard_EXPORT virtual void Assign (const Handle(NIS_Drawer)& theOther);
-
- /**
- * Called before execution of Draw(), once per group of interactive objects.
- */
- Standard_EXPORT virtual void BeforeDraw(const DrawType theType,
- const NIS_DrawList& theDrawList);
-
- /**
- * Called after execution of Draw(), once per group of interactive objects.
- */
- Standard_EXPORT virtual void AfterDraw(const DrawType theType,
- const NIS_DrawList& theDrawList);
-
- /**
- * Main function: display the given interactive object in the given view.
- */
- Standard_EXPORT virtual void Draw (const Handle(NIS_InteractiveObject)&,
- const DrawType theType,
- const NIS_DrawList& theDrawList);
-
- /**
- * Matching two instances, for Map interface.
- */
- Standard_EXPORT virtual Standard_Boolean
- IsEqual (const Handle(NIS_Drawer)& theOth)const;
-
-protected:
- /**
- * If myPolygonAsLineLoop is true then draw polygons of the object
- * in the mode GL_LINE_LOOP instead of GL_POLYGON in the case if no filling
- * was requested. This will eliminate the bug with Intel integrated graphic
- * cards (e.g. 945G Express) for the sake of polygon offset functionality.
- */
- Standard_Boolean myPolygonAsLineLoop;
-
- Quantity_Color myColor[5];
- Standard_ShortReal myLineWidth;
- Standard_Boolean myIsDrawPolygons;
- unsigned int myPolygonType;
-
- friend class NIS_Triangulated;
-
- public:
-// Declaration of CASCADE RTTI
-DEFINE_STANDARD_RTTI (NIS_TriangulatedDrawer)
-};
-
-// Definition of HANDLE object using Standard_DefineHandle.hxx
-DEFINE_STANDARD_HANDLE (NIS_TriangulatedDrawer, NIS_Drawer)
-
-
-#endif
+++ /dev/null
-// Created on: 2007-07-06
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2007-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <NIS_View.hxx>
-#include <NIS_InteractiveContext.hxx>
-#include <NIS_InteractiveObject.hxx>
-#include <gp_Ax1.hxx>
-#include <Visual3d_View.hxx>
-#include <Bnd_B2f.hxx>
-#include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
-
-#include <OpenGl_GlCore11.hxx>
-
-IMPLEMENT_STANDARD_HANDLE (NIS_View, V3d_View)
-IMPLEMENT_STANDARD_RTTIEXT (NIS_View, V3d_View)
-
-//=======================================================================
-//function : NIS_View()
-//purpose : Constructor
-//=======================================================================
-
-NIS_View::NIS_View (const Handle(V3d_Viewer)& theViewer,
- const Handle(Aspect_Window)& theWindow)
- : V3d_View (theViewer),
- myIsTopHilight(Standard_False),
- myDoHilightSelected(Standard_True)
-{
- if (!theWindow.IsNull())
- V3d_View::SetWindow (theWindow, NULL, &MyCallback, this);
-}
-
-//=======================================================================
-//function : SetWindow
-//purpose :
-//=======================================================================
-
-void NIS_View::SetWindow(const Handle(Aspect_Window) &theWindow)
-{
- V3d_View::SetWindow (theWindow, NULL, &MyCallback, this);
-}
-
-// //=======================================================================
-// //function : ~NIS_View
-// //purpose : Destructor
-// //=======================================================================
-
-// NIS_View::~NIS_View()
-// {}
-
-
-//=======================================================================
-//function : AddContext
-//purpose :
-//=======================================================================
-
-void NIS_View::AddContext (NIS_InteractiveContext * theCtx)
-{
- // Check that the given context is not among already attached contexts
- NCollection_List<NIS_InteractiveContext *>::Iterator anIter (myContexts);
- for (; anIter.More(); anIter.Next())
- if (anIter.Value() == theCtx)
- break;
- if (anIter.More() == Standard_False)
- myContexts.Append (theCtx);
-}
-
-//=======================================================================
-//function : RemoveContext
-//purpose :
-//=======================================================================
-
-void NIS_View::RemoveContext (NIS_InteractiveContext * theCtx)
-{
- NCollection_List<NIS_InteractiveContext *>::Iterator anIter (myContexts);
- for (; anIter.More(); anIter.Next())
- if (anIter.Value() == theCtx) {
- myContexts.Remove (anIter);
- break;
- }
-
- NCollection_Map<Handle(NIS_Drawer)>::Iterator anIterD (theCtx->GetDrawers ());
- for (; anIterD.More(); anIterD.Next()) {
- const Handle(NIS_Drawer)& aDrawer = anIterD.Value();
- if (aDrawer.IsNull() == Standard_False) {
- aDrawer->UpdateExListId(this);
- }
- }
-}
-
-//=======================================================================
-//function : FitAll3d
-//purpose :
-//=======================================================================
-
-Standard_Boolean NIS_View::FitAll3d (const Quantity_Coefficient theCoef)
-{
- Bnd_B3f aB3fBox = GetBndBox();
-
- if (aB3fBox.IsVoid() || MyView->IsDefined() == Standard_False)
- {
- return Standard_False;
- }
-
- Bnd_Box aBox;
- aBox.Add (gp_Pnt (aB3fBox.CornerMin()));
- aBox.Add (gp_Pnt (aB3fBox.CornerMax()));
-
- if (!FitMinMax (myCamera, aBox, theCoef, 0.0, Standard_False))
- {
- return Standard_False;
- }
-
- View()->AutoZFit();
-
- ImmediateUpdate();
-
- return Standard_True;
-}
-
-//=======================================================================
-//function : GetBndBox
-//purpose :
-//=======================================================================
-
-Bnd_B3f NIS_View::GetBndBox() const
-{
- // Calculate the 3D bounding box of visible objects
- // in all interactive contexts
- Bnd_B3f aBox;
- NCollection_List<NIS_InteractiveContext *>::Iterator anIterC (myContexts);
- for (; anIterC.More(); anIterC.Next()) {
- NCollection_Map<Handle(NIS_Drawer)>::Iterator anIterD
- (anIterC.Value()->myDrawers);
- for (; anIterD.More(); anIterD.Next()) {
- const Handle(NIS_Drawer)& aDrawer = anIterD.Value();
- Bnd_B3f aBoxD = aDrawer->GetBox (this);
- aBox.Add (aBoxD);
- }
- }
-
- // Take the bounding box of AIS objects displayed in the view
- Bnd_Box aVal = View()->MinMaxValues();
- if (!aVal.IsVoid())
- {
- aBox.Add (aVal.CornerMin());
- aBox.Add (aVal.CornerMax());
- }
-
- return aBox;
-}
-
-//=======================================================================
-//function : GetBndBox
-//purpose :
-//=======================================================================
-
-void NIS_View::GetBndBox( Standard_Integer& theXMin, Standard_Integer& theXMax,
- Standard_Integer& theYMin, Standard_Integer& theYMax ) const
-{
- theXMin = theYMin = 0;
- theXMax = theYMax = -1;
-
- Bnd_B3f aBox = GetBndBox();
-
- // Check that the box is not empty
- if (aBox.IsVoid() == Standard_False) {
- // Convert the 3D box to 2D representation in pixel coordinates
- gp_XYZ aCoord;
- Standard_Integer anXp, anYp;
- const gp_XYZ aCorner[2] = { aBox.CornerMin(), aBox.CornerMax() };
- Standard_Integer aLimp[4] = { 1000000, -1000000, 1000000, -1000000 };
- for (Standard_Integer i = 0; i < 8; i++) {
- if (i & 0x1) aCoord.SetX (aCorner[0].X());
- else aCoord.SetX (aCorner[1].X());
- if (i & 0x2) aCoord.SetY (aCorner[0].Y());
- else aCoord.SetY (aCorner[1].Y());
- if (i & 0x4) aCoord.SetZ (aCorner[0].Z());
- else aCoord.SetZ (aCorner[1].Z());
- Convert( aCoord.X(), aCoord.Y(), aCoord.Z(), anXp, anYp );
- if (aLimp[0] > anXp) aLimp[0] = anXp;
- if (aLimp[1] < anXp) aLimp[1] = anXp;
- if (aLimp[2] > anYp) aLimp[2] = anYp;
- if (aLimp[3] < anYp) aLimp[3] = anYp;
- }
- if (aLimp[0] < aLimp[1] && aLimp[2] < aLimp[3])
- {
- // Scale the view
- // WindowFit (aLimp[0], aLimp[2], aLimp[1], aLimp[3]);
- theXMin = aLimp[0];
- theXMax = aLimp[1];
- theYMin = aLimp[2];
- theYMax = aLimp[3];
- }
- }
-}
-
-
-//=======================================================================
-//function : MyCallback
-//purpose :
-//=======================================================================
-
-int NIS_View::MyCallback (Aspect_Drawable /* Window ID */,
- void* ptrData,
- Aspect_GraphicCallbackStruct* callData /* call data */)
-{
- // Avoid multiple rendering of the scene ( accordingly with update of
- // callback mechanism, that invokes additional callbacks before
- // underlay and overlay redrawing with OCC_PRE_REDRAW and OCC_PRE_OVERLAY
- // bits added to the "reason" value of the callback data structure;
- // see comments to OCC_REDRAW_ADDITIONAL_CALLBACKS definition )
- if (callData->reason & OCC_REDRAW_ADDITIONAL_CALLBACKS)
- return 0;
-
- if (callData->IsCoreProfile)
- {
- return 0; // not supported
- }
-
- const Handle(NIS_View) thisView (static_cast<NIS_View *> (ptrData));
- NCollection_List<NIS_InteractiveContext *>::Iterator anIter;
-#ifdef CLIP
- // Find the bounding box of all displayed objects by summing the boxes stored
- // in the relevant DrawList instances.
- Bnd_B3f aBndBox;
- for (anIter = thisView->myContexts; anIter.More(); anIter.Next())
- anIter.Value()->GetBox (aBndBox, pView);
-
- if (aBndBox.IsVoid() == Standard_False) {
- const gp_XYZ aBoxSize = 0.5 * (aBndBox.CornerMax() - aBndBox.CornerMin());
- const gp_XYZ aBoxCenter = 0.5 * (aBndBox.CornerMax() + aBndBox.CornerMin());
-
- // Find the ray passing through the clicked point in the view window.
- Standard_Real anX, anY, aZ;
- thisView->Convert(0, 0, anX, anY, aZ); // 3D point for the 3D coordinates
- const gp_Pnt anEye (anX, anY, aZ);
- thisView->Proj (anX, anY, aZ); // vector orthogonal to the view plane
- const gp_Dir aProj (anX, anY, aZ);
- const gp_Ax1 anAxis (anEye, aProj);
-
- const Standard_Real aCenterDist = (anEye.XYZ() - aBoxCenter) * aProj.XYZ();
- const Standard_Real aBoxExtent /*(fabs(aBoxSize.X() * anX) +
- fabs(aBoxSize.Y() * anY) +
- fabs(aBoxSize.Z() * aZ))*/(100.);
-
-#define FRONT_CLIPPING_PLANE (GL_CLIP_PLANE0 + 0)
-#define BACK_CLIPPING_PLANE (GL_CLIP_PLANE0 + 1)
- Standard_Real arr[4] = {
- 0.0, /* Nx */
- 0.0, /* Ny */
- 1.0, /* Nz */
- 0.
- };
- arr[3] = aBoxExtent + 1.;
- glClipPlane (BACK_CLIPPING_PLANE, arr);
- glEnable (BACK_CLIPPING_PLANE);
- arr[2] = -1.0;
- arr[3] = aBoxExtent + 1.;
- glClipPlane (FRONT_CLIPPING_PLANE, arr);
- glEnable (FRONT_CLIPPING_PLANE);
- }
-#endif //IS_DISABLED
-
- GLboolean isDepthWriteMask, isDepthTest;
- glGetBooleanv(GL_DEPTH_WRITEMASK,&isDepthWriteMask);
- glGetBooleanv(GL_DEPTH_TEST,&isDepthTest);
-// printf ("GlDepthMask=%d; GlDepthTest=%d\n", depthwritemask, depthtest);
- glDisableClientState(GL_COLOR_ARRAY);
- glDisableClientState(GL_EDGE_FLAG_ARRAY);
- glDisableClientState(GL_INDEX_ARRAY);
- glDisableClientState(GL_NORMAL_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- if (!isDepthTest) {
- glEnable(GL_DEPTH_TEST);
- glDepthFunc(GL_LESS);
- glClearDepth(1.);
- glClear(GL_DEPTH_BUFFER_BIT);
- }
-
- TColStd_MapIteratorOfPackedMapOfInteger anIterM(thisView->myExListId);
- for (; anIterM.More(); anIterM.Next())
- if (anIterM.Key() != 0) {
-#ifdef ARRAY_LISTS
- glDeleteLists (anIterM.Key(), 5);
-#else
- glDeleteLists (anIterM.Key(), 1);
- }
-#endif
- thisView->myExListId.Clear();
-
- for (anIter = thisView->myContexts; anIter.More(); anIter.Next())
- anIter.Value()->redraw (thisView, NIS_Drawer::Draw_Normal);
-
- // #818151 - selected object is hidden by covered unselected one
- // display hilighted objects always above the rest ones
- if (thisView->myIsTopHilight == Standard_True) {
- glDepthFunc(GL_ALWAYS);
- }
-
- for (anIter = thisView->myContexts; anIter.More(); anIter.Next())
- anIter.Value()->redraw (thisView, NIS_Drawer::Draw_Hilighted);
- for (anIter = thisView->myContexts; anIter.More(); anIter.Next())
- anIter.Value()->redraw (thisView, NIS_Drawer::Draw_DynHilighted);
- for (anIter = thisView->myContexts; anIter.More(); anIter.Next())
- anIter.Value()->redraw (thisView, NIS_Drawer::Draw_Transparent);
-
- // draw top objects always above
- if (thisView->myIsTopHilight == Standard_False) {
- glDepthFunc(GL_ALWAYS);
- }
-
- for (anIter = thisView->myContexts; anIter.More(); anIter.Next())
- anIter.Value()->redraw (thisView, NIS_Drawer::Draw_Top);
-
- return 0;
-}
-
-//=======================================================================
-//function : DynamicHilight
-//purpose :
-//=======================================================================
-
-void NIS_View::DynamicHilight (const Standard_Integer theX,
- const Standard_Integer theY)
-{
- myDetected.Clear();
- const Handle(NIS_InteractiveObject) aSelected = Pick (theX, theY);
-
- // ASV: if at least one Context returns IsSelectable()==False,
- // hilight is canceled, this method returns
- if (aSelected.IsNull() == Standard_False) {
- if (aSelected->IsSelectable() == Standard_False)
- return;
- }
- if (aSelected != myDynHilighted) {
- const Handle(NIS_View) aView (this);
- if (myDynHilighted.IsNull() == Standard_False)
- if (myDynHilighted->GetDrawer().IsNull() == Standard_False)
- myDynHilighted->GetDrawer()->SetDynamicHilighted(Standard_False,
- myDynHilighted, aView);
-
- // 30.07.10 - NKV - synchronize behaviour with AIS interactive context (if need)
- if (aSelected.IsNull() ||
- (myDoHilightSelected == Standard_False &&
- aSelected->GetDrawer()->GetContext()->IsSelected(aSelected)))
- {
- myDynHilighted.Nullify();
- }
- else {
- aSelected->GetDrawer()->SetDynamicHilighted (Standard_True,
- aSelected, aView);
- myDynHilighted = aSelected;
- }
- Redraw();
- }
-}
-
-//=======================================================================
-//function : DynamicUnhilight
-//purpose :
-//=======================================================================
-
-void NIS_View::DynamicUnhilight(const Handle(NIS_InteractiveObject)& theObj)
-{
- if (theObj == myDynHilighted && theObj.IsNull() == Standard_False) {
- const Handle(NIS_View) aView (this);
- if (myDynHilighted->GetDrawer().IsNull() == Standard_False)
- myDynHilighted->GetDrawer()->SetDynamicHilighted (Standard_False,
- myDynHilighted, aView);
- myDynHilighted.Nullify();
- Redraw();
- }
-}
-
-//=======================================================================
-//function : Select
-//purpose : selection by single click
-//=======================================================================
-
-void NIS_View::Select (const Standard_Integer theX,
- const Standard_Integer theY,
- const Standard_Boolean isForceMultiple,
- const Standard_Boolean theRedraw)
-{
- myDetected.Clear();
- const Handle(NIS_InteractiveObject) aSelected = Pick (theX, theY);
- NCollection_List<NIS_InteractiveContext *>::Iterator anIter (myContexts);
- for (; anIter.More(); anIter.Next())
- anIter.Value()->ProcessSelection (aSelected, isForceMultiple);
- if (aSelected == myDynHilighted && aSelected.IsNull() == Standard_False)
- {
- myDynHilighted.Nullify();
- const Handle(NIS_Drawer)& aDrawer = aSelected->GetDrawer();
- aDrawer->SetDynamicHilighted (Standard_False, aSelected, this);
- }
- if (theRedraw) Redraw();
-}
-
-//=======================================================================
-//function : Select
-//purpose : selection by rectange
-//=======================================================================
-
-void NIS_View::Select (const Standard_Integer theXmin,
- const Standard_Integer theYmin,
- const Standard_Integer theXmax,
- const Standard_Integer theYmax,
- const Standard_Boolean isForceMult,
- const Standard_Boolean isFullyIncluded,
- const Standard_Boolean theRedraw)
-{
- myDetected.Clear();
- Standard_Real anX, anY, aZ;
- if (theXmin == theXmax || theYmin == theYmax)
- return;
-
- //Transformed box corresponding to the selected rectangle
- Proj (anX, anY, aZ); // vector orthogonal to the view plane
- const gp_Dir aProj (anX, anY, aZ);
-
- Convert(theXmin, theYmin, anX, anY, aZ); // 3D point for the 3D coordinates
- const gp_Pnt anEye (anX, anY, aZ);
-
- Convert(theXmax, theYmin, anX, anY, aZ); // 3D point for the 3D coordinates
- const gp_XYZ anXdir (gp_XYZ(anX, anY, aZ) - anEye.XYZ());
- const gp_Ax3 anAx3 (anEye, aProj, anXdir);
- gp_Trsf aTrf;
- aTrf.SetTransformation (anAx3);
- const gp_Trsf aTrfInv = aTrf.Inverted();
-
- Convert(theXmax, theYmax, anX, anY, aZ); // 3D point for the 3D coordinates
- gp_XYZ anUpperCorner (anX, anY, aZ);
- aTrf.Transforms(anUpperCorner);
-
- // Selecting box
- Bnd_B3f aBoxSel;
- aBoxSel.Add (gp_XYZ(0., 0., -10000.));
- aBoxSel.Add (anUpperCorner);
-
- TColStd_PackedMapOfInteger mapSelected;
- NCollection_List<NIS_InteractiveContext *>::Iterator anIterC (myContexts);
- for (; anIterC.More(); anIterC.Next()) {
- NIS_InteractiveContext * pCtx = anIterC.Value();
- mapSelected.Clear();
- pCtx->selectObjects (mapSelected, aBoxSel, aTrfInv, aTrf, isFullyIncluded);
- pCtx->ProcessSelection (mapSelected, isForceMult);
- }
- if (theRedraw) Redraw();
-}
-
-//=======================================================================
-//function : Select
-//purpose : Selection by polygon
-//=======================================================================
-
-void NIS_View::Select (const NCollection_List<gp_XY> &thePolygon,
- const Standard_Boolean isForceMult,
- const Standard_Boolean isFullyIncluded,
- const Standard_Boolean theRedraw)
-{
- myDetected.Clear();
- if (thePolygon.IsEmpty())
- return;
-
- Standard_Real anX, anY, aZ;
-
- //Transformed box corresponding to the selected rectangle
- Proj (anX, anY, aZ); // vector orthogonal to the view plane
- const gp_Dir aProj (anX, anY, aZ);
-
- const gp_XY &aPf = thePolygon.First();
- // 3D point for the 3D coordinates
- Convert((Standard_Integer) aPf.X(), (Standard_Integer) aPf.Y(), anX, anY, aZ);
- const gp_Pnt anEye (anX, anY, aZ);
-
- // 3D point for the 3D coordinates
- const gp_XY &aPl = thePolygon.Last();
-
- Convert((Standard_Integer) aPl.X(), (Standard_Integer) aPl.Y(), anX, anY, aZ);
-
- // Compute transformation.
- const gp_XYZ anXdir (gp_XYZ(anX, anY, aZ) - anEye.XYZ());
- if (anXdir.Modulus() <= gp::Resolution())
- {
- return;
- }
-
- const gp_Ax3 anAx3 (anEye, aProj, anXdir);
- gp_Trsf aTrf;
- aTrf.SetTransformation (anAx3);
-
- // Prepare list of 2d points of selection polygon.
- NCollection_List<gp_XY> aPoints;
- NCollection_List<gp_XY>::Iterator anIter(thePolygon);
- Bnd_B2f aPolyBox;
-
- for (; anIter.More(); anIter.Next()) {
- const gp_XY &aP = anIter.Value();
-
- Convert((Standard_Integer) aP.X(), (Standard_Integer) aP.Y(), anX, anY, aZ);
- gp_XYZ aP3d(anX, anY, aZ);
-
- aTrf.Transforms(aP3d);
-
- gp_XY aP2d(aP3d.X(), aP3d.Y());
-
- aPoints.Append(aP2d);
- aPolyBox.Add(aP2d);
- }
-
- TColStd_PackedMapOfInteger mapSelected;
- NCollection_List<NIS_InteractiveContext *>::Iterator anIterC(myContexts);
-
- for (; anIterC.More(); anIterC.Next()) {
- NIS_InteractiveContext * pCtx = anIterC.Value();
- mapSelected.Clear();
- pCtx->selectObjects (mapSelected, aPoints, aPolyBox, aTrf, isFullyIncluded);
- pCtx->ProcessSelection (mapSelected, isForceMult);
- }
-
- if (theRedraw) Redraw();
-}
-
-//=======================================================================
-//function : Pick
-//purpose :
-//=======================================================================
-
-Handle(NIS_InteractiveObject) NIS_View::Pick (const Standard_Integer theX,
- const Standard_Integer theY)
-{
- // Find the ray passing through the clicked point in the view window.
- Standard_Real anX, anY, aZ, anOver;
- Convert(theX, theY, anX, anY, aZ); // 3D point for the 3D coordinates
- const gp_Pnt anEye (anX, anY, aZ);
- Proj (anX, anY, aZ); // vector orthogonal to the view plane
- const gp_Dir aProj (-anX, -anY, -aZ);
- const gp_Ax1 anAxis (anEye, aProj);
-
- Convert (theX+1, theY+1, anX, anY, aZ);
- anOver = ((gp_XYZ(anX, anY, aZ) - anEye.XYZ()) ^ aProj.XYZ()).Modulus() * 1.5;
-
- return Pick(anAxis, anOver, Standard_True);
-}
-
-//=======================================================================
-//function : Pick
-//purpose :
-//=======================================================================
-
-Handle(NIS_InteractiveObject) NIS_View::Pick
- (const gp_Ax1& theAxis,
- const Standard_Real theOver,
- const Standard_Boolean isOnlySelectable)
-{
- typedef NCollection_List<NIS_InteractiveContext::DetectedEnt> LstDetected;
- Standard_Real aDistance (0.1 * RealLast());
- Handle(NIS_InteractiveObject) aSelected, aTmpSel;
- LstDetected aDetected;
-
- NCollection_List<NIS_InteractiveContext *>::Iterator anIterC (myContexts);
- for (; anIterC.More(); anIterC.Next()) {
- const Standard_Real aDist =
- anIterC.Value()->selectObject (aTmpSel, aDetected, theAxis, theOver,
- isOnlySelectable);
- if (aDist < aDistance) {
- aDistance = aDist;
- aSelected = aTmpSel;
- }
- }
-
- // simple iterating is enough to create list of detected objects
- // in the order of increasing distance
- myDetected.Clear();
- for (LstDetected::Iterator anIt(aDetected); anIt.More(); anIt.Next())
- myDetected.Append(anIt.Value().PObj);
-
- return aSelected;
-}
-
+++ /dev/null
-// Created on: 2007-07-06
-// Created by: Alexander GRIGORIEV
-// Copyright (c) 2007-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#ifndef NIS_View_HeaderFile
-#define NIS_View_HeaderFile
-
-#include <Handle_NIS_InteractiveObject.hxx>
-#include <V3d_View.hxx>
-#include <Standard_DefineHandle.hxx>
-#include <NCollection_List.hxx>
-#include <NCollection_Vector.hxx>
-#include <Bnd_B3f.hxx>
-#include <TColStd_PackedMapOfInteger.hxx>
-#include <gp_XY.hxx>
-
-class NIS_InteractiveContext;
-class gp_Ax1;
-
-/**
- * Manager of a single window with OpenGL context, used by one or more
- * NIS_InteractiveContext instances.
- * This class inherits V3d_View therefore its instances can be used
- * to display any object that is normally handled by Graphic3d/V3d/AIS classes.
- * Also the standard view operations: Pan, Rotate, Zoom, mouse API, etc. are
- * supported due to this inheritance.<p>
- * The new services added by this class is the visualisation of
- * NIS_InteractiveObject (i.e., accommodation of NIS_InteractiveContext
- * instances). This visualisation is done by the method MyCallback that is
- * called just before redrawing the scene by Graphic3d/OpenGl drivers.<p>
- * The View instance can be understood as a collector of several interactive
- * contexts that exist independently (do not interfere) though they output
- * into the same OpenGL context. The contexts are:
- * <ul>
- * <li>AIS_InteractiveContext associated with the view by means of V3d_Viewer
- * instance (the traditional AIS architecture);</li>
- * <li>1st associated NIS_InteractiveContext</li>
- * <li>2nd associated NIS_InteractiveContext</li>
- * <li>...</li>
- * </ul>
- * The list of associated NIS_InteractiveContext can be modified by methods
- * AddContext and RemoveContext.
- */
-
-class NIS_View : public V3d_View
-{
- public:
- // ---------- PUBLIC METHODS ----------
-
-
- /**
- * Attach the view to the window.
- */
- Standard_EXPORT NIS_View (const Handle(V3d_Viewer)& theViewer,
- const Handle(Aspect_Window)& theWindow = NULL);
-
- /**
- * Attach the view to the window.
- */
- Standard_EXPORT void SetWindow(const Handle(Aspect_Window) &theWindow);
-
- /**
- * Indicate whether to draw hilighted objects on top of all other ones
- */
- inline void SetHilightOnTop(const Standard_Boolean theTop = Standard_True)
- { myIsTopHilight = theTop; }
-
- /**
- * Indicate whether to hilight selected object dynamically
- * By default dynamic hilight works on all objects independently on its
- * selected/non-selected state.
- * This behaviour differs from the behaviour of AIS interactive context,
- * that doesn't hilight dynamically (on mouse movements) selected objects.
- * In the case both context are used in the same view the behaviour of both
- * context can be made consistent by setting this flag to False
- */
- inline void SetDynHilightSelected (const Standard_Boolean
- theHilight = Standard_True)
- { myDoHilightSelected = theHilight; }
-
- /**
- * Zoom the view to fit to visible objects size and positions.
- * @param theCoef
- * Relative margin in both X and Y dimensions. For example, value 1.0
- * will fit to twice the actual size.
- * @return
- * True if operation performed, False if failed (most likely because of
- * very big actual scale)
- */
- Standard_EXPORT Standard_Boolean FitAll3d (const Quantity_Coefficient theCoef
- = 0.01);
-
- /**
- * Gets bounding box covering objects displayed in viewer.
- */
- Standard_EXPORT Bnd_B3f GetBndBox() const;
-
- /**
- * Gets bounding box covering objects displayed in viewer.
- * If operation is fails when Xmax < Xmin abd Ymax < Ymin
- */
- Standard_EXPORT void GetBndBox(Standard_Integer& theXMin,
- Standard_Integer& theXMax,
- Standard_Integer& theYMin,
- Standard_Integer& theYMax ) const;
-
-// /**
-// * Destructor.
-// */
-// Standard_EXPORT virtual ~NIS_View ();
-
- /**
- * Set or unset the dynamically hilighted object, depending on the
- * given mouse coordinates.
- */
- Standard_EXPORT void DynamicHilight (const Standard_Integer theX,
- const Standard_Integer theY);
-
- /**
- * Unhilights the hilighted object if it coincides with the given
- * object instance.
- */
- Standard_EXPORT void DynamicUnhilight(const Handle(NIS_InteractiveObject)&);
-
- /**
- * Unhilights the currently hilighted object.
- */
- inline void DynamicUnhilight() { DynamicUnhilight(myDynHilighted); }
-
- /**
- * Set or unset the selected (hilighted) state of the object that is under
- * the coordinates theX, theY.
- * @param theX
- * X coordinate of the view window
- * @param theY
- * X coordinate of the view window
- * @param isForceMult
- * True if the effect of multi-Selection should be forced (e.g., when Shift
- * is pressed).
- * @param theRedraw
- * True to redraw view automatically (default value).
- */
- Standard_EXPORT void Select (const Standard_Integer theX,
- const Standard_Integer theY,
- const Standard_Boolean isForceMult
- = Standard_False,
- const Standard_Boolean theRedraw
- = Standard_True);
-
- /**
- * Set or unset the selected (hilighted) state of the objects that are
- * intersected by 2D box in the view
- * @param theXmin
- * left X coordinate of the view window
- * @param theYmin
- * lower Y coordinate of the view window
- * @param theXmax
- * right X coordinate of the view window
- * @param theYmax
- * upper Y coordinate of the view window
- * @param isForceMult
- * True if the effect of multi-Selection should be forced (e.g., when Shift
- * is pressed).
- * @param isFullyIncluded
- * True if only those objects are processed that are fully inside the
- * selection rectangle. False if objects fully or partially included in
- * the rectangle are processed.
- * @param theRedraw
- * True to redraw view automatically (default value).
- */
- Standard_EXPORT void Select (const Standard_Integer theXmin,
- const Standard_Integer theYmin,
- const Standard_Integer theXmax,
- const Standard_Integer theYmax,
- const Standard_Boolean isForceMult
- = Standard_False,
- const Standard_Boolean isFullyIncluded
- = Standard_False,
- const Standard_Boolean theRedraw
- = Standard_True);
-
- /**
- * Set or unset the selected (hilighted) state of the objects that are
- * intersected by 2D polygon in the view
- * @param thePolygon
- * defines the vertices of a free-form closed polygon without
- * self-intersections. The last point should not coincide with the first
- * point of the list. Points are interpreted as X and Y integer coordinates
- * of the view window. Any two neighbor points should not be confused.
- * @param isForceMult
- * True if the effect of multi-Selection should be forced (e.g., when Shift
- * is pressed).
- * @param isFullyIncluded
- * True if only those objects are processed that are fully inside the
- * selection rectangle. False if objects fully or partially included in
- * the rectangle are processed.
- * @param theRedraw
- * True to redraw view automatically (default value).
- */
- Standard_EXPORT void Select (const NCollection_List<gp_XY> &thePolygon,
- const Standard_Boolean isForceMult
- = Standard_False,
- const Standard_Boolean isFullyIncluded
- = Standard_False,
- const Standard_Boolean theRedraw
- = Standard_True);
-
- /**
- * Interactive selection by mouse click. Selection itself is performed in each
- * Interactive Context attached to this View, accordingto the local parameters
- * (mode, filter) of selection in each context.
- * @param theX
- * X coordinate of mouse pointer in the window.
- * @param theY
- * Y coordinate of mouse pointer in the window.
- * @return
- * the selected object picked by the minimal intersection distance among
- * all contexts attached to this View.
- */
- Standard_EXPORT Handle(NIS_InteractiveObject)
- Pick (const Standard_Integer theX,
- const Standard_Integer theY);
-
- /**
- * Interactive selection by mouse click. Selection itself is performed in each
- * Interactive Context attached to this View, accordingto the local parameters
- * (mode, filter) of selection in each context.
- * @param theAxis
- * 3D axis for objects selection
- * @param theOver
- * Overlap for the selecting axis
- * @param isOnlySel
- * If False, any displayed object can be picked, otherwise only selectable
- * ones.
- * @return
- * the selected object picked by the minimal intersection distance among
- * all contexts attached to this View.
- */
- Standard_EXPORT Handle(NIS_InteractiveObject)
- Pick (const gp_Ax1& theAxis,
- const Standard_Real theOver,
- const Standard_Boolean isOnlySel);
-
- /**
- * Gets all objects detected by last call of Pick() method
- */
- inline NCollection_Vector<NIS_InteractiveObject *> GetDetected() const
- { return myDetected; }
-
- /**
- * Obtain the IDs of ex-lists.
- */
- inline TColStd_PackedMapOfInteger& GetExListId ()
- { return myExListId; }
-
- protected:
- // ---------- PROTECTED METHODS ----------
-
- static int MyCallback (Aspect_Drawable /* Window ID */,
- void* /* user data */,
- Aspect_GraphicCallbackStruct* /* call data */);
-
- /**
- * Register an interactive context for this view.
- */
- Standard_EXPORT void AddContext (NIS_InteractiveContext *);
-
- /**
- * Detach an interactive context from this view.
- */
- Standard_EXPORT void RemoveContext (NIS_InteractiveContext *);
-
- private:
- // ---------- PRIVATE FIELDS ----------
-
- NCollection_List<NIS_InteractiveContext *> myContexts;
- Handle(NIS_InteractiveObject) myDynHilighted;
- Standard_Boolean myIsTopHilight : 1;
- Standard_Boolean myDoHilightSelected : 1;
- NCollection_Vector<NIS_InteractiveObject *> myDetected;
- TColStd_PackedMapOfInteger myExListId;
-
- friend class NIS_InteractiveContext;
-
- public:
-// Declaration of CASCADE RTTI
-DEFINE_STANDARD_RTTI (NIS_View)
-};
-
-// Definition of HANDLE object using Standard_DefineHandle.hxx
-//DEFINE_STANDARD_HANDLE (NIS_View, V3d_OrthographicView)
-
-#include <Handle_NIS_View.hxx>
-
-#endif
TKV3d \
TKOpenGl \
TKMeshVS \
- TKNIS \