UnityMol  0.9.6-875
UnityMol viewer / In developement
DisplayMolecule.cs
Go to the documentation of this file.
1 namespace Molecule.View {
2  using UnityEngine;
3  using System.Collections;
4  using System.Collections.Generic;
5  using Molecule.Model;
6  using Molecule.Control;
9  using UI;
10 
11 
12  public class DisplayMolecule {
13  private static HBallManager hbManager;
14  private static SphereManager spManager;
15  private static CubeManager cubeManager;
18  private static LineManager lineManager;
20  private static HStickManager hStickManager;
22 
23 
24 
31  public static List<GenericManager> GetManagers() {
33  List<GenericManager> managerList = new List<GenericManager>();
34 // if(aType == UIData.AtomType.hyperball) { //|| UIData.bondtype == UIData.BondType.hyperstick) {
35  if(hbManager == null){
36  GameObject hbManagerObj = GameObject.FindGameObjectWithTag("HBallManager");
37  hbManager = hbManagerObj.GetComponent<HBallManager>();
38  }
39  managerList.Add(hbManager);
40 // }else if (aType == UIData.AtomType.sphere) {
41  if(spManager == null){
42  GameObject spManagerObj = GameObject.FindGameObjectWithTag("SphereManager");
43  spManager = spManagerObj.GetComponent<SphereManager>();
44  }
45  managerList.Add(spManager);
46 // } else if (aType == UIData.AtomType.cube) {
47  if(cubeManager == null){
48  GameObject cubeManagerObj = GameObject.FindGameObjectWithTag("CubeManager");
49  cubeManager = cubeManagerObj.GetComponent<CubeManager>();
50  }
51  managerList.Add(cubeManager);
52 // } else if (aType == UIData.AtomType.particleball) {
53  if(shManager == null){
54  GameObject psObj = GameObject.FindGameObjectWithTag("ShurikenParticleManager");
55  shManager = psObj.GetComponent<ShurikenParticleManager>();
56  }
57  managerList.Add(shManager);
58 // } else if(aType == UIData.AtomType.optihb) {
59  if(hbmeshManager == null){
60  GameObject hbmeshManagerObj = GameObject.FindGameObjectWithTag("HBallMeshManager");
61  hbmeshManager = hbmeshManagerObj.GetComponent<HBallMeshManager>();
62  }
63  managerList.Add(hbmeshManager);
64 // }
65 // if (UIData.bondtype == UIData.BondType.line) {
66  if(lineManager == null){
67  GameObject lineManagerObj = GameObject.FindGameObjectWithTag("LineManager");
68  lineManager = lineManagerObj.GetComponent<LineManager>();
69  }
70  managerList.Add(lineManager);
71 // } else if (UIData.bondtype == UIData.BondType.cube) {
72  if(cubeBondManager == null){
73  GameObject cubeBondManagerObj = GameObject.FindGameObjectWithTag("CubeBondManager");
74  cubeBondManager = cubeBondManagerObj.GetComponent<CubeBondManager>();
75  }
76  managerList.Add(cubeBondManager);
77 // } else if (UIData.bondtype == UIData.BondType.hyperstick) {
78  if(hStickManager == null){
79  GameObject hStickManagerObj = GameObject.FindGameObjectWithTag("HStickManager");
80  hStickManager = hStickManagerObj.GetComponent<HStickManager>();
81  }
82  managerList.Add(hStickManager);
83 // }
84 // else if (UIData.bondtype == UIData.BondType.optihs) {
85  if(hStickMeshManager == null){
86  GameObject hStickMeshManagerObj = GameObject.FindGameObjectWithTag("HStickMeshManager");
87  hStickMeshManager = hStickMeshManagerObj.GetComponent<HStickMeshManager>();
88  }
89  managerList.Add(hStickMeshManager);
90 // }
91 
92  return managerList;
93  }
94 
95  public static void AddPhysics() {
97  if(MoleculeModel.atomsByChar!=null) {
98  foreach(string key in MoleculeModel.atomsByChar.Keys){
99  foreach(GameObject box in MoleculeModel.atomsByChar[key]) {
100  if(box&&box.GetComponent <Rigidbody>()==null) {
101  box.AddComponent<Rigidbody>();
102  box.GetComponent<Rigidbody>().useGravity = false;
103  box.GetComponent<Rigidbody>().interpolation = RigidbodyInterpolation.Interpolate;
104  box.GetComponent<Rigidbody>().drag = 0.6f;
105  }
106  if(box&&box.GetComponent <SpringJoint>()==null) {
107  box.AddComponent<SpringJoint>();
108  box.GetComponent<SpringJoint>().spring = 5;
109  }
110  }
111  }
112  }
113  }
114  public static void DeletePhysics() {
115  UIData.resetInteractive=false;
116  if(MoleculeModel.atomsByChar!=null) {
117  foreach(string key in MoleculeModel.atomsByChar.Keys){
118  foreach(GameObject box in MoleculeModel.atomsByChar[key]) {
119  if(box&&box.GetComponent <SpringJoint>())
120  Object.Destroy (box.GetComponent <SpringJoint>());
121  if(box&&box.GetComponent <Rigidbody>())
122  Object.Destroy (box.GetComponent <Rigidbody>());
123  }
124  }
125  }
126  }
127 
128  public static void ToggleDistanceCueing(bool enabling) {
129  List<GenericManager> managers = GetManagers();
130  foreach(GenericManager manager in managers)
131  manager.ToggleDistanceCueing(enabling);
132  }
133 
134  public static void DestroyAtomsAndBonds() {
135  List<GenericManager> managers = GetManagers();
136  foreach(GenericManager manager in managers)
137  manager.DestroyAll();
138  }
139  public static void DestroyBonds(){
140 
142  if(bondManager != null){
143  bondManager.DestroyAll();
144  }
145  }
146  public static void DestroyAllAtomsAndBonds(){
147  if(hbManager != null){
148  hbManager.DestroyAll();
149  }
150  if(spManager != null){
151  spManager.DestroyAll();
152  }
153  if(cubeManager != null){
154  cubeManager.DestroyAll();
155  }
156  if(shManager != null){
157  shManager.DestroyAll();
158  }
159  if(hbmeshManager != null){
160  hbmeshManager.DestroyAll();
161  }
162  if(lineManager != null){
163  lineManager.DestroyAll();
164  }
165  if(cubeBondManager != null){
166  cubeBondManager.DestroyAll();
167  }
168  if(hStickManager != null){
169  hStickManager.DestroyAll();
170  }
171  if(hStickMeshManager != null){
172  hStickMeshManager.DestroyAll();
173  }
174 
175 
176  }
177  public static void InitManagers() {
178  List<GenericManager> managers = GetManagers();
179  foreach(GenericManager manager in managers)
180  manager.Init();
181  }
182 
183  public static void HideMolecule(){
184  HideAtoms();
185  HideBonds();
186  }
187 
188  public static void ShowMolecule(){
189  ShowAtoms();
190  ShowBonds();
191  }
192  public static void HideAtoms() {
194  atomManager.DisableRenderers();
195  }
196 
197 
198  public static void ShowAtoms() {
200  atomManager.EnableRenderers();
201  }
202  public static void ShowBonds(){
203 
205  if(bondManager != null){
206  bondManager.EnableRenderers();
207  }
208  }
209  public static void HideBonds(){
210 
212 
213  if(bondManager != null)
214  bondManager.DisableRenderers();
215  }
216  public static void showHydrogens(bool hide){
217 
220 
221 
222  atomManager.showHydrogens(hide);
223 
224  if(bondManager != null )
225  bondManager.showHydrogens(hide);
226 
228  }
229 
230  public static void ChangeRepresentation(UIData.AtomType newAtomType,UIData.BondType newBondType = UIData.BondType.nobond){
231 
232 // HideAtoms();
233 // if(UIData.bondtype != newBondType)
234 // HideBonds();
235 
236 
237 
238  GenericManager atomManager = null;
239  GenericManager bondManager = null;
240 
241  atomManager = UnityMolMain.getCurrentAtomManager();
242  bondManager = UnityMolMain.getCurrentBondManager();
243 
244  atomManager.DisableRenderers();
245  bondManager.DisableRenderers();
246 
247  UIData.atomtype = newAtomType;
248  UIData.bondtype = newBondType;
249 
250  // Select the renderer corresponding to the selected representation.
251  //
252  if (UIData.atomtype == UIData.AtomType.cube) {
253  UnityMolMain.setCurrentAtomManager(cubeManager);
254  }
255  else if (UIData.atomtype == UIData.AtomType.hyperball) {
257  }
258  else if(UIData.atomtype == UIData.AtomType.optihb){
259  UnityMolMain.setCurrentAtomManager(hbmeshManager);
260  }
261  else if(UIData.atomtype == UIData.AtomType.sphere){
263  }
264  else if(UIData.atomtype == UIData.AtomType.particleball){
266  }
267 
268  if (UIData.bondtype==UIData.BondType.cube) {
269  UnityMolMain.setCurrentBondManager(cubeBondManager);
270  }
271  else if (UIData.bondtype==UIData.BondType.hyperstick) {
272  UnityMolMain.setCurrentBondManager(hStickManager);
273  }
274  else if(UIData.bondtype==UIData.BondType.line) {
275  UnityMolMain.setCurrentBondManager(lineManager);
276  }
277  else if(UIData.bondtype==UIData.BondType.optihs){
278  UnityMolMain.setCurrentBondManager(hStickMeshManager);
279  }
280 
281  atomManager = UnityMolMain.getCurrentAtomManager();
282  bondManager = UnityMolMain.getCurrentBondManager();
283 
284  //
285  // Instantiate atoms if not already done.
286  //
287 
288  if (atomManager.isInit && UIData.atomtype != UIData.AtomType.noatom) {
289  atomManager.EnableRenderers();
290  } else {
291  if(UIData.atomtype == UIData.AtomType.cube || UIData.atomtype == UIData.AtomType.hyperball){
292  IAtomStyle displayAtom=new AtomCubeStyle();
293  displayAtom.DisplayAtoms(UIData.atomtype);
294  }
295 
296  else if(UIData.atomtype == UIData.AtomType.optihb){
297  IAtomStyle displayAtom=new AtomMeshStyle();
298  displayAtom.DisplayAtoms(UIData.atomtype);
299  hbmeshManager.EnableRenderers();
300  UnityMolMain.setCurrentAtomManager(hbmeshManager);
301  }
302  else if(UIData.atomtype == UIData.AtomType.sphere){
303  IAtomStyle displayAtom=new AtomSphereStyle();
304  displayAtom.DisplayAtoms(UIData.atomtype);
305  spManager.EnableRenderers();
307  }
308  else if(UIData.atomtype == UIData.AtomType.particleball){
309  IAtomStyle displayAtom=new AtomParticleStyle();
310  displayAtom.DisplayAtoms(UIData.atomtype);
311  }
312  }
313 
314  //
315  // Instantiate bonds if not already done.
316  //
317  if (bondManager.isInit && UIData.bondtype != UIData.BondType.nobond) {
318  bondManager.EnableRenderers();
319  }
320  else {
321  if(UIData.bondtype==UIData.BondType.cube||UIData.bondtype==UIData.BondType.hyperstick||UIData.bondtype==UIData.BondType.bbhyperstick) {
322  IBondStyle displayBond=new BondCubeStyle();
323  displayBond.DisplayBonds();
324  }
325  else if(UIData.bondtype==UIData.BondType.line) {
326  IBondStyle displayBond=new BondLineStyle();
327  displayBond.DisplayBonds();
328  }
329  else if(UIData.bondtype==UIData.BondType.optihs){
330  IBondStyle displayBond=new BondMeshStyle();
331  displayBond.DisplayBonds();
332  }
333  }
334 
335  atomManager.ResetRadii();
336  bondManager.ResetRadii();
337 
338  if(UIData.bondtype != UIData.BondType.nobond)
339  showHydrogens(LoadTypeGUI.toggle_HIDE_HYDROGEN);
340 
341  }
342 
343 
344 
345  public static void ClearMemory(){
346 
347 
348  // DestroyAtomsAndBonds();
349  DestroyAllAtomsAndBonds();
350 
351 
355 
359 
360  }
361  }
362 
363 
364 }
abstract void Init()
Initializes this instance of the manager.
static ShurikenParticleManager shManager
override void DestroyAll()
Definition: CubeManager.cs:21
static HBallManager hbManager
static SphereManager spManager
static void DestroyOxySphere()
Definition: SugarManager.cs:98
static void ToggleDistanceCueing(bool enabling)
void DestroySurfaces()
override void DestroyAll()
static void DestroySugarRibs()
Definition: SugarManager.cs:78
abstract void DestroyAll()
override void DestroyAll()
Disable and destroys all the Hyperballs
override void DestroyAll()
Disable and destroys all the Hyperballs and Sticks.
static HBallMeshManager hbmeshManager
abstract void ResetRadii()
override void EnableRenderers()
Enables the renderers for the entire set of balls and sticks.
static HStickMeshManager hStickMeshManager
static void DestroyRingBlending()
Definition: SugarManager.cs:51
override void DestroyAll()
abstract void EnableRenderers()
Enables the renderers for all objects managed by the instance of the manager.
abstract void showHydrogens(bool hide)
static CubeBondManager cubeBondManager
static void showHydrogens(bool hide)
static HStickManager hStickManager
static LineManager lineManager
override void DestroyAll()
Disable and destroys all the Sticks.
static bool resetInteractive
Definition: UIData.cs:147
static void setCurrentAtomManager(GenericManager manager)
Definition: UnityMolMain.cs:63
abstract void DisableRenderers()
Disables the renderers for all objects managed by the instance of the manager.
static ElectrostaticManager getElectrostaticManager()
Definition: UnityMolMain.cs:42
static void setCurrentBondManager(GenericManager manager)
Definition: UnityMolMain.cs:68
static Dictionary< string, GameObject[]> atomsByChar
!WiP Includes FLAGS of GUI.
Definition: UIData.cs:78
static CubeManager cubeManager
static void ChangeRepresentation(UIData.AtomType newAtomType, UIData.BondType newBondType=UIData.BondType.nobond)
static BondType bondtype
Definition: UIData.cs:141
override void DestroyAll()
override void DestroyAll()
Definition: LineManager.cs:22
static List< GenericManager > GetManagers()
Gets the list of active managers based on the atom type provided and based on the bond type in UIData...
static AtomType atomtype
Definition: UIData.cs:139
static SurfaceManager getSurfaceManager()
Definition: UnityMolMain.cs:24
static GenericManager getCurrentBondManager()
Definition: UnityMolMain.cs:54
void DisplayAtoms(UIData.AtomType type_atom, bool force_display=false)
override void EnableRenderers()
Enables the renderers for all objects managed by the instance of the manager.
Definition: GUIDisplay.cs:66
static GenericManager getCurrentAtomManager()
Definition: UnityMolMain.cs:50
abstract void ToggleDistanceCueing(bool enabling)