2 using System.Collections;
4 using System.ComponentModel;
6 using UnityEngine.EventSystems;
8 using System.Collections.Generic;
10 public class Annotation : MonoBehaviour, IPointerHoverHandler{
13 public string creator;
14 public DateTime creationDate;
16 public GameObject myAnnotationLabel;
17 public GameObject myAnnotationMesh;
18 public GameObject rotationObjects;
19 public GameObject translationObjects;
20 public GameObject scalingObjects;
21 public GameObject viveMoveObject;
22 public GameObject myAnnotationListEntry;
23 public AnnotationControl.AnnotationType myType;
24 private Color myColor;
25 private Color defaultColor;
27 public Material defaultMaterial, previewMaterial;
28 public Collider myCollider;
29 public float maxDistanceToMeshNode = 12f;
31 public float MoveCircleRadiant = 0.5f;
32 private bool rotateWithVive;
36 creationDate = DateTime.Now;
40 defaultColor =
new Color (defaultMaterial.color.r, defaultMaterial.color.g, defaultMaterial.color.b);
41 defaultMaterial = Instantiate (defaultMaterial);
42 previewMaterial = Instantiate (previewMaterial);
46 public void CreateLabel (GameObject annotationLabelMaster) {
48 myAnnotationLabel = (GameObject)Instantiate (annotationLabelMaster,
new Vector3 (0f, 0f, 15f), this.transform.localRotation);
49 myAnnotationLabel.transform.localScale =
new Vector3 (0.05f, 0.05f, 0.05f);
50 myAnnotationLabel.transform.SetParent (this.transform,
false);
51 myAnnotationLabel.SetActive (
true);
57 public void setLabeText (String newLabel) {
59 if (myAnnotationLabel == null) {
60 Debug.LogError (
"Annotation has no AnnotationLabel to edit");
64 myAnnotationLabel.GetComponent<
AnnotationLabel> ().setLabelText (newLabel);
74 this.transform.localPosition = position;
75 this.transform.localRotation = rotation;
79 public GameObject getLabel () {
80 return myAnnotationLabel;
84 public String getLabelText () {
85 return myAnnotationLabel.GetComponent<
AnnotationLabel> ().getLabelText ();
89 public Color getColor () {
90 return new Color (myColor.r, myColor.g, myColor.b, myAnnotationMesh.GetComponent<MeshRenderer> ().material.color.a);
94 public void saveLabelChanges () {
95 if (myAnnotationListEntry != null) {
98 AnnotationControl.instance.updatePatientAnnotationList ();
102 public void changeColor (Color newColor) {
103 myColor =
new Color (newColor.r, newColor.g, newColor.b, myAnnotationMesh.GetComponent<MeshRenderer> ().material.color.a);
104 Material[] mats = myAnnotationMesh.GetComponent<MeshRenderer> ().materials;
105 for (
int i = 0; i < mats.GetLength (0); i++) {
106 mats [i].color = myColor;
108 myAnnotationMesh.GetComponent<MeshRenderer> ().materials = mats;
112 public void setDefaultColor () {
113 changeColor (
new Color (defaultColor.r, defaultColor.g, defaultColor.b, myAnnotationMesh.GetComponent<Renderer> ().material.color.a));
120 Material[] mats = myAnnotationMesh.GetComponent<MeshRenderer> ().materials;
123 for (
int i = 0; i < mats.GetLength (0); i++) {
124 Color pinColor = mats [i].color;
126 mats [i] = defaultMaterial;
127 mats [i].color = pinColor;
129 myAnnotationMesh.GetComponent<MeshRenderer> ().materials = mats;
132 for (
int i = 0; i < mats.GetLength (0); i++) {
133 Color pinColor = mats [i].color;
135 mats [i] = previewMaterial;
136 mats [i].color = pinColor;
138 myAnnotationMesh.GetComponent<MeshRenderer> ().materials = mats;
155 Material[] mats = myAnnotationMesh.GetComponent<MeshRenderer> ().materials;
156 for (
int i = 0; i < mats.GetLength (0); i++) {
157 Color pinColor = mats [i].color;
159 mats [i] = defaultMaterial;
160 mats [i].color = pinColor;
162 myAnnotationMesh.GetComponent<MeshRenderer> ().materials = mats;
169 public void disableMeshCollider () {
170 myCollider.enabled =
false;
173 public void enableAllCollider (
bool enable) {
174 myCollider.enabled = enable;
175 myAnnotationLabel.GetComponent<
AnnotationLabel> ().myBoxCollider.enabled = enable;
179 public void transferAnnotationSettings (GameObject settingSource) {
180 changeColor (settingSource.GetComponent<
Annotation> ().getColor ());
181 setLabeText (settingSource.GetComponent<
Annotation> ().getLabelText ());
190 InputDevice inputDevice = InputDeviceManager.instance.currentInputDevice;
194 changeAnnotationLabelLayer (
"UIAnnotationEdit");
195 GameObject.Find(
"GlobalScript").GetComponent<HierarchicalInputModule>().disableLayer(
"UIOrgans");
198 GameObject.Find(
"GlobalScript").GetComponent<HierarchicalInputModule>().enableLayer(
"UIOrgans");
199 changeAnnotationMeshLayer (
"UIOrgans");
200 changeAnnotationLabelLayer (
"UIOrgans");
203 if (inputDevice.getDeviceType () == InputDeviceManager.InputDeviceType.Mouse) {
204 if (rotationObjects != null) {
205 rotationObjects.SetActive (active);
207 if (translationObjects != null) {
208 translationObjects.SetActive (active);
210 if (scalingObjects != null) {
211 scalingObjects.SetActive (active);
213 }
else if (inputDevice.getDeviceType () == InputDeviceManager.InputDeviceType.ViveController) {
214 changeAnnotationMeshLayer (
"UIAnnotationEdit");
215 if(viveMoveObject != null) {
216 viveMoveObject.SetActive (active);
221 public void OnPointerHover (UnityEngine.EventSystems.PointerEventData eventData) {
223 if(viveMoveObject == null) {
226 if(eventData.pointerEnter != myAnnotationMesh) {
229 InputDevice inputDevice = InputDeviceManager.instance.currentInputDevice;
230 if (inputDevice.getDeviceType () == InputDeviceManager.InputDeviceType.ViveController) {
231 Vector3 localEventPos = transform.InverseTransformPoint (eventData.pointerCurrentRaycast.worldPosition);
232 GameObject trans = viveMoveObject.transform.GetChild (0).gameObject;
233 GameObject rot = viveMoveObject.transform.GetChild (1).gameObject;
234 viveMoveObject.transform.position = eventData.pointerCurrentRaycast.worldPosition;
237 Vector3 localDevicePos = transform.InverseTransformPoint (inputDevice.getEventCamera().transform.position);
238 float angle = Vector3.Angle (localEventPos, localDevicePos);
240 rotateWithVive =
true;
241 trans.SetActive (
false);
242 rot.SetActive (
true);
244 rotateWithVive =
false;
245 rot.SetActive (
false);
246 trans.SetActive (
true);
250 float minScale = Mathf.Min (myAnnotationMesh.transform.localScale.x, myAnnotationMesh.transform.localScale.y) / 2f;
251 float distance = (localEventPos - myAnnotationMesh.transform.localPosition).magnitude * 1f/minScale;
253 if(distance > MoveCircleRadiant) {
254 rotateWithVive =
true;
255 trans.SetActive (
false);
256 rot.SetActive (
true);
258 rotateWithVive =
false;
259 rot.SetActive (
false);
260 trans.SetActive (
true);
267 public void endHover() {
268 if(viveMoveObject == null) {
271 viveMoveObject.transform.GetChild (0).gameObject.SetActive(
false);
272 viveMoveObject.transform.GetChild (1).gameObject.SetActive(
false);
276 public void rescaleMesh (Vector3 newScale) {
277 if(scalingObjects != null) {
278 myAnnotationMesh.transform.localScale = newScale;
282 public Vector3 getMeshScale() {
283 return myAnnotationMesh.transform.localScale;
287 public void rotateMesh(Quaternion rotation) {
288 myAnnotationMesh.transform.rotation *= rotation;
291 public Quaternion getMeshRotation() {
292 return myAnnotationMesh.transform.rotation;
296 public void translateMesh(Vector3 newPos) {
298 this.transform.position = newPos;
302 public void changeAnnotationMeshLayer(String layer) {
303 myAnnotationMesh.layer = LayerMask.NameToLayer (layer);
306 private void changeAnnotationLabelLayer(String layer) {
307 myAnnotationLabel.layer = LayerMask.NameToLayer (layer);
310 public bool LabelClicked(PointerEventData data) {
311 return AnnotationControl.instance.annotationClicked (data);
314 public void AnnotationClicked (BaseEventData eventData) {
315 PointerEventData data = eventData as PointerEventData;
317 myAnnotationMesh.GetComponent<
AnnotationMoveVive> ().AnnotationClicked (data, rotateWithVive);
321 public void saveAnnotationChanges() {
322 AnnotationControl.instance.updatePatientAnnotationList ();
325 public void destroyAnnotation() {
328 if (myAnnotationLabel != null)
330 Destroy(myAnnotationLabel);
334 public void ViveMovement(
bool active) {
335 viveMoveObject.SetActive (!active);
void setDefaultTransparency()
Reste Transparency of Annotation
bool annotationClicked(PointerEventData data)
Called by Annotation when Clicked on Annotation
void makeTransperent(float alpha)
Makes the Annotation transperent.
void updatePosition(Quaternion rotation, Vector3 position)
Updates the position and Rotation in local Coordinates.
void setMovementMeshsActive(bool active)
Sets the movement meshs active.