cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Fit component of an assembly to the screen

ysinitsin
12-Amethyst

Fit component of an assembly to the screen

Hello!


I'm stuck in one task in using J-Link.


I want fit the part to screen, which was selected by the mouse in the tree. Or, just, pan this part to center of the screen without zooming.


my code:


sel_options = pfcSelect.SelectionOptions_Create("membfeat");


selections = session.Select(sel_options, null);


SelItem = selections.get(0);


ComponentPath cp = SelItem.GetPath();


Transform3D tr3d_part = cp.GetTransform(true);


View vw = session.GetCurrentModel().GetCurrentView();


Transform3D tr3d = vw.GetTransform();


//Get origen of the selected part


st.SetZoom(1.0);


hPan = scale_x;


double vPan = scale_y;


st.SetPanX(hPan);


st.SetPanY(vPan);


cur_wind.SetScreenTransform(st);


cur_wind.Refresh();



The code are working not bad, if Zoom is 1. But if the Zoom <> 1, then the selected part fly out from the center of the screen.


I noticed that if the Zoom != 1 then PanX=0 and PanY=0 it is not a center of screen, as in the case of Zoom = 1.


Any help?





This thread is inactive and closed by the PTC Community Management Team. If you would like to provide a reply and re-open this thread, please notify the moderator and reference the thread. You may also use "Start a topic" button to ask a new question. Please be sure to include what version of the PTC product you are using so another community member knowledgeable about your version may be able to assist.
5 REPLIES 5
FV
17-Peridot
17-Peridot
(To:ysinitsin)

Hello all,


Yaroslav,


Those are transformations which one would have to apply to get a point expressed in terms of the inertia coordinate system to be shown at the center of thePro/E window.


Let's say that the screen center point is at {500.0,400.0, 0.0} ( screen coordinate system) and view to screen transformation is identity matrix {{1,0,0,0}, {0,1,0,0}, {0,0,1,0},{0,0,0,1}}


-get selected component


- gettransformationfrom component to assembly coordinates


- get selected point in component coordinates


- transform point to assembly coordinates


- get view transformation


- apply desired window scale to theview->screen transformation


- invertview->screen transformation


- transform point from assembly coordinates to view coordinates using view transformation


- transform screen center point to view coordinates using invertedscreen->view transformation


- calculate displacement from point to screen center in view coordinates


- transform displacement vector from view coordinates to screen coordinates usingview->screen transformation.


- add the displacement vector to the displacement vector of the view->screen transformation


- apply view->screen transformation to the window



HIH.


Feliks.

In Reply to Yaroslav Sinitsyn:



Hello!


I'm stuck in one task in using J-Link.


I want fit the part to screen, which was selected by the mouse in the tree. Or, just, pan this part to center of the screen without zooming.


my code:


sel_options = pfcSelect.SelectionOptions_Create("membfeat");


selections = session.Select(sel_options, null);


SelItem = selections.get(0);


ComponentPath cp = SelItem.GetPath();


Transform3D tr3d_part = cp.GetTransform(true);


View vw = session.GetCurrentModel().GetCurrentView();


Transform3D tr3d = vw.GetTransform();


//Get origen of the selected part


st.SetZoom(1.0);


hPan = scale_x;


double vPan = scale_y;


st.SetPanX(hPan);


st.SetPanY(vPan);


cur_wind.SetScreenTransform(st);


cur_wind.Refresh();



The code are working not bad, if Zoom is 1. But if the Zoom <> 1, then the selected part fly out from the center of the screen.


I noticed that if the Zoom != 1 then PanX=0 and PanY=0 it is not a center of screen, as in the case of Zoom = 1.


Any help?





Hello, Feliks!


Thank you very much for the reply!But I still need some help.


What I do:



-get selected component


sel_options = pfcSelect.SelectionOptions_Create("part");


selections = session.Select(sel_options, null);


SelItem = selections.get(0);


Transform3D component_transform = cp.GetTransform(true);


- transform point to assembly coordinates




- get view transformation


View vw = SelItem.GetSelModel().GetCurrentView();


Transform3D view_transform = vw.GetTransform();


- apply desired window scale to theview->screen transformation


I skip this step


- invertview->screen transformation


Transform3D tr3d_inverted = view_transform;


tr3d_inverted.Invert();


- transform point from assembly coordinates to view coordinates using view transformation


pointonmodel= view_transform.TransformPoint(pointonmodel);


- transform screen center point to view coordinates using invertedscreen->view transformation


Point3D screen_center = Point3D.create();


screen_center.set(0, 500);


screen_center.set(0, 432);


screen_center.set(0, 0);


- calculate displacement from point to screen center in view coordinates


Point3D delta = Point3D.create();


delta.set(0, pointonmodel.get(0) - screen_center.get(0));


delta.set(1, pointonmodel.get(1) - screen_center.get(1));


delta.set(2, pointonmodel.get(2) - screen_center.get(2));


FV
17-Peridot
17-Peridot
(To:ysinitsin)

Hello all,


Yaroslav,


Pro/Toolkit has two functions:


ProWindowPanZoomMatrixSet()





which we are using toget/settransformationsbetween model view coordinatesand screen coordinates. Somebody with J-Link experience should pitch in ...





But what I'm seeing from your sampe - there are no calls to get and set screen transformations, there were only calls related to model-view transformations.


The step you had skipped sets the scale to view-to-screen matrix, you could leave it at identity state but it has to be used, ommition creates errors in the next statements - you are applying view-to-model transformations to ahard coded screen center point, insteadyou have to apply screen-to-view transformations to get screen centerpointmapped to view coordinates.


Another error is in displacement calculations, if you need to calculate a displacement vector (AB)from arbitrary point (A)to a fix point (B) the displacement vector AB calculated as A + AB = B; AB = B -A.What you are doing isthe opposite of this.


HIH.


Feliks.




In Reply to Yaroslav Sinitsyn:




Hello, Feliks!


Thank you very much for the reply!But I still need some help.


What I do:



-get selected component


sel_options = pfcSelect.SelectionOptions_Create("part");


selections = session.Select(sel_options, null);


SelItem = selections.get(0);


Transform3D component_transform = cp.GetTransform(true);


- transform point to assembly coordinates




- get view transformation


View vw = SelItem.GetSelModel().GetCurrentView();


Transform3D view_transform = vw.GetTransform();


- apply desired window scale to theview->screen transformation


I skip this step


- invertview->screen transformation


Transform3D tr3d_inverted = view_transform;


tr3d_inverted.Invert();


- transform point from assembly coordinates to view coordinates using view transformation


pointonmodel= view_transform.TransformPoint(pointonmodel);


- transform screen center point to view coordinates using invertedscreen->view transformation


Point3D screen_center = Point3D.create();


screen_center.set(0, 500);


screen_center.set(0, 432);


screen_center.set(0, 0);


- calculate displacement from point to screen center in view coordinates


Point3D delta = Point3D.create();


delta.set(0, pointonmodel.get(0) - screen_center.get(0));


delta.set(1, pointonmodel.get(1) - screen_center.get(1));


delta.set(2, pointonmodel.get(2) - screen_center.get(2));


I think inside the JLink the equivalent functions are Window.ScreenTransformSet(), Window.ScreenTransformGet() where you can set the Zoom and PanX / PanY to your calculated values. Both are from pfcBase in the help pages.


To create your own ScreenTransform use
pfcBase.ScreenTransform_Create(/*optional*/ Double, /*optional*/ Double, /*optional*/ Double);



Best regards,
Eike

Hello all!


Feliks andEike, thank you very much for your help!


I got what I want. Maybe the result will be useful for somebody else.


My working code for J-Link:


//============================================================

public void FitToCenter() {

Selections selections;

SelectionOptions sel_options;

Selection SelItem;

ModelItem mItem;

Surface surfItem;

try {

sel_options = pfcSelect.SelectionOptions_Create("part");

selections = session.Select(sel_options, null);

SelItem = selections.get(0);



//Get the assembly component path for the selected component

ComponentPath cp = SelItem.GetPath();



//Get random point in the solid

Solid sl = (Solid) SelItem.GetSelModel();

ModelItem itm = sl.ListItems(ModelItemType.ITEM_EDGE).get(0);

Edge ed = (Edge) itm;

Point3D pointonmodel = ed.Eval3DData(0).GetPoint();



Point3D screen_point = Point3D.create();



//Get the coordinate transformation matrix for the component to the assembly

Transform3D component_transform = cp.GetTransform(true);



//Transform the selected point into the coordinate system of the top level assembly

screen_point = component_transform.TransformPoint(pointonmodel);

//Get root assembly

Assembly rootassembly = cp.GetRoot();

//Get current view of the assembly

View vw = rootassembly.GetCurrentView();

//Get transformation of the view

Transform3D view_transform = vw.GetTransform();

//Transform the solid model point to screen coordinates

screen_point = view_transform.TransformPoint(screen_point);



//Set size of the screen

Point3D screen_center = Point3D.create();

screen_center.set(0, 1000);

screen_center.set(1, 843);

screen_center.set(2, 0);



//Get current window

Window cur_wind = session.GetCurrentWindow();

//Get screen transformation

ScreenTransform st = cur_wind.GetScreenTransform();



double hPan = st.GetPanX();

double vPan = st.GetPanY();

double zoom = st.GetZoom();



Point3D delta = Point3D.create();

//Calculation for new PanX and PanY

delta.set(0, ((screen_center.get(0))/2 - screen_point.get(0) * zoom)/1000);

delta.set(1, ((screen_center.get(1))/2 - screen_point.get(1) * zoom)/843);



hPan = delta.get(0);

vPan = delta.get(1);



st.SetPanX(hPan);

st.SetPanY(vPan);



cur_wind.SetScreenTransform(st);

cur_wind.Refresh();

} catch (jxthrowable x) {

try {

session.UIShowMessageDialog(x.toString(), null);

} catch (jxthrowable k) {

}

}

}

//============================================================

By the way, for PROTOOLKIT exist an example.
The sample code in the file UgGraphZoomAtPoint.c located at
/protk_appls/pt_userguide/ptu_graphics

I don't test this sample. But I see some difference in Pan calculation. For J-Link PanX and PanY represent the horizontal and vertical movement. Every increment of 1.0 moves the view point one screen width or height. But in sample for C, this calculation looks strange. Maybe, for J-Link and Toolkit need to use different technics.

Best regards.


Announcements
NEW Creo+ Topics: Real-time Collaboration


Top Tags