00001 /*************************************************************************** 00002 *cr 00003 *cr (C) Copyright 1995-2019 The Board of Trustees of the 00004 *cr University of Illinois 00005 *cr All Rights Reserved 00006 *cr 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * RCS INFORMATION: 00011 * 00012 * $RCSfile: PickList.h,v $ 00013 * $Author: johns $ $Locker: $ $State: Exp $ 00014 * $Revision: 1.38 $ $Date: 2020/10/28 17:42:35 $ 00015 * 00016 *************************************************************************** 00017 * DESCRIPTION: 00018 * 00019 * The PickList object, which maintains a list of Pickable objects and 00020 * has the ability to find and deal with items picked by a pointer device. 00021 * 00022 * Each Scene is derived from PickList. 00023 * 00024 * Each PickList has a list of possible picking modes; these are created by 00025 * the request of Pickable objects, which then get notified when an 00026 * object is picked. Only Pickables which are interested in the specified 00027 * mode are told of the picking result. 00028 * 00029 * For each pick mode, there is a corresponding PickMode object; PickMode 00030 * is a base class for the particular type of picking mode requested. 00031 * Pickable objects may request to have a new pick mode added to this list, 00032 * and if they do so they must provide an instance of the PickMode object 00033 * they require. If the mode exists, the objects may replace the mode or 00034 * may just use the current one. When modes are removed, the instance is 00035 * deleted. 00036 * 00037 * Only one picking operation may be in effect at a time. A picking operation 00038 * consists of these steps: 00039 * 1. A pick is started by a pointer, by queueing a CmdPickStart command. 00040 * 2. pick_start is called, which determines if something is selected. 00041 * If so, returns tag of item, and sets internal flags to 00042 * indicate what is being picked, and how. 00043 * 2.1 Each Pickable which is interested in the current mode is 00044 * told when the pick starts, and all later steps. 00045 * 2.2 The object for the current pick mode is also told of 00046 * the start of the pick. 00047 * 3. pick_move is called whenever the pointer moves, by queueing the 00048 * CmdPickMove command. This continues until the picking is 00049 * finished. The PickMode object and interested Pickables are 00050 * also told of the move. 00051 * 4. pick_end is called by queueing CmdPickEnd; this behaves similarly 00052 * the pick_move. When finished, the internal flags are reset 00053 * to indicate that picking is finished, and a new one can begin. 00054 * NOTE: multiple concurrent picks could be implemented later by providing 00055 * an object which maintains separate sets of the internal flags and variables, 00056 * for each picking device. This would also require another argument to the 00057 * pick_* routines, to indicate which picking device is being used. Also, 00058 * PickMode and Pickable object involved in another picking operation would 00059 * have to be excluded from being informed of other picking operations. 00060 ***************************************************************************/ 00061 #ifndef PICKLIST_H 00062 #define PICKLIST_H 00063 00064 #include "ResizeArray.h" 00065 #include "NameList.h" 00066 #include "Command.h" 00067 class Pickable; 00068 class VMDApp; 00069 00071 class PickEvent : public Command { 00072 public: 00073 Pickable *pickable; 00074 int tag; 00075 00076 PickEvent(Pickable *p, int t) 00077 : Command(PICK_EVENT), pickable(p), tag(t) {} 00078 }; 00079 00082 class PickList { 00083 private: 00084 int currPickDim; 00085 int currPickTag; 00086 Pickable *currPickable; 00087 00088 int num_pickable(void) { return int(pickableObjs.num()); } 00089 Pickable *pickable(int n) { return pickableObjs[n]; } 00090 int picking(void) { return currPickable != NULL; } 00091 00093 ResizeArray<Pickable *> pickableObjs; 00094 00095 VMDApp *app; 00096 00098 int total_callback_clients; 00099 00100 public: 00102 PickList(VMDApp *); 00103 00104 // 00105 // routines for registering Pickable objects 00106 // 00107 00109 void add_pickable(Pickable *); 00110 00112 void remove_pickable(Pickable *); 00113 00114 // 00115 // routines to handle starting a pick, moving during a pick, 00116 // ending of a pick 00117 // 00118 00133 Pickable *pick_check(int, const float *, int &, int * cell, 00134 float window_size, char *callback_client=NULL); 00135 00142 int pick_start(int btn, int dim, const float *); 00143 00148 int pick_move(const float *); 00149 00154 int pick_end(); 00155 00158 void pick_callback_clear(char *callback_client); 00159 }; 00160 00161 #endif 00162