Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nomad-3d-commons
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Instrument Control
Protos
Nomad 3D
nomad-3d-commons
Commits
1b5f93f4
"MDANSE/Framework/Widgets/InstrumentResolutionWidget.py" did not exist on "9f2e95ddde1401576011f7e81d0c9ffbe0449a04"
Commit
1b5f93f4
authored
7 years ago
by
dages
Browse files
Options
Downloads
Patches
Plain Diff
axis builder : doc
parent
86444383
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/fr/ill/ics/gui/AxisBuilder.java
+139
-108
139 additions, 108 deletions
src/main/java/fr/ill/ics/gui/AxisBuilder.java
with
139 additions
and
108 deletions
src/main/java/fr/ill/ics/gui/AxisBuilder.java
+
139
−
108
View file @
1b5f93f4
package
fr.ill.ics.gui
;
import
fr.ill.ics.model.Axis
;
import
fr.ill.ics.model.Component
;
import
javafx.geometry.Point2D
;
import
javafx.geometry.Point3D
;
import
javafx.scene.Group
;
import
javafx.scene.paint.Color
;
import
javafx.scene.transform.NonInvertibleTransformException
;
import
javafx.scene.transform.Rotate
;
/**
* Class for creating and placing axes.
* @author dages
*/
public
class
AxisBuilder
{
public
static
final
Color
buildingColor
=
Color
.
color
(
0
,
1
,
0.8
);
private
Axis
axis
;
private
Group
parentGroup
;
private
Point2D
mousePos
=
null
;
private
Point2D
mouseOldPos
=
null
;
/**
* Default constructor.
*/
public
AxisBuilder
()
{
this
.
axis
=
null
;
this
.
parentGroup
=
null
;
}
public
void
start
(
Axis
axis
,
Group
parentGroup
,
CameraControls
controls
,
boolean
modified
)
{
this
.
axis
=
axis
;
this
.
axis
.
setDirection
(
new
Point3D
(
0
,
1
,
0
));
this
.
axis
.
setPosition
(
controls
.
getCenter
());
try
{
this
.
axis
.
setSceneToParent
(
parentGroup
.
getLocalToSceneTransform
().
createInverse
());
}
catch
(
NonInvertibleTransformException
e
)
{
e
.
printStackTrace
();
}
this
.
axis
.
getVisualGroup
().
setVisible
(
true
);
this
.
parentGroup
=
parentGroup
;
if
(!
modified
)
{
parentGroup
.
getChildren
().
add
(
this
.
axis
.
getVisualGroup
());
}
this
.
axis
.
getVisualGroup
().
setOnMousePressed
(
me
->
{
mousePos
=
new
Point2D
(
me
.
getSceneX
(),
me
.
getSceneY
());
mouseOldPos
=
new
Point2D
(
me
.
getSceneX
(),
me
.
getSceneY
());
});
this
.
axis
.
getVisualGroup
().
setOnMouseDragged
(
me
->
{
mouseOldPos
=
mousePos
;
mousePos
=
new
Point2D
(
me
.
getSceneX
(),
me
.
getSceneY
());
Point2D
delta
=
mousePos
.
subtract
(
mouseOldPos
);
Point3D
screenAxisDir3D
=
controls
.
getTransform
().
deltaTransform
(
axis
.
getDirection
());
Point2D
screenAxisDir
=
new
Point2D
(
screenAxisDir3D
.
getX
(),
screenAxisDir3D
.
getY
());
Point3D
viewDir
=
controls
.
viewDirection
();
double
angle
=
screenAxisDir
.
angle
(
delta
);
while
(
angle
<
0
)
angle
+=
360
;
while
(
angle
>
180
)
angle
-=
180
;
angle
=
(
angle
/
90
)
-
1
;
if
(
Math
.
abs
(
angle
)
<
1
)
{
angle
=
Math
.
exp
(-
1
/(
1
-
angle
*
angle
));
}
else
{
angle
=
0
;
}
angle
*=
delta
.
magnitude
()
*
-
Math
.
signum
(
delta
.
dotProduct
(
screenAxisDir
.
getY
(),
-
screenAxisDir
.
getX
()));
angle
*=
controls
.
modifier
(
me
.
isControlDown
(),
me
.
isShiftDown
());
rotate
(
viewDir
,
angle
);
});
}
public
void
setType
(
Axis
.
Type
type
)
{
this
.
axis
.
setType
(
type
);
}
public
void
translate
(
Point3D
destination
)
{
if
(
this
.
axis
==
null
)
{
return
;
}
this
.
axis
.
setPosition
(
destination
);
}
public
void
rotate
(
Point3D
axis
,
double
angle
)
{
if
(
this
.
axis
==
null
)
{
return
;
}
Rotate
r
=
new
Rotate
(
angle
,
axis
);
this
.
axis
.
setDirection
(
r
.
transform
(
this
.
axis
.
getDirection
()).
normalize
());
}
public
void
stop
(
boolean
modified
)
{
if
(!
modified
&&
this
.
axis
!=
null
&&
this
.
parentGroup
!=
null
)
{
this
.
parentGroup
.
getChildren
().
remove
(
this
.
axis
.
getVisualGroup
());
}
this
.
axis
=
null
;
this
.
parentGroup
=
null
;
}
public
void
stop
(
Component
component
)
{
component
.
setAxis
(
this
.
axis
.
clone
());
stop
(
true
);
}
}
package
fr.ill.ics.gui
;
import
fr.ill.ics.model.Axis
;
import
fr.ill.ics.model.Component
;
import
javafx.geometry.Point2D
;
import
javafx.geometry.Point3D
;
import
javafx.scene.Group
;
import
javafx.scene.transform.NonInvertibleTransformException
;
import
javafx.scene.transform.Rotate
;
/**
* Class for creating and placing axes.
* @author dages
*/
public
class
AxisBuilder
{
/** Edited axis. */
private
Axis
axis
;
/** Parent of the visual group of the axis. */
private
Group
parentGroup
;
/** Mouse position, used when dragging the mouse. */
private
Point2D
mousePos
=
null
;
/** Mouse old position, used when dragging the mouse. */
private
Point2D
mouseOldPos
=
null
;
/**
* Default constructor.
*/
public
AxisBuilder
()
{
this
.
axis
=
null
;
this
.
parentGroup
=
null
;
}
/**
* Starts the axis editing.
* @param axis Axis to edit
* @param parentGroup Parent of the visual group of the axis
* @param controls Camera controls
* @param modified true if the axis is modified, false if it added
*/
public
void
start
(
Axis
axis
,
Group
parentGroup
,
CameraControls
controls
,
boolean
modified
)
{
this
.
axis
=
axis
;
this
.
axis
.
setDirection
(
new
Point3D
(
0
,
1
,
0
));
this
.
axis
.
setPosition
(
controls
.
getCenter
());
try
{
this
.
axis
.
setSceneToParent
(
parentGroup
.
getLocalToSceneTransform
().
createInverse
());
}
catch
(
NonInvertibleTransformException
e
)
{
e
.
printStackTrace
();
}
this
.
axis
.
getVisualGroup
().
setVisible
(
true
);
this
.
parentGroup
=
parentGroup
;
if
(!
modified
)
{
parentGroup
.
getChildren
().
add
(
this
.
axis
.
getVisualGroup
());
}
this
.
axis
.
getVisualGroup
().
setOnMousePressed
(
me
->
{
mousePos
=
new
Point2D
(
me
.
getSceneX
(),
me
.
getSceneY
());
mouseOldPos
=
new
Point2D
(
me
.
getSceneX
(),
me
.
getSceneY
());
});
this
.
axis
.
getVisualGroup
().
setOnMouseDragged
(
me
->
{
mouseOldPos
=
mousePos
;
mousePos
=
new
Point2D
(
me
.
getSceneX
(),
me
.
getSceneY
());
Point2D
delta
=
mousePos
.
subtract
(
mouseOldPos
);
Point3D
screenAxisDir3D
=
controls
.
getTransform
().
deltaTransform
(
axis
.
getDirection
());
Point2D
screenAxisDir
=
new
Point2D
(
screenAxisDir3D
.
getX
(),
screenAxisDir3D
.
getY
());
Point3D
viewDir
=
controls
.
viewDirection
();
double
angle
=
screenAxisDir
.
angle
(
delta
);
while
(
angle
<
0
)
angle
+=
360
;
while
(
angle
>
180
)
angle
-=
180
;
angle
=
(
angle
/
90
)
-
1
;
if
(
Math
.
abs
(
angle
)
<
1
)
{
angle
=
Math
.
exp
(-
1
/(
1
-
angle
*
angle
));
}
else
{
angle
=
0
;
}
angle
*=
delta
.
magnitude
()
*
-
Math
.
signum
(
delta
.
dotProduct
(
screenAxisDir
.
getY
(),
-
screenAxisDir
.
getX
()));
angle
*=
controls
.
modifier
(
me
.
isControlDown
(),
me
.
isShiftDown
());
rotate
(
viewDir
,
angle
);
});
}
/**
* Sets the type of the edited axis.
* @param type New type
*/
public
void
setType
(
Axis
.
Type
type
)
{
this
.
axis
.
setType
(
type
);
}
/**
* Translates the axis.
* @param destination Position of the axis once the translation is over, in global coordinate system
*/
public
void
translate
(
Point3D
destination
)
{
if
(
this
.
axis
==
null
)
{
return
;
}
this
.
axis
.
setPosition
(
destination
);
}
/**
* Rotates the axis.
* @param axis Rotation axis, in global coordinate system
* @param angle Rotation angle
*/
public
void
rotate
(
Point3D
axis
,
double
angle
)
{
if
(
this
.
axis
==
null
)
{
return
;
}
Rotate
r
=
new
Rotate
(
angle
,
axis
);
this
.
axis
.
setDirection
(
r
.
transform
(
this
.
axis
.
getDirection
()).
normalize
());
}
/**
* Stops the axis editing.
* @param modified true if the axis was modified, false if it was added
*/
public
void
stop
(
boolean
modified
)
{
if
(!
modified
&&
this
.
axis
!=
null
&&
this
.
parentGroup
!=
null
)
{
this
.
parentGroup
.
getChildren
().
remove
(
this
.
axis
.
getVisualGroup
());
}
this
.
axis
=
null
;
this
.
parentGroup
=
null
;
}
/**
* Stops the axis editing and store the axis.
* @param component Owner of the modified axis
*/
public
void
stop
(
Component
component
)
{
component
.
setAxis
(
this
.
axis
.
clone
());
stop
(
true
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment