3 using System.Collections;
4 using System.Collections.Generic;
9 public GameObject mainPane;
10 public GameObject editPane;
11 public GameObject viewNameInputField;
12 public Color colorInactive;
13 public Color colorActive;
16 public Button newButton, deleteButton;
17 public Text viewNameText;
18 public Button buttoPrev, buttonNext;
19 public GameObject viewCountElement;
21 public GameObject meshViewerScaleNode, meshViewerRotationNode;
23 private int currentViewIndex = 0;
27 viewCountElement.SetActive (
false);
35 Patient p = Patient.getLoadedPatient ();
44 PatientEventSystem.startListening(PatientEventSystem.Event.MESH_LoadedSingle, meshLoaded);
45 PatientEventSystem.startListening(PatientEventSystem.Event.PATIENT_Closed, patientClosed);
47 mMeshLoader = GameObject.Find(
"GlobalScript").GetComponent<MeshLoader>();
55 PatientEventSystem.stopListening(PatientEventSystem.Event.MESH_LoadedSingle, meshLoaded);
56 PatientEventSystem.stopListening(PatientEventSystem.Event.PATIENT_Closed, patientClosed);
59 public void meshLoaded(
object obj = null )
63 public void activate()
65 Debug.Log (
"Activate View Control");
66 newButton.interactable =
true;
68 setView (currentViewIndex);
70 public void patientClosed(
object obj = null )
72 deleteButton.interactable =
false;
73 newButton.interactable =
false;
74 viewNameText.text =
"No patient loaded.";
77 public void showMainPane()
79 editPane.SetActive (
false);
80 mainPane.SetActive (
true);
82 public void showEditPane()
84 mainPane.SetActive (
false);
85 editPane.SetActive (
true);
87 public void nextView()
89 setView (currentViewIndex + 1);
91 public void prevView()
93 setView (currentViewIndex - 1);
96 public void insertNewView()
98 Patient p = Patient.getLoadedPatient ();
100 string t = viewNameInputField.GetComponent<InputField> ().text;
102 if (mMeshLoader.MeshGameObjectContainers.Count != 0) {
107 newView.orientation = meshViewerRotationNode.transform.localRotation;
108 newView.scale = meshViewerScaleNode.transform.localScale;
111 foreach (GameObject g
in mMeshLoader.MeshGameObjectContainers) {
112 MeshRenderer mr = g.GetComponentInChildren<MeshRenderer> ();
114 newView.opacities [g.name] = mr.material.color.a;
116 newView.opacities [g.name] = 0.0f;
120 currentViewIndex = p.insertView ( newView, currentViewIndex + 1 );
121 setView (currentViewIndex);
130 public void deleteView()
132 Patient p = Patient.getLoadedPatient ();
134 p.deleteView (currentViewIndex);
137 if (p.getViewCount() <= currentViewIndex) {
138 currentViewIndex = p.getViewCount() - 1;
141 setView (currentViewIndex,
false);
144 void setView(
int index,
bool animate =
true )
146 Patient p = Patient.getLoadedPatient ();
149 if (p.getViewCount () == 0) {
150 viewNameText.text =
"No views configured.";
153 View view = p.getView (index);
155 viewNameText.text = (index + 1).ToString ();
156 viewNameText.text +=
": ";
157 viewNameText.text += view.name;
161 meshViewerScaleNode.GetComponent<
ModelZoomer> ().setTargetZoom (view.scale, 0.8f);
162 meshViewerRotationNode.GetComponent<
ModelRotator> ().setTargetOrientation (view.orientation, 0.8f);
164 meshViewerScaleNode.GetComponent<
ModelZoomer> ().setTargetZoom (view.scale);
165 meshViewerRotationNode.GetComponent<
ModelRotator> ().setTargetOrientation (view.orientation);
168 foreach (KeyValuePair<string, double> entry
in view.opacities) {
169 setMeshOpacity (entry.Key, (
float)entry.Value);
172 currentViewIndex = index;
176 PatientEventSystem.triggerEvent (PatientEventSystem.Event.MESH_Opacity_Changed);
180 if( p.getViewCount () > 0 )
181 deleteButton.interactable =
true;
183 deleteButton.interactable =
false;
187 void setMeshOpacity(
string name,
float opacity )
190 GameObject gameObjectToChangeOpacity = null;
191 foreach (GameObject g
in mMeshLoader.MeshGameObjectContainers) {
192 if (g.name == name) {
193 gameObjectToChangeOpacity = g;
199 if (gameObjectToChangeOpacity != null) {
202 moc.changeOpactiyOfChildren (opacity);
207 void updateViewCount()
209 Patient p = Patient.getLoadedPatient ();
211 int elementsToShow = Math.Max( p.getViewCount (), 1 );
213 if (viewCountElement.transform.parent.childCount < elementsToShow + 1 ) {
214 int toCreate = elementsToShow - (viewCountElement.transform.parent.childCount - 1);
215 for (
int i = 0; i < toCreate; i++) {
216 GameObject newElem = Instantiate (viewCountElement);
217 newElem.transform.SetParent (viewCountElement.transform.parent,
false);
218 newElem.SetActive (
true);
220 }
else if( viewCountElement.transform.parent.childCount > elementsToShow + 1 ) {
222 int toRemove = (viewCountElement.transform.parent.childCount - 1) - elementsToShow;
223 for (
int i = 0; i < toRemove; i++) {
224 Transform tf = viewCountElement.transform.parent.GetChild (viewCountElement.transform.parent.childCount - 1 - i);
226 Destroy( tf.gameObject );
230 foreach (Transform tf
in viewCountElement.transform.parent) {
231 tf.GetComponent<Image> ().color = colorInactive;
235 Transform t = viewCountElement.transform.parent.GetChild( currentViewIndex + 1 );
236 t.GetComponent<Image>().color = colorActive;