1 // Copyright (c) 2012-2015  GeometryFactory Sarl (France)
2 // All rights reserved.
3 //
4 // This file is part of CGAL (www.cgal.org).
5 //
6 // $URL: https://github.com/CGAL/cgal/blob/v5.3/Three/include/CGAL/Three/Scene_interface.h $
7 // $Id: Scene_interface.h 7bfa33f 2021-06-04T14:01:47+02:00 albert-github
8 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
9 //
10 //
11 // Author(s)     : Laurent RINEAU
12 
13 //! \file Scene_interface.h
14 
15 
16 #ifndef SCENE_INTERFACE_H
17 #define SCENE_INTERFACE_H
18 #include <CGAL/license/Three.h>
19 /*!
20 * \ingroup PkgThreeRef
21 * The RenderingMode determines which of an item's primitives must be drawn.
22 * It can be Points, PointsPlusNormals, Wireframe, Flat, FlatPlusEdges, or Gouraud.
23 * - Points, PointsPlusNormals, and Wireframe have no light model.
24 * - Flat and FlatPlusEdges use a basic light model with one normal per facet.
25 * - Gouraud uses the same light model but with one normal per vertex.
26 */
27 enum RenderingMode
28 {
29   Points = 0,           //!< Renders only points without lighting.
30   PointsPlusNormals,    //!< Renders points and normals.
31   Wireframe,            //!< Renders only edges.
32   Flat,                 //!< Renders only faces, with a lighting per face.
33   FlatPlusEdges,        //!< Renders flat faces and edges.
34   Gouraud,              //!< Renders only faces, with a lighting per vertex.
35   GouraudPlusEdges,     //!< Renders faces with a lighting per vertex, and edges.
36   ShadedPoints,         //!< Renders only points with lighting.
37   NumberOfRenderingMode //!< Number of values in this enum.
38 };
39 
40 
41 #include <QString>
42 #include <QColor>
43 #include <QList>
44 #include <algorithm>
45 #include <cmath>
46 #include <CGAL/Bbox_3.h>
47 namespace CGAL{
48 namespace Three{
49 class Scene_item;
50 class Scene_group_item;
51 }
52 }
53 
54 namespace CGAL {
55 namespace Three{
56 /*!
57  * This is the class given to the plugins to interact with the scene.
58  * */
59 class Scene_interface {
60 public:
61 
62   //!A bounding box is a box with each face corresponding to an extremum of its contents.
63 
64   typedef CGAL::Bbox_3 Bbox;
65 
66   //!\brief Integer used as the index of a Scene_item.
67   //! An item's index is its position in the Geometric Objects list.
68   typedef int Item_id;
~Scene_interface()69   virtual ~Scene_interface() {};
70   //!Adds an item to the Geometric Objects list.
71   //!@returns the index of the new item.
72   virtual Item_id addItem(CGAL::Three::Scene_item* item) = 0;
73   //!Adds a CGAL::Three::Scene_item* to the list of children.
74   virtual void addChild(Scene_item* item)=0;
75   //! \brief replaces an item by a new one in the scene.
76   //! The item which id is `id` is replaced by `item`.
77   //! The first one is deleted and gives its index to the second one.
78   //! If emit_item_about_to_be_destroyed is true, emits
79   //! an itemAboutToBeDestroyed signal.
80   //!@returns a pointer to the old item.
81   virtual Scene_item* replaceItem(Item_id id, CGAL::Three::Scene_item* item, bool emit_item_about_to_be_destroyed = false) = 0;
82   //!Moves item to the targeted group.
83   virtual void changeGroup(CGAL::Three::Scene_item* item, CGAL::Three::Scene_group_item* target_group) = 0;
84 
85   /*! Erases an item in the list.
86    * @returns the index of the item just before the one that is erased,
87    * or just after.
88    * @returns -1 if the list is empty.*/
89   virtual Item_id erase(Item_id) = 0;
90   /*! Deletes the items with the target indices.
91    * @returns the index of the polyhedron just before the
92    * one that is erased, or just after. Returns -1 if
93    * the list is empty.
94    */
95   virtual int erase(QList<int>) = 0;
96 
97   /*! Creates a copy of the item whith the id `id`.
98    * @returns the index of the new item (-1 on error).
99    */
100     virtual Item_id duplicate(Item_id id) = 0;
101 
102   // Accessors (getters)
103   //! \brief The number of items
104   //!@returns the number of items in the scene.
105   virtual int numberOfEntries() const = 0;
106   //!\brief The `id`th item.
107   //! @returns the item with the specified index.
108   virtual CGAL::Three::Scene_item* item(Item_id id) const = 0;
109   //!\brief The id of `item`
110   //! @returns the id of the specified item.
111   virtual Item_id item_id(CGAL::Three::Scene_item* item) const = 0;
112   //!\brief The currently selected item's index.
113   //!@returns the currently selected item's index.
114   //!@returns -1 if none or several items are selected
115   virtual Item_id mainSelectionIndex() const = 0;
116   //!The id of the currently selected item.
117   //!@returns the list of currently selected items indices.
118   virtual QList<Item_id> selectionIndices() const = 0;
119   //!Item_A is designated with the column A/B in the Geometric Objetcts widget.
120   //!@returns the index of the Item_A
121   virtual Item_id selectionAindex() const = 0;
122   //!Item_B is designated with the column A/B in the Geometric Objetcts widget.
123   //!@returns the index of the Item_B
124   virtual Item_id selectionBindex() const = 0;
125 
126   //!\brief The scene's Bbox
127   //!@returns the scene's bounding box
128   //! @see Scene_interface::Bbox
129   virtual Bbox bbox() const = 0;
130   //!The length of the diagonal of the scene's Bbox
131   //!@returns the length of the bounding box's diagonal.
132   virtual double len_diagonal() const = 0;
133 
134 public:
135   //! Updates the information about the `i`th item in the
136   //! Geometric Objects list and redraws the scene.
137   virtual void itemChanged(Item_id i) = 0;
138   //! Updates the information about `item` in the
139   //! Geometric Objects list and redraws the scene.
140   virtual void itemChanged(CGAL::Three::Scene_item* item) = 0;
141   //! Re computes the scene Bbox without recentering it.
142   virtual void itemVisibilityChanged(CGAL::Three::Scene_item*) = 0;
143   //! Clears the current selection then sets the selected item to the target index.
144   //! Used to update the selection in the Geometric Objects view.
145   virtual void setSelectedItem(Item_id) = 0;
146   //! \brief ignore data updating.
147   //!
148   //! This will ignore all the individual calls to `itemChanged()` until
149   //! `setUpdatesEnabled()` is called whith `b` being `true`.
150   //!
151   virtual void setUpdatesEnabled(bool b) =0;
152   //!
153   //! \brief updates all the items in the SceneView.
154   //!
155   virtual void allItemsChanged() = 0;
156 }; // end interface Scene_interface
157 }
158 }
159 
160 
161 #endif // SCENE_INTERFACE_H
162