home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / freedraft.tar.gz / freedraft.tar / FREEdraft-050298 / GEOMLIB2D / pick.h < prev    next >
C/C++ Source or Header  |  1998-04-29  |  5KB  |  134 lines

  1. // pick.h
  2.  
  3. // Copyright (C) 1997  Cliff Johnson                                       //
  4. //                                                                         //
  5. // This program is free software; you can redistribute it and/or           //
  6. // modify it under the terms of the GNU  General Public                    //
  7. // License as published by the Free Software Foundation; either            //
  8. // version 2 of the License, or (at your option) any later version.        //
  9. //                                                                         //
  10. // This software is distributed in the hope that it will be useful,        //
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of          //
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       //
  13. // General Public License for more details.                                //
  14. //                                                                         //
  15. // You should have received a copy of the GNU General Public License       //
  16. // along with this software (see COPYING); if not, write to the        //
  17. // Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. //
  18.  
  19.  
  20. #ifndef PICK_H
  21. #define PICK_H
  22.  
  23. #include <iostream.h>
  24. #include "geom.h"
  25. #include "point.h"
  26. #include "locale_enum.h"
  27.  
  28. // the Pick class is a common container for passing geometry to
  29. // solver functions - the method is intended 
  30. // to implement a generalized appearance in the solver class in
  31. // a form appropriate for cad usage - hence the data
  32. // encapsulated is a Geom* and a Point - The Geom* pointing
  33. // to the geometry selected, and the Point giving a 
  34. // spatial coordinate, in the cad global coordinate system, 
  35. // the selection.
  36. // 
  37. // This makes possible solver functions like:
  38. //     Point PointConstraint2D(const Pick& p1, const Pick& p2) throw (GeomException);
  39. //     
  40. // This function solves a point by 2 constraints where the constraints can be combinations
  41. // of different geometry types . 2 points -> midpoint , 2 lines -> intersection, Point
  42. // and a Circle -> intersection _nearest_ the selection point of pick 2, etc.
  43. // 
  44. // Similar to the selection class, Pick drops the button value, 
  45. // and as well does not require a persistent object - a Handle -
  46. // just the pointer to the geometry.
  47. // Of course the USER MUST THEN MANAGE THE SCOPE OF THE OBJECT        ***WARNING***
  48. // POINTERED in the container 
  49. // 
  50. // This is a very dangerous thing, but necessary me thinks, because sometime 
  51. // the user selects nothing, but what he means is an "free point". In the 
  52. // FREEdraft interface, selecting with the middle mouse button does this. 
  53. // If the MenuHandler is needs 2 picks, it needs to keep the free
  54. // point - which is not persistent - alive until the second pick is made
  55. // and the "free" point is used.
  56. // 
  57. // Why not put the free picks into the bank as persistent objects, just
  58. // for as long as needed?  1) this would tie the geombank fiasco to
  59. // the geomlib2d stuff 2) geombank is not a particularly refined, 
  60. // efficient, fast, optimized, or robust database system, and will 
  61. // be changed. 
  62. // 
  63. // to assist in managing the scope of locally allocated geometry, 
  64. // each Pick contains a flag "local" which is set by the 
  65. // user at pick assignment time to PERSISTENT if the object pointer is from 
  66. // a handle, and LOCAL if locally allocated geom object.
  67. // The user can then call CleanUp() on the pick when they are finished with it.
  68. // if the flag is LOCAL, the object pointed to is deleted. if the flag is 
  69. // PERSISTENT or UNUSED, indicating the pick was never assigned a value, 
  70. // the pointered object is left alone.
  71.  
  72. // DO NOT PASS THE ADDRESS OF A TEMPORARY IN A PICK. (like this)
  73. // Point p1(x,y,z);
  74. // Pick pk1 = Pick(&p1,p1);
  75. // ...
  76. // 
  77. // ALWAYS Instead explicitly allocate all local stuff you load into a pick, (like this)
  78. // Point* p1 = new Point(x,y,z);
  79. // Pick pk1 = Pick(p1,*p1,LOCAL);
  80. // ...
  81. // 
  82.  
  83. //picks are loaded into a stack by the HandlerHandler object, and are not
  84. //actually used in a computation until enough of them are available for the pending computation.
  85. //i.e. a line by contraints waits until two picks are available. So if you store a temporary,
  86. //you'll surely meet with doom.
  87. // CleanUp is typically used by handler object sub-methods after such a computation.
  88.  
  89. // You must however provide *some* geometry object. So in the case of
  90. // a free pick, pass the coordinate (possibly rounded) point as both the 
  91. // geometry and the pick point
  92. // 
  93. // See the MenuHandler family for examples. 
  94. // 
  95. // Picks are created - converted from Selections - during calls to MenuHandler::DoPick()
  96.  
  97. class Pick
  98. {
  99. private:
  100.     const Geom* geometry;
  101.     Point point;
  102.     Locale locale;
  103. public:
  104.     Pick(){ locale = UNUSED; }
  105.     Pick(const Geom* g, const Point& p,Locale l = PERSISTENT);
  106.  
  107.     Pick(const Pick& p);
  108.     Pick& operator=(const Pick& p);
  109.  
  110.     Point GetPoint() const { return point; }
  111.     const Geom* PointsAt() const { return geometry;}
  112.  
  113.     void CleanUp();                 //for freeing non-handle (local) geometry - 
  114.                     //do not call on geometry created by 
  115.                         //GeomBank::Create(). (it won't do anything) 
  116.                     //use GeomBank::Destroy(h) to delete geometry objects.  
  117.                     //that.) 
  118.  
  119.     int Type() const { return geometry->Type(); }
  120.  
  121.     bool IsLocal() const { return locale == LOCAL; }
  122.     bool IsLocked() const { return locale == LOCKED; }
  123.  
  124.     bool Lock();
  125.     bool Unlock();
  126.  
  127.     friend bool operator==(const Pick& p1, const Pick& p2);
  128.  
  129.     friend ostream& operator<<(ostream& os, const Pick& p);
  130. };
  131.  
  132. #endif
  133.  
  134.