Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-05 09:21:08

0001 // Created on: 2015-11-23
0002 // Created by: Anastasia BORISOVA
0003 // Copyright (c) 2015 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _AIS_RubberBand_HeaderFile
0017 #define _AIS_RubberBand_HeaderFile
0018 
0019 #include <AIS_InteractiveObject.hxx>
0020 #include <Graphic3d_ArrayOfPolylines.hxx>
0021 #include <Graphic3d_ArrayOfTriangles.hxx>
0022 #include <NCollection_Vec2.hxx>
0023 #include <Standard_TypeDef.hxx>
0024 #include <NCollection_Sequence.hxx>
0025 
0026 //! Presentation for drawing rubber band selection.
0027 //! It supports rectangle and polygonal selection.
0028 //! It is constructed in 2d overlay.
0029 //! Default configuration is built without filling.
0030 //! For rectangle selection use SetRectangle() method.
0031 //! For polygonal selection use AddPoint() and GetPoints() methods.
0032 class AIS_RubberBand : public AIS_InteractiveObject
0033 {
0034 public:
0035   DEFINE_STANDARD_RTTIEXT(AIS_RubberBand, AIS_InteractiveObject)
0036 
0037   //! Constructs rubber band with default configuration: empty filling and white solid lines.
0038   //! @warning It binds this object with Graphic3d_ZLayerId_TopOSD layer.
0039   Standard_EXPORT AIS_RubberBand();
0040 
0041   //! Constructs the rubber band with empty filling and defined line style.
0042   //! @param[in] theLineColor  color of rubber band lines
0043   //! @param[in] theType  type of rubber band lines
0044   //! @param[in] theLineWidth  width of rubber band line. By default it is 1.
0045   //! @warning It binds this object with Graphic3d_ZLayerId_TopOSD layer.
0046   Standard_EXPORT AIS_RubberBand(const Quantity_Color&   theLineColor,
0047                                  const Aspect_TypeOfLine theType,
0048                                  const double            theLineWidth       = 1.0,
0049                                  const bool              theIsPolygonClosed = true);
0050 
0051   //! Constructs the rubber band with defined filling and line parameters.
0052   //! @param[in] theLineColor  color of rubber band lines
0053   //! @param[in] theType  type of rubber band lines
0054   //! @param[in] theFillColor  color of rubber band filling
0055   //! @param[in] theTransparency  transparency of the filling. 0 is for opaque filling. By default
0056   //! it is transparent.
0057   //! @param[in] theLineWidth  width of rubber band line. By default it is 1.
0058   //! @warning It binds this object with Graphic3d_ZLayerId_TopOSD layer.
0059   Standard_EXPORT AIS_RubberBand(const Quantity_Color&   theLineColor,
0060                                  const Aspect_TypeOfLine theType,
0061                                  const Quantity_Color    theFillColor,
0062                                  const double            theTransparency    = 1.0,
0063                                  const double            theLineWidth       = 1.0,
0064                                  const bool              theIsPolygonClosed = true);
0065 
0066   Standard_EXPORT ~AIS_RubberBand() override;
0067 
0068   //! Sets rectangle bounds.
0069   Standard_EXPORT void SetRectangle(const int theMinX,
0070                                     const int theMinY,
0071                                     const int theMaxX,
0072                                     const int theMaxY);
0073 
0074   //! Adds last point to the list of points. They are used to build polygon for rubber band.
0075   //! @sa RemoveLastPoint(), GetPoints()
0076   Standard_EXPORT void AddPoint(const NCollection_Vec2<int>& thePoint);
0077 
0078   //! Remove last point from the list of points for the rubber band polygon.
0079   //! @sa AddPoint(), GetPoints()
0080   Standard_EXPORT void RemoveLastPoint();
0081 
0082   //! @return points for the rubber band polygon.
0083   Standard_EXPORT const NCollection_Sequence<NCollection_Vec2<int>>& Points() const;
0084 
0085   //! Remove all points for the rubber band polygon.
0086   void ClearPoints() { myPoints.Clear(); }
0087 
0088   //! @return the Color attributes.
0089   Standard_EXPORT Quantity_Color LineColor() const;
0090 
0091   //! Sets color of lines for rubber band presentation.
0092   Standard_EXPORT void SetLineColor(const Quantity_Color& theColor);
0093 
0094   //! @return the color of rubber band filling.
0095   Standard_EXPORT Quantity_Color FillColor() const;
0096 
0097   //! Sets color of rubber band filling.
0098   Standard_EXPORT void SetFillColor(const Quantity_Color& theColor);
0099 
0100   //! Sets width of line for rubber band presentation.
0101   Standard_EXPORT void SetLineWidth(const double theWidth) const;
0102 
0103   //! @return width of lines.
0104   Standard_EXPORT double LineWidth() const;
0105 
0106   //! Sets type of line for rubber band presentation.
0107   Standard_EXPORT void SetLineType(const Aspect_TypeOfLine theType);
0108 
0109   //! @return type of lines.
0110   Standard_EXPORT Aspect_TypeOfLine LineType() const;
0111 
0112   //! Sets fill transparency.
0113   //! @param[in] theValue  the transparency value. 1.0 is for transparent background
0114   Standard_EXPORT void SetFillTransparency(const double theValue) const;
0115 
0116   //! @return fill transparency.
0117   Standard_EXPORT double FillTransparency() const;
0118 
0119   //! Enable or disable filling of rubber band.
0120   Standard_EXPORT void SetFilling(const bool theIsFilling);
0121 
0122   //! Enable filling of rubber band with defined parameters.
0123   //! @param[in] theColor  color of filling
0124   //! @param[in] theTransparency  transparency of the filling. 0 is for opaque filling.
0125   Standard_EXPORT void SetFilling(const Quantity_Color theColor, const double theTransparency);
0126 
0127   //! @return true if filling of rubber band is enabled.
0128   Standard_EXPORT bool IsFilling() const;
0129 
0130   //! @return true if automatic closing of rubber band is enabled.
0131   Standard_EXPORT bool IsPolygonClosed() const;
0132 
0133   //! Automatically create an additional line connecting the first and
0134   //! the last screen points to close the boundary polyline
0135   Standard_EXPORT void SetPolygonClosed(bool theIsPolygonClosed);
0136 
0137 protected:
0138   //! Returns true if the interactive object accepts the display mode.
0139   bool AcceptDisplayMode(const int theMode) const override { return theMode == 0; }
0140 
0141   //! Computes presentation of rubber band.
0142   Standard_EXPORT void Compute(const occ::handle<PrsMgr_PresentationManager>& thePrsMgr,
0143                                const occ::handle<Prs3d_Presentation>&         thePrs,
0144                                const int                                      theMode) override;
0145 
0146   //! Does not fill selection primitives for rubber band.
0147   void ComputeSelection(const occ::handle<SelectMgr_Selection>& /*aSelection*/,
0148                         const int /*aMode*/) override {};
0149 
0150   //! Fills triangles primitive array for rubber band filling.
0151   //! It uses Delaunay triangulation.
0152   //! @return true if array of triangles is successfully filled.
0153   Standard_EXPORT bool fillTriangles();
0154 
0155 protected:
0156   NCollection_Sequence<NCollection_Vec2<int>> myPoints; //!< Array of screen points
0157 
0158   occ::handle<Graphic3d_ArrayOfTriangles> myTriangles; //!< Triangles for rubber band filling
0159   occ::handle<Graphic3d_ArrayOfPolylines> myBorders;   //!< Polylines for rubber band borders
0160 
0161   bool myIsPolygonClosed; //!< automatic closing of rubber-band flag
0162 };
0163 #endif