/** ** ** @RDE_HEADER@ ** Definition of base class for rubberbands ** $Id$ ** $HeadURL$ ** $Author$ ** ** ----------------------------------------------------------------------------------------------- ** ** Hardware-Environment: Intel-PC ** Software-Environment: Windows 7, Qt 5.4. ArcGIS 10.2.5 ** ** Language ........: C++ 11 ** ** ----------------------------------------------------------------------------------------------- ** ** Author ...........: Jörg Turla, SPD G, Tel. 3132 ** ** ----------------------------------------------------------------------------------------------- ** ** Notes .........: ** ** 27.03.2015, JT : First edition for use with Qt5 ** ** ----------------------------------------------------------------------------------------------- */ #pragma once #include "event_dispatcher.h" #include "event_delegater.h" #include "rubberband_base.h" #include "rubberband.h" #include "rubberband_arrow.h" #include "rubberband_corridor.h" #include "rubberband_ellipse.h" #include "rubberband_free_hand.h" #include "rubberband_multi_point_feature.h" #include "rubberband_multi_ellipse_feature.h" #include "rubberband_point_cluster.h" #include "rubberband_point_feature.h" #include "rubberband_polyline_width.h" #include "rubberband_rectangle.h" #include "rubberband_smooth_line.h" #include "rubberband_state_select.h" #include "rubberband_transform.h" #include "rubberband_transform_move.h" #include "rubberband_transform_rotate.h" #include "rubberband_transform_scale.h" #include "rubberband_3d.h" #include "rubberband_point_feature_3d.h" #include "rubberband_multi_point_feature_3d.h" #include #include #include namespace SituationMap { namespace RB { /** @brief Factory class to create rubberbands Rubberbands are used to create or modifiy 2D geometries like lines, circles, polygons etc. on a 2D map view Rubberbands are used to create or modifiy 2D geometries like lines, circles, polygons etc. by processing Qt input events like keyboard and mouse events. Following rubberbands are available: | Class Name | Description | | :----------------------------- | : --------------------------------------------------------------------------------------- | | RubberbandPointFeature | Rubberband to edit a single position for a point feature. | | RubberbandPointCluster | Rubberband to edit multiple positions to define a cluster of point features. | | RubberbandMultiPointFeature | Rubberband to edit a polyline or polygon to define line or areal features. | | RubberbandSmoothLine | Like RubberbandMultiPointFeature with rounded edges. | | RubberbandPolylineWidth | Rubberband like RubberbandMultiPointFeature for symbols with additional width coordinate. | | RubberbandArrow | Rubberband to edit a polyline with an arrow at the end. | | RubberbandCorridor | Rubberband to edit corridors by defining a polyline and a width. | | RubberbandRectangle | Rubberband to edit a rectangle or square. | | RubberbandEllipse | Rubberband to edit a ellipse or circle. | | RubberbandFreeHand | Rubberband to input a free hand line. | | RubberbandStateSelect | Rubberband to set states to coordinates. | | RubberbandTransform | Rubberband to manipulate moving, rotating and scaling in a single step | | RubberbandTransformMove | Rubberband to define moving transformations | | RubberbandTransformRotate | Rubberband to define rotating transformations | | RubberbandTransformScale | Rubberband to define scaling transformations | On a 3D map scene following rubberbands are available: | Class Name | Description | | :----------------------------- | : --------------------------------------------------------------------------------------- | | RubberbandPointFeature3D | Rubberband to edit a single position for a point feature. | | RubberbandMultiPointFeature3D | Rubberband to edit a polyline or polygon to define line or areal features. | @see Rubberband, RubberbandPointFeature, RubberbandPointCluster, RubberbandMultiPointFeature, RubberbandSmoothLine, RubberbandPolylineWidth RubberbandRectangle, RubberbandEllipse, RubberbandCorridor, RubberbandArrow, RubberbandFreeHand, RubberbandStateSelect RubberbandTransform, RubberbandTransformMove, RubberbandTransformRotate, RubberbandTransformScale, Rubberband3D, RubberbandPointFeature3D, RubberbandMultiPointFeature3D */ class SITUATIONMAP_EXPORT RubberbandFactory : public QObject { Q_OBJECT public: explicit RubberbandFactory( SituationMap::Map * map ); virtual ~RubberbandFactory(); /** @brief template methode to create a rubberband instance Creates with new a rubberband from type RubberbandClass. RubberbandClass must be inherited from class SiMapRubBnd::Rubberband otherwise a nullptr will be retruned. After use the pointer have to be freed with delete. Expample to create a rubberband: @code SituationMap::Map & map = ... const RubberbandFactory & rubberbandFactory = map.rubberbandFactory(); RubberbandPointFeature * rubberband = rubberbandFactory.create(); if (rubberband != nullptr) doSomething(rubberband); @endcode @param parent Parent of rubberband object. If parent is nullptr \c _map will be used as parent @see Rubberband, RubberbandPointFeature, RubberbandPointCluster, RubberbandMultiPointFeature, RubberbandRectangle, RubberbandEllipse, RubberbandCorridor, RubberbandArrow */ template RubberbandClass * create( QObject * parent = nullptr ) const { RubberbandClass * rubberband = nullptr; if ((std::is_base_of::value) && (Mode::Mode_2D == _map->mode())) { // be careful it is not thread safe here Rubberband::currentFactoryMap(_map); Rubberband::allowMultipleRubberbands(_allowMultipleRubberbands); try { rubberband = new RubberbandClass( _map, parent ); } catch (const SituationMap::Exception &) {;} setDefaults( rubberband ); } return rubberband; } /** Creates a new corridor rubberband and defines the input method of the rubberband @param inputMethode Defines the input method of the rubberband @param width With of a corridor in meters. @param parent Parent of rubberband object. If parent is nullptr \c _map will be used as parent @see RubberbandCorridor */ RubberbandCorridor * create( RubberbandCorridor::InputMode inputMode, qreal width = 0, QObject * parent = nullptr ) const { if (!_map->isReady() || (Mode::Mode_2D != _map->mode()) ) return nullptr; Rubberband::currentFactoryMap(_map); Rubberband::allowMultipleRubberbands(_allowMultipleRubberbands); RubberbandCorridor * rubberband = nullptr; try { rubberband = new RubberbandCorridor( _map, inputMode, width, parent ); } catch (const SituationMap::Exception &) {;} setDefaults( rubberband ); return rubberband; } /** Creates a new rubberband fitting to the sidc code @param sidc sidc of symbol that will be created with rubberband. @see RubberbandPointFeature, RubberbandMultiPointFeature */ Rubberband * createSymbol( const QString & sidc, QObject * parent = nullptr ) const; /** Creates a new rubberband fitting to the sidc code @param sidc sidc of symbol that will be created with rubberband. @param winPos Default position of the rubberband on window @see RubberbandPointFeature, RubberbandMultiPointFeature */ Rubberband * createSymbol( const QString & sidc, const QPoint & winPos, QObject * parent = nullptr ) const; /** @brief template methode to create a rubberband instance in 3D maps Creates with new a rubberband from type RubberbandClass. RubberbandClass must be inherited from class SiMapRubBnd::Rubberband otherwise a nullptr will be retruned. After use the pointer have to be freed with delete. Expample to create a rubberband: @code SituationMap::Map & map = ... const RubberbandFactory & rubberbandFactory = map.rubberbandFactory(); RubberbandPointFeature * rubberband = rubberbandFactory.create(); if (rubberband != nullptr) doSomething(rubberband); @endcode @param parent Parent of rubberband object. If parent is nullptr \c _map will be used as parent @see Rubberband, RubberbandPointFeature, RubberbandPointCluster, RubberbandMultiPointFeature, RubberbandRectangle, RubberbandEllipse, RubberbandCorridor, RubberbandArrow */ template RubberbandClass * create3D( QObject * parent = nullptr ) const { RubberbandClass * rubberband = nullptr; if ((std::is_base_of::value) && (Mode::Mode_3D == _map->mode())) { // be careful it is not thread safe here RubberbandBase::currentFactoryMap(_map); RubberbandBase::allowMultipleRubberbands(_allowMultipleRubberbands); try { rubberband = new RubberbandClass( _map, parent ); } catch (const SituationMap::Exception &) {;} setDefaults( rubberband ); } return rubberband; }; /** If pass \c true multiple rubberbands per time can be created per map. Creating a rubberbad of the same type twice per time will return one rubberband that is not alive. Default is \c false. In this case creating a second rubberband before the first has finsihed (rubberband is not alive) will retrun \c nullptr. */ void allowMultipleRubberbands(bool on) { _allowMultipleRubberbands = on; } bool allowMultipleRubberbands() const { return _allowMultipleRubberbands; } void setRubberbandDrawColor( const QColor & ); void setRubberbandFillColor( const QColor & ); void setRubberbandHandleDrawColor( const QColor & ); void setRubberbandHandleFillColor( const QColor & ); void setRubberbandSelectionColor( const QColor & ); void setRubberbandFrameColor( const QColor & ); void setRubberbandFrameFillColor( const QColor & ); void setRubberbandFrameHandleMargin( int ); void setRubberbandPreviewOffset( const QPoint & ); void setRubberbandPreviewSize( unsigned int ); void setRubberbandPickingRatio( unsigned int ); void setRubberbandLineHandleWidth( unsigned int ); signals: void rubberbandCreated(); void rubberbandDestroyed(); private: class Defaults; SituationMap::Map * _map; Defaults * _defaults; bool _allowMultipleRubberbands; LOGGER_T _logger; void setDefaults( RubberbandBase * ) const; void setDefaults( Rubberband * ) const; private slots: void onActivateRubberband( RubberbandBase * rubberband ); void onAbortRubberband ( RubberbandBase * rubberband ); }; /* RubberbandFactory */ } } /* namespace SituationMap::RB */