]> gerrit.simantics Code Review - simantics/3d.git/blob
fbae87e4703f54ca77b246905ce7c9109ecec38a
[simantics/3d.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2007- VTT Technical Research Centre of Finland.\r
3  * All rights reserved. This program and the accompanying materials\r
4  * are made available under the terms of the Eclipse Public License v1.0\r
5  * which accompanies this distribution, and is available at\r
6  * http://www.eclipse.org/legal/epl-v10.html\r
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package org.simantics.proconf.g3d.shapeeditor.common;\r
12 \r
13 import java.util.Collection;\r
14 \r
15 import org.simantics.db.Builtins;\r
16 import org.simantics.db.Resource;\r
17 import org.simantics.layer0.utils.Statement;\r
18 import org.simantics.layer0.utils.IEntity;\r
19 import org.simantics.layer0.utils.viewpoints.AcceptDecision;\r
20 import org.simantics.layer0.utils.viewpoints.AcceptRule;\r
21 import org.simantics.layer0.utils.viewpoints.PlainStateFactory;\r
22 import org.simantics.layer0.utils.viewpoints.ResourceViewpoint;\r
23 import org.simantics.layer0.utils.viewpoints.State;\r
24 import org.simantics.layer0.utils.viewpoints.StateFactory;\r
25 import org.simantics.layer0.utils.viewpoints.TraversalDecision;\r
26 import org.simantics.layer0.utils.viewpoints.TraversalRule;\r
27 import org.simantics.layer0.utils.viewpoints.rules.AcceptAllResourceAcceptRule;\r
28 import org.simantics.proconf.g3d.shapeeditor.ShapeEditorResources;\r
29 \r
30 \r
31 public class ViewpointGenerator {\r
32         \r
33         public static ResourceViewpoint createStuctureViewpoint() {\r
34                 StateFactory f = new PlainStateFactory();\r
35                 final State rootState = f.newState();\r
36                 final State projectState = f.newState();\r
37                 final State libraryState = f.newState();\r
38 \r
39                 return new ResourceViewpoint(new TraversalRule() {\r
40                         @Override\r
41                         public TraversalDecision makeTraversalDecision(State state,\r
42                                         Statement statement) {\r
43                                 Builtins b = statement.getGraph().getBuiltins();\r
44                                 if (state.equals(rootState)) {\r
45                                         if (!statement.getPredicate().equals(b.ConsistsOf))\r
46                                                 return TraversalDecision.stopTraversal;\r
47                                         //if (!statement.getObject().isInstanceOf(b.Project))\r
48                                         //    return TraversalDecision.stopTraversal;\r
49                                         return TraversalDecision.continueTraversal(projectState);\r
50                                 } else if (state.equals(projectState)) {\r
51                                         if (!statement.getPredicate().equals(b.ConsistsOf))\r
52                                                 return TraversalDecision.stopTraversal;\r
53                                         //if (!statement.getObject().isInstanceOf(b.Library))\r
54                                         //    return TraversalDecision.stopTraversal;\r
55                                         return TraversalDecision.continueTraversal(libraryState);\r
56                                 } else if (state.equals(libraryState)) {\r
57                                         if (!statement.getPredicate().equals(b.ConsistsOf)\r
58                                                         && !statement.getPredicate().isSubrelationOf(\r
59                                                                         ShapeEditorResources.g3dResource.HasChild))\r
60                                                 return TraversalDecision.stopTraversal;\r
61                                         return TraversalDecision.continueTraversal(libraryState);\r
62                                 }\r
63                                 return TraversalDecision.stopTraversal;\r
64                         }\r
65 \r
66                         @Override\r
67                         public boolean areAllStatesRelevant() {\r
68                                 return true;\r
69                         }\r
70 \r
71                         @Override\r
72                         public Collection<State> relevantStates() {\r
73                                 return null;\r
74                         }\r
75                 }, new AcceptAllResourceAcceptRule(), rootState);\r
76         }\r
77         \r
78         public static ResourceViewpoint createObjectStructureViewpoint() {\r
79                 StateFactory f = new PlainStateFactory();\r
80                 final State rootState = f.newState();\r
81 \r
82                 return new ResourceViewpoint(new TraversalRule() {\r
83                         @Override\r
84                         public TraversalDecision makeTraversalDecision(State state,\r
85                                         Statement statement) {\r
86                                 if (state.equals(rootState)) {\r
87                                         if (!statement.getPredicate().isSubrelationOf(\r
88                                                         ShapeEditorResources.g3dResource.HasChild))\r
89                                                 return TraversalDecision.stopTraversal;\r
90                                         return TraversalDecision.continueTraversal(rootState);\r
91                                 }\r
92                                 return TraversalDecision.stopTraversal;\r
93                         }\r
94 \r
95                         @Override\r
96                         public boolean areAllStatesRelevant() {\r
97                                 return true;\r
98                         }\r
99 \r
100                         @Override\r
101                         public Collection<State> relevantStates() {\r
102                                 return null;\r
103                         }\r
104                 }, new AcceptAllResourceAcceptRule(), rootState);\r
105         }\r
106         \r
107         public static ResourceViewpoint createObjectSizingParameterViewpoint(Resource modelToParameterRelation) {\r
108                 StateFactory f = new PlainStateFactory();\r
109                 final State rootState = f.newState();\r
110                 final State endState = f.newState();\r
111                 final Resource relation = modelToParameterRelation;\r
112 \r
113                 return new ResourceViewpoint(new TraversalRule() {\r
114                         @Override\r
115                         public TraversalDecision makeTraversalDecision(State state,\r
116                                         Statement statement) {\r
117                                 if (state.equals(rootState)) {\r
118                                         if (!statement.getPredicate().isSubrelationOf(relation))\r
119                                                 return TraversalDecision.stopTraversal;\r
120                                         return TraversalDecision.continueTraversal(endState);\r
121                                 }\r
122                                 return TraversalDecision.stopTraversal;\r
123                         }\r
124 \r
125                         @Override\r
126                         public boolean areAllStatesRelevant() {\r
127                                 return true;\r
128                         }\r
129 \r
130                         @Override\r
131                         public Collection<State> relevantStates() {\r
132                                 return null;\r
133                         }\r
134                 }, new AcceptAllResourceAcceptRule(), rootState);\r
135         }\r
136         \r
137         public static ResourceViewpoint createViewpoint() {\r
138                 StateFactory f = new PlainStateFactory();\r
139                 final State rootState = f.newState();\r
140                 final State projectState = f.newState();\r
141                 final State libraryState = f.newState();\r
142                 \r
143                 return new ResourceViewpoint(new TraversalRule() {\r
144                         @Override\r
145                         public TraversalDecision makeTraversalDecision(State state, Statement statement) {\r
146                                 Builtins b = statement.getGraph().getBuiltins();\r
147                                 if (state.equals(rootState)) {\r
148                                         if (statement.getObject().isInstanceOf(b.Ontology))\r
149                                                 return TraversalDecision.stopTraversal;\r
150                                         if(!statement.getPredicate().equals(b.ConsistsOf))\r
151                                                 return TraversalDecision.stopTraversal;\r
152                                         return TraversalDecision.continueTraversal(projectState);\r
153                                 } else if (state.equals(projectState)) {\r
154                                         if(!statement.getPredicate().equals(b.ConsistsOf))\r
155                                                 return TraversalDecision.stopTraversal;\r
156                                         return TraversalDecision.continueTraversal(libraryState);\r
157                                 } else if (state.equals(libraryState)) {\r
158                                         if(!statement.getPredicate().equals(b.ConsistsOf))\r
159                                                 return TraversalDecision.stopTraversal;\r
160                                         return TraversalDecision.continueTraversal(libraryState);\r
161                                 }\r
162                                 return TraversalDecision.stopTraversal;\r
163                         }\r
164                         \r
165                         @Override\r
166                         public boolean areAllStatesRelevant() {\r
167                                 return true;\r
168                         }\r
169                         \r
170                         @Override\r
171                         public Collection<State> relevantStates() {\r
172                                 return null;\r
173                         }\r
174                 }, new AcceptRule<IEntity>() {\r
175                 @Override\r
176                         public AcceptDecision makeAcceptDecision(State state, IEntity obj) {\r
177                                 Builtins b = obj.getGraph().getBuiltins();\r
178                                 //NOSEResource nr = NOSEResource.getInstance(obj.getGraph());\r
179                                 if(obj.isInstanceOf(b.Project)) return AcceptDecision.REJECT;\r
180                                 else if (obj.isInstanceOf(b.Ontology)) return AcceptDecision.REJECT;\r
181                                 else return AcceptDecision.ACCEPT;\r
182                         }\r
183                 \r
184                         @Override\r
185                         public boolean areAllStatesRelevant() {\r
186                                 return true;\r
187                         }\r
188                         \r
189                         @Override\r
190                         public Collection<State> relevantStates() {\r
191                                 return null;\r
192                         }\r
193                 }, rootState);\r
194         }\r
195 \r
196 }\r