0030520: VIS - IVtkTools_ShapePicker::GetPickPosition() returns incorrect point
[occt.git] / src / IVtkOCC / IVtkOCC_Shape.cxx
CommitLineData
913a4c4a 1// Created on: 2011-10-14
2// Created by: Roman KOZLOV
3// Copyright (c) 2011-2014 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#include <IVtkOCC_Shape.hxx>
17#include <TopExp.hxx>
18
92efcf78 19IMPLEMENT_STANDARD_RTTIEXT(IVtkOCC_Shape,IVtk_IShape)
20
913a4c4a 21// Handle implementation
ec357c5c 22
913a4c4a 23
24//============================================================================
25// Method: Constructor
26// Purpose:
27//============================================================================
28IVtkOCC_Shape::IVtkOCC_Shape (const TopoDS_Shape& theShape)
29: myTopoDSShape (theShape)
30{
31 buildSubShapeIdMap();
32}
33
34//============================================================================
35// Method: Destructor
36// Purpose:
37//============================================================================
38IVtkOCC_Shape::~IVtkOCC_Shape() { }
39
40//============================================================================
41// Method: getSubShapeId
42// Purpose: Returns unique ID of the given sub-shape within the top-level shape.
43//============================================================================
44IVtk_IdType IVtkOCC_Shape::GetSubShapeId (const TopoDS_Shape& theSubShape) const
45{
46 Standard_Integer anIndex = theSubShape.IsSame (myTopoDSShape) ?
47 -1 :
48 mySubShapeIds.FindIndex (theSubShape);
49
50 if (!anIndex) // Not found in the map
51 {
52 anIndex = -1;
53 }
54
55 return (IVtk_IdType)anIndex;
56}
57
58//============================================================================
59// Method: getSubIds
60// Purpose: Get ids of sub-shapes composing a sub-shape with the given id.
61//============================================================================
62IVtk_ShapeIdList IVtkOCC_Shape::GetSubIds (const IVtk_IdType theId) const
63{
64 IVtk_ShapeIdList aRes;
65 // Get the sub-shape by the given id.
50f32555 66 TopoDS_Shape aShape = mySubShapeIds.FindKey ((Standard_Integer) theId);
913a4c4a 67 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
68 if (aShapeType == TopAbs_VERTEX || aShapeType == TopAbs_EDGE ||
69 aShapeType == TopAbs_FACE)
70 {
71 // If it is vertex, edge or face return just the input id.
72 aRes.Append (theId);
73 }
74 else
75 {
76 // Find all composing vertices, edges and faces of the the found sub-shape
77 // and append their ids to the result.
78 TopTools_IndexedMapOfShape aSubShapes;
79 if (aShape.IsSame (myTopoDSShape))
80 {
81 aSubShapes = mySubShapeIds;
82 }
83 else
84 {
85 TopExp::MapShapes (aShape, aSubShapes);
86 }
87
88 for (int anIt = 1; anIt <= aSubShapes.Extent(); anIt++)
89 {
90 aShape = aSubShapes.FindKey (anIt);
91 aShapeType = aShape.ShapeType();
92 if (aShapeType == TopAbs_VERTEX || aShapeType == TopAbs_EDGE ||
93 aShapeType == TopAbs_FACE)
94 {
95 // If it is vertex, edge or face add its id to the result.
96 aRes.Append (mySubShapeIds.FindIndex (aShape));
97 }
98 }
99 }
100
101 return aRes;
102}
103
104//============================================================================
105// Method: GetSubShape
106// Purpose:
107//============================================================================
108const TopoDS_Shape& IVtkOCC_Shape::GetSubShape (const IVtk_IdType theId) const
109{
50f32555 110 return mySubShapeIds.FindKey ((Standard_Integer) theId);
913a4c4a 111}
112
113//============================================================================
114// Method: buildShapeIdMap
115// Purpose: Private method, assigns IDs to all sub-shapes of the top-level shape.
116//============================================================================
117void IVtkOCC_Shape::buildSubShapeIdMap()
118{
119 mySubShapeIds.Clear();
120 TopExp::MapShapes (myTopoDSShape, mySubShapeIds);
121}