00001
00002
00003
00004
00005
00006
00007
00008 #define MODULE_SELECT 1
00009
00010 #include "design.h"
00011
00012 static void DrawLassoList(HDC hDC);
00013 static void DrawCircle(HDC hDC,int xx, int yy, int x, int y);
00014 static BOOL SelectBezier(void);
00015 static BOOL SelectMappedVertices(int status);
00016 static void DeSelectEvery(void);
00017
00018 static BOOL CALLBACK SelectByColourDlgProc(HWND hdlg,UINT msg,
00019 WPARAM wparam,LPARAM lparam){
00020 switch( msg ) {
00021 case WM_PAINT:
00022 PaintDialogBackground(hdlg,ghinst_main);
00023 break;
00024 case WM_INITDIALOG:
00025 EnableToolPannels(ALL_PANNELS,FALSE);
00026 CentreDialogOnCursor(hdlg);
00027 return (TRUE);
00028 case WM_DESTROY:
00029 EnableToolPannels(ALL_PANNELS,TRUE);
00030 break;
00031 case WM_DRAWITEM:{
00032 HBRUSH hbr,hbrold;
00033 BYTE r,g,b;
00034 LPDRAWITEMSTRUCT lpdis;
00035 lpdis=(LPDRAWITEMSTRUCT)lparam;
00036 if(lpdis->CtlID == DLG_COLSELECT_COLOUR){
00037 r=LastColour[0]; g=LastColour[1]; b=LastColour[2];
00038 if(lpdis->itemState & ODS_SELECTED)
00039 InvertRect(lpdis->hDC,&(lpdis->rcItem));
00040 else{
00041 hbr=CreateSolidBrush(RGB(r,g,b));
00042 hbrold=SelectObject(lpdis->hDC,hbr);
00043 Rectangle(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top,
00044 lpdis->rcItem.right,lpdis->rcItem.bottom);
00045 SelectObject(lpdis->hDC,hbrold);
00046 DeleteObject(hbr);
00047 }
00048 }
00049 }
00050 return TRUE;
00051 case WM_COMMAND:
00052 switch(LOWORD(wparam)){
00053 case DLG_COLSELECT_COLOUR:
00054 SetSfxColour(LastColour,IDX_MISC_CHOOSE_COLOUR,hdlg);
00055 InvalidateRect(GetDlgItem(hdlg,DLG_COLSELECT_COLOUR),NULL,FALSE);
00056 break;
00057 case IDCANCEL:
00058 EndDialog(hdlg,-1);
00059 return(TRUE);
00060 case DLG_COLSELECT_NEAR:
00061 EndDialog(hdlg,1);
00062 return(TRUE);
00063 case IDOK:
00064 EndDialog(hdlg,0);
00065 return(TRUE);
00066 default: break;
00067 }
00068 break;
00069 default: break;
00070 }
00071 return(FALSE);
00072 }
00073
00074 void ExecuteSelect(int item){
00075 long i;
00076 vertex *Vx,*vp;
00077 face *fp;
00078 Vx=NULL;
00079 if(Nvert == 0){
00080 SendPrgmQuery(IDQ_TOOFEWITEMS,0);
00081 return;
00082 }
00083 EDIT_ACTION=YES;
00084 switch(item){
00085 case IDM_EDIT_SELECTMAPPED:
00086 if(!SelectMappedVertices(SELECTED))return;
00087 break;
00088 case IDM_EDIT_DESELECTMAPPED:
00089 if(!SelectMappedVertices(DESELECTED))return;
00090 break;
00091 case IDM_EDIT_SELECTBY_COLOUR:{
00092 int id,i,j,lim=1;
00093 if(Nface == 0){
00094 SendPrgmQuery(IDQ_TOOFEWFACES,0);
00095 return;
00096 }
00097 id=DialogBox(ghinst_main,MAKEINTRESOURCE(DLG_COLSELECT),ghwnd_main,
00098 (DLGPROC)SelectByColourDlgProc);
00099 if(id < 0)return;
00100 if(id == 1)lim=32;
00101 else lim=1;
00102 fp=MainFp; if(MainFp != NULL && Nface > 0)for(i=0;i<Nface;i++){
00103 if(abs(fp->color[0] - LastColour[0]) < lim &&
00104 abs(fp->color[1] - LastColour[1]) < lim &&
00105 abs(fp->color[2] - LastColour[2]) < lim){
00106 for(j=0;j<3;j++){
00107 if((MainVp+fp->V[j])->status == DESELECTED){
00108 (MainVp+fp->V[j])->status=SELECTED;
00109 NvertSelect++; NvertDeselect--;
00110 }
00111 }
00112 }
00113 fp++;
00114 }
00115 }
00116 break;
00117 case IDM_EDIT_SELECTBY_MAP:{
00118 int id,j;
00119 if(Nface == 0)return;
00120 if(nImaps < 1){
00121 SendPrgmQuery(IDQ_NOBRUSH,0);
00122 return;
00123 }
00124 else if(nImaps > 1){
00125 if((id=RequestMapID(ghwnd_main,"Select by Map",0)) < 0)return;
00126 }
00127 else id=0;
00128 fp=MainFp; if(MainFp != NULL && Nface > 0)for(i=0;i<Nface;i++){
00129 if( (int)(fp->imagemap) == id){
00130 for(j=0;j<3;j++){
00131 if((MainVp+fp->V[j])->status == DESELECTED){
00132 (MainVp+fp->V[j])->status=SELECTED;
00133 NvertSelect++; NvertDeselect--;
00134 }
00135 }
00136 }
00137 fp++;
00138 }
00139 }
00140 break;
00141 case IDM_EDIT_SELECTBY_SHADER:{
00142 int id,j;
00143 if(Nface == 0)return;
00144 if(nMats == 1)id=0;
00145 else{
00146 id=RequestMaterialID(ghwnd_main,"Select by Material");
00147 if(id < 0)return;
00148 }
00149 fp=MainFp; if(MainFp != NULL && Nface > 0)for(i=0;i<Nface;i++){
00150 if((int)(fp->material) == id){
00151 for(j=0;j<3;j++){
00152 if((MainVp+fp->V[j])->status == DESELECTED){
00153 (MainVp+fp->V[j])->status=SELECTED;
00154 NvertSelect++; NvertDeselect--;
00155 }
00156 }
00157 }
00158 fp++;
00159 }
00160 }
00161 break;
00162 case IDM_EDIT_SELECTBY_BEZIER:
00163 if(!SelectBezier())return;
00164 break;
00165 case IDM_EDIT_SELECTBY_INVIEW:
00166 case IDM_EDIT_SELECTBY_OUTVIEW:
00167 vp=MainVp; if(MainVp != NULL && Nvert > 0)for(i=0;i<Nvert;i++){
00168 if(vp->status != HIDDEN){
00169 if(intriview(vp)){
00170 if(item == IDM_EDIT_SELECTBY_INVIEW && vp->status == DESELECTED){
00171 vp->status=SELECTED; NvertSelect++; NvertDeselect--;
00172 }
00173 }
00174 else{
00175 if(item == IDM_EDIT_SELECTBY_OUTVIEW && vp->status == DESELECTED){
00176 vp->status=SELECTED; NvertSelect++; NvertDeselect--;
00177 }
00178 }
00179 }
00180 vp++;
00181 }
00182 break;
00183 case IDM_EDIT_SELECTCONNECT:
00184 SelectConnected(SELECTED);
00185 return;
00186 case IDM_EDIT_DESELECTCONNECT:
00187 SelectConnected(DESELECTED);
00188 return;
00189 case IDM_EDIT_DESELECT_EVERY:
00190 DeSelectEvery();
00191 break;
00192 case IDM_EDIT_SELECTALL:
00193 case IDM_EDIT_DESELECTALL:
00194 case IDM_EDIT_SWAPSELECT:
00195 vp=MainVp; if(MainVp != NULL && Nvert > 0)for(i=0;i<Nvert;i++){
00196 if(item == IDM_EDIT_SELECTALL &&
00197 vp->status != HIDDEN && vp->status==DESELECTED){
00198 vp->status=SELECTED; NvertSelect++; NvertDeselect--;
00199 }
00200 else if(item == IDM_EDIT_DESELECTALL &&
00201 vp->status != HIDDEN && vp->status==SELECTED){
00202 vp->status=DESELECTED; NvertSelect--; NvertDeselect++;
00203 }
00204 else if(item == IDM_EDIT_SWAPSELECT && vp->status != HIDDEN){
00205 if(vp->status==SELECTED){
00206 vp->status=DESELECTED; NvertSelect--; NvertDeselect++;
00207 }
00208 else{
00209 vp->status=SELECTED; NvertSelect++; NvertDeselect--;
00210 }
00211 }
00212 vp++;
00213 }
00214 break;
00215 default: break;
00216 }
00217 DrawVerticesOnly(Vx);
00218 UpdateCounters();
00219 }
00220
00221 void ExecuteHide(BOOL hide){
00222 long i;
00223 vertex *vp;
00224 vp=MainVp; if(MainVp != NULL && Nvert > 0)for(i=0;i<Nvert;i++){
00225 if(hide){
00226 if(vp->status==SELECTED){
00227 vp->status=HIDDEN; NvertSelect--; NvertDeselect++;
00228 }
00229 }
00230 else{
00231 if(vp->status==HIDDEN)vp->status=DESELECTED;
00232 }
00233 vp++;
00234 }
00235 }
00236
00237 void SelectConnected(int status){
00238 HCURSOR lhcurSave;
00239 vertex *vp,*vf,*V0,*V1;
00240 edge *ep;
00241 long range;
00242 int i,sho,svo,shp,svp,flag;
00243 double d,dmin,drange;
00244 if(sktool)return;
00245 EDIT_ACTION=YES;
00246 dmin=(double)TVsizeY*(double)TVsizeX*(double)TVsizeZ;
00247 vp=MainVp;
00248 vf=NULL;
00249 if(MainVp != NULL && Nvert > 0)for(i=0;i<Nvert;i++){
00250 if(vp->status != HIDDEN && intriview(vp)){
00251 GetWindowCoords(ActiveView,
00252 vp->xyz[0],vp->xyz[1],vp->xyz[2],&sho,&svo);
00253 GetWindowCoords(ActiveView,
00254 NpointerX,NpointerY,NpointerZ,&shp,&svp);
00255 if(abs(sho-shp) < 4 && abs(svo-svp) <4){
00256 d=(double)(vp->xyz[0]-NpointerX)*(double)(vp->xyz[0]-NpointerX)
00257 +(double)(vp->xyz[1]-NpointerY)*(double)(vp->xyz[1]-NpointerY)
00258 +(double)(vp->xyz[2]-NpointerZ)*(double)(vp->xyz[2]-NpointerZ);
00259 if(d < dmin){
00260 dmin=d;
00261 vf=vp;
00262 }
00263 }
00264 }
00265 vp->id=0;
00266 vp++;
00267 }
00268 if((vp=vf) != NULL){
00269 vp->status=status; vp->id=1;
00270 if(Nvert > 10000)lhcurSave=SetCursor(ghcurWait);
00271 flag=1;
00272 while(flag){
00273 flag=0;
00274 ep=MainEp; for(i=0;i<Nedge;i++){
00275 V0=(MainVp+ep->V[0]);
00276 V1=(MainVp+ep->V[1]);
00277 if(V0->id == 1 && V1->id != 1 && V1->status != HIDDEN){
00278 V1->id = 1; flag=1;
00279 }
00280 if(V1->id == 1 && V0->id != 1 && V0->status != HIDDEN){
00281 V0->id = 1; flag=1;
00282 }
00283 ep++;
00284 }
00285 }
00286 NvertSelect=0;
00287 vp=MainVp; if(MainVp != NULL && Nvert > 0)for(i=0;i<Nvert;i++){
00288 if(vp->id == 1)vp->status = status;
00289 if(vp->status == SELECTED)NvertSelect++;
00290 vp++;
00291 }
00292 NvertDeselect=Nvert-NvertSelect;
00293 if(Nvert > 10000)SetCursor(lhcurSave);
00294 DrawVerticesOnly(NULL);
00295 UpdateCounters();
00296 }
00297 }
00298
00299 void SelectConnectedTo(long id){
00300 BOOL bExtended;
00301 int status,istatus;
00302 HCURSOR lhcurSave;
00303 vertex *vp,*V0,*V1;
00304 edge *ep;
00305 long range;
00306 int i,flag;
00307 vp=(MainVp+id);
00308 if(vp->status == SELECTED){status=DESELECTED; istatus=SELECTED;}
00309 else {status=SELECTED; istatus=DESELECTED;}
00310 vp->status=status; vp->id=1;
00311 if(GetKeyState(VK_SHIFT) & 0x8000)bExtended=TRUE;
00312 else bExtended=FALSE;
00313 if(Nvert > 10000)lhcurSave=SetCursor(ghcurWait);
00314 flag=1;
00315 while(flag){
00316 flag=0;
00317 ep=MainEp; for(i=0;i<Nedge;i++){
00318 V0=(MainVp+ep->V[0]);
00319 V1=(MainVp+ep->V[1]);
00320 if(V0->id == 1 && V1->id != 1 && V1->status != HIDDEN){
00321 V1->id = 1; flag=1;
00322 }
00323 if(V1->id == 1 && V0->id != 1 && V0->status != HIDDEN){
00324 V0->id = 1; flag=1;
00325 }
00326 ep++;
00327 }
00328 }
00329 NvertSelect=0;
00330 vp=MainVp; if(MainVp != NULL && Nvert > 0)for(i=0;i<Nvert;i++){
00331 if(vp->id == 1)vp->status = status;
00332
00333
00334 if(vp->status == SELECTED)NvertSelect++;
00335 vp++;
00336 }
00337 NvertDeselect=Nvert-NvertSelect;
00338 if(Nvert > 10000)SetCursor(lhcurSave);
00339 DrawVerticesOnly(NULL);
00340 UpdateCounters();
00341 }
00342
00343 long SelectVertex(int criteria, int cx, int cy){
00344 vertex *vp,*vf;
00345 double d,dmin,drange;
00346 int i,sho,svo;
00347 long id;
00348 if(sktool)return -1;
00349 EDIT_ACTION=YES;
00350 vp=MainVp; vf=NULL; id= -1;
00351 dmin=(double)TVsizeX*(double)TVsizeY*(double)TVsizeZ;
00352 drange=dmin/32/32/32;
00353 if(grid_on){
00354 GetWindowCoords(ActiveView,NpointerX,NpointerY,NpointerZ,&cx,&cy);
00355 }
00356 if(MainVp != NULL && Nvert > 0)for(vp=MainVp,i=0;i<Nvert;i++,vp++){
00357 if(intriview(vp)){
00358 if(criteria == 0){
00359 d=(double)(vp->xyz[0]-NpointerX)*(double)(vp->xyz[0]-NpointerX)
00360 +(double)(vp->xyz[1]-NpointerY)*(double)(vp->xyz[1]-NpointerY)
00361 +(double)(vp->xyz[2]-NpointerZ)*(double)(vp->xyz[2]-NpointerZ);
00362 if(d < dmin){
00363 dmin=d;
00364 if(d < drange){vf=vp; id=(long)i;}
00365 }
00366 }
00367 else{
00368 GetWindowCoords(ActiveView,
00369 vp->xyz[0],vp->xyz[1],vp->xyz[2],&sho,&svo);
00370 if( (sho > cx-4) && (sho < cx+4) && (svo > cy-4) && (svo < cy+4)){
00371 d=(double)(vp->xyz[0]-NpointerX)*(double)(vp->xyz[0]-NpointerX)
00372 +(double)(vp->xyz[1]-NpointerY)*(double)(vp->xyz[1]-NpointerY)
00373 +(double)(vp->xyz[2]-NpointerZ)*(double)(vp->xyz[2]-NpointerZ);
00374 if(d < dmin){
00375 dmin=d;
00376 vf=vp;
00377 id=(long)i;
00378 }
00379 }
00380 }
00381 }
00382 }
00383 if(vf != NULL){
00384 if(vf->status==SELECTED){
00385 NvertSelect--;
00386 NvertDeselect++;
00387 vf->status=DESELECTED;
00388 }
00389 else{
00390 NvertSelect++;
00391 NvertDeselect--;
00392 vf->status=SELECTED;
00393 }
00394 DrawVerticesOnly(vf);
00395 UpdateCounters();
00396 }
00397 return id;
00398 }
00399
00400 static int selector_xx,selector_x,selector_yy,selector_y,
00401 selector_type,n_lasso=0;
00402 static HDC hDCselector;
00403 static POINT *lasso_list=NULL;
00404
00405
00406 static void DrawCircle(HDC hDC, int xx, int yy, int x, int y){
00407 int cx,cy,radius;
00408 cx=(x+xx)/2; cy=(y+yy)/2;
00409 radius=(int)(sqrt((double)(x-cx)*(double)(x-cx)
00410 +(double)(y-cy)*(double)(y-cy)));
00411 if(radius > 0)Ellipse(hDC,cx-radius,cy-radius,
00412 cx+radius,cy+radius);
00413 }
00414
00415 void DrawLassoList(HDC hDC){
00416 long i;
00417 if(n_lasso > 0 && lasso_list != NULL){
00418 MoveToEx(hDC,lasso_list[0].x,lasso_list[0].y,NULL);
00419 if(n_lasso > 1)for(i=1;i<n_lasso;i++){
00420 LineTo(hDC,lasso_list[i].x,lasso_list[i].y);
00421 }
00422 LineTo(hDC,lasso_list[0].x,lasso_list[0].y);
00423 }
00424 return;
00425 }
00426
00427 void SelectorDown(HWND hwnd, int view, int x, int y){
00428 HDC hdc;
00429 selector_x=selector_xx=x; selector_y=selector_yy=y;
00430 if(view < 0)selector_type=0;
00431 else if(GetAsyncKeyState(VK_CONTROL) & 0x8000)selector_type=1;
00432 else if(GetAsyncKeyState(VK_SHIFT) & 0x8000)selector_type=2;
00433 else selector_type=0;
00434 hDCselector=GetDC(hwnd);
00435 SelectObject(hDCselector,GetStockObject(NULL_BRUSH));
00436 if(tool == SELECTOR)SelectObject(hDCselector,ghSelectorPen);
00437 else SelectObject(hDCselector,ghDeselectorPen);
00438 SetROP2(hDCselector,R2_XORPEN);
00439 SelectPalette(hDCselector,ghpaletteScreen,FALSE);
00440 RealizePalette(hDCselector);
00441 if(view >= 0)DrawOne3dCursor(hDCselector,view);
00442 if(selector_type == 0)Rectangle(hDCselector,
00443 selector_xx,selector_yy,
00444 selector_x,selector_y);
00445 else if(selector_type == 2){
00446 if((lasso_list=(POINT *)X__Malloc(sizeof(point))) != NULL){
00447 lasso_list[0].x=x; lasso_list[0].y=y;
00448 n_lasso=1;
00449 DrawLassoList(hDCselector);
00450 }
00451 }
00452 else DrawCircle(hDCselector,selector_xx,selector_yy,selector_x,selector_y);
00453 if(view >= 0)DrawOne3dCursor(hDCselector,view);
00454 }
00455
00456 void SelectorMove(HWND hwnd, int view, int x, int y){
00457 if(view >= 0)DrawOne3dCursor(hDCselector,view);
00458 if(selector_type == 0)Rectangle(hDCselector,selector_xx,selector_yy,selector_x,selector_y);
00459 else if(selector_type == 2)DrawLassoList(hDCselector);
00460 else DrawCircle(hDCselector,selector_xx,selector_yy,selector_x,selector_y);
00461 selector_x=x; selector_y=y;
00462 if(selector_type == 2){
00463 POINT *pt;
00464 pt=X__Realloc(lasso_list,(n_lasso+1)*sizeof(POINT));
00465 if(pt != NULL){
00466 pt[n_lasso].x=x; pt[n_lasso].y=y; n_lasso++;
00467 lasso_list=pt;
00468 }
00469 }
00470 if(selector_type == 0)Rectangle(hDCselector,selector_xx,selector_yy,selector_x,selector_y);
00471 else if(selector_type == 2)DrawLassoList(hDCselector);
00472 else DrawCircle(hDCselector,selector_xx,selector_yy,selector_x,selector_y);
00473 if(view >= 0)DrawOne3dCursor(hDCselector,view);
00474 }
00475
00476 void SelectorUp(HWND hwnd, int view, int x, int y,
00477 BOOL bFlagMoved, BOOL bFlagNodeTool){
00478 if(view >= 0)DrawOne3dCursor(hDCselector,view);
00479 if(selector_type == 0)Rectangle(hDCselector,selector_xx,selector_yy,selector_x,selector_y);
00480 else if(selector_type == 2){
00481 DrawLassoList(hDCselector);
00482 }
00483 else DrawCircle(hDCselector,selector_xx,selector_yy,selector_x,selector_y);
00484 if(view >= 0)DrawOne3dCursor(hDCselector,view);
00485 ReleaseDC(hwnd,hDCselector);
00486 if(!bFlagMoved){
00487 if(lasso_list != NULL){
00488 X__Free(lasso_list);
00489 n_lasso=0; lasso_list=NULL;
00490 }
00491 return;
00492 }
00493 if(view < 0)SelectInPerspective(tool,selector_xx,selector_x
00494 ,selector_yy,selector_y);
00495 else if(selector_type < 2){
00496 vertex *vp;
00497 int i,sx,sy,cx,cy,xl,yt,xr,yb;
00498 double radius1,radius2;
00499 xl=min(selector_x,selector_xx); xr=max(selector_x,selector_xx);
00500 yt=min(selector_y,selector_yy); yb=max(selector_y,selector_yy);
00501 if(selector_type == 0){
00502 vp=MainVp; if(MainVp != NULL && Nvert > 0)for(i=0;i<Nvert;i++){
00503 if(!intriview(vp))goto NEXT;
00504 GetWindowCoords(view,vp->xyz[0],vp->xyz[1],vp->xyz[2],&sx,&sy);
00505 if((sx < xl) || (sx > xr) || (sy < yt) || (sy > yb))goto NEXT;
00506 if(tool == SELECTOR && vp->status == DESELECTED){
00507 vp->status=SELECTED;
00508 NvertSelect++; NvertDeselect--;
00509 }
00510 else if(tool == DESELECTOR && vp->status==SELECTED){
00511 vp->status=DESELECTED;
00512 NvertSelect--; NvertDeselect++;
00513 }
00514 NEXT:
00515 vp++;
00516 }
00517 if(Nnurbs > 0)SelectNurbsInRectangle(tool,bFlagNodeTool,xl,xr,yt,yb);
00518 }
00519 else{
00520 cx = (xl+xr)/2; cy = (yt+yb)/2;
00521 radius1 = (sqrt((double)(xl-cx)*(double)(xl-cx)
00522 +(double)(yt-cy)*(double)(yt-cy)));
00523 vp=MainVp; if(MainVp != NULL && Nvert > 0)for(i=0;i<Nvert;i++){
00524 if(!intriview(vp))goto NEXT1;
00525 GetWindowCoords(view,vp->xyz[0],vp->xyz[1],vp->xyz[2],&sx,&sy);
00526 radius2 = (sqrt((double)(sx-cx)*(double)(sx-cx)
00527 +(double)(sy-cy)*(double)(sy-cy)));
00528 if(radius2 > radius1)goto NEXT1;
00529 if(tool == SELECTOR && vp->status == DESELECTED){
00530 vp->status=SELECTED;
00531 NvertSelect++; NvertDeselect--;
00532 }
00533 else if(tool == DESELECTOR && vp->status==SELECTED){
00534 vp->status=DESELECTED;
00535 NvertSelect--; NvertDeselect++;
00536 }
00537 NEXT1:
00538 vp++;
00539 }
00540 if(Nnurbs > 0)SelectNurbsInCircle(tool,bFlagNodeTool,cx,cy,radius1);
00541 }
00542 }
00543 else if(selector_type == 2){
00544 if(lasso_list != NULL){
00545 vertex *vp;
00546 int i,sx,sy;
00547 HRGN hrgn;
00548 if((hrgn=CreatePolygonRgn(lasso_list,n_lasso,WINDING)) != NULL){
00549 vp=MainVp; if(MainVp != NULL && Nvert > 0)for(i=0;i<Nvert;i++){
00550 if(!intriview(vp))goto NEXT2;
00551 GetWindowCoords(view,vp->xyz[0],vp->xyz[1],vp->xyz[2],&sx,&sy);
00552 if(!PtInRegion(hrgn,sx,sy))goto NEXT2;
00553 if(tool == SELECTOR && vp->status == DESELECTED){
00554 vp->status=SELECTED;
00555 NvertSelect++; NvertDeselect--;
00556 }
00557 else if(tool == DESELECTOR && vp->status==SELECTED){
00558 vp->status=DESELECTED;
00559 NvertSelect--; NvertDeselect++;
00560 }
00561 NEXT2:
00562 vp++;
00563 }
00564 if(Nnurbs > 0)SelectNurbsInLasso(tool,bFlagNodeTool,hrgn);
00565 DeleteObject(hrgn);
00566 }
00567 X__Free(lasso_list);
00568 n_lasso=0; lasso_list=NULL;
00569 }
00570 }
00571 if(Nnurbs > 0)DrawModel();
00572 else DrawVerticesOnly(NULL);
00573 UpdateCounters();
00574 }
00575
00576 void SnapCursorTo(int item){
00577 static point cursor_memory={0,0,0};
00578 char status;
00579 int i,id=0;
00580 point p,TVp;
00581 double d,dmin,x,y,z;
00582 vertex *vp,*vc=NULL;
00583 p[0]=NpointerX; p[1]=NpointerY; p[2]=NpointerZ; vc=NULL;
00584 dmin=(double)TVsizeX*(double)TVsizeY*(double)TVsizeZ;
00585 switch (item){
00586 case IDM_SNAP_CLOSEST:
00587 if((vp=MainVp) != NULL)for(i=0;i<Nvert;i++){
00588 d=(double)(vp->xyz[0]-NpointerX)*(double)(vp->xyz[0]-NpointerX)
00589 +(double)(vp->xyz[1]-NpointerY)*(double)(vp->xyz[1]-NpointerY)
00590 +(double)(vp->xyz[2]-NpointerZ)*(double)(vp->xyz[2]-NpointerZ);
00591 if(d < dmin){dmin=d; vc=vp;}
00592 vp++;
00593 }
00594 if(vc != NULL){
00595 p[0]=vc->xyz[0]; p[1]=vc->xyz[1]; p[2]=vc->xyz[2];
00596 }
00597 else{
00598 p[0]=NpointerX; p[1]=NpointerY; p[2]=NpointerZ;
00599 }
00600 id=1;
00601 break;
00602 case IDM_SNAP_CLOSESELECT:
00603 if(NvertSelect == 0)break;
00604 if((vp=MainVp) != NULL)for(i=0;i<Nvert;i++){
00605 if(vp->status == SELECTED){
00606 d=(double)(vp->xyz[0]-NpointerX)*(double)(vp->xyz[0]-NpointerX)
00607 +(double)(vp->xyz[1]-NpointerY)*(double)(vp->xyz[1]-NpointerY)
00608 +(double)(vp->xyz[2]-NpointerZ)*(double)(vp->xyz[2]-NpointerZ);
00609 if(d < dmin){dmin=d; vc=vp;}
00610 }
00611 vp++;
00612 }
00613 if(vc != NULL){
00614 p[0]=vc->xyz[0]; p[1]=vc->xyz[1]; p[2]=vc->xyz[2];
00615 }
00616 else{
00617 p[0]=NpointerX; p[1]=NpointerY; p[2]=NpointerZ;
00618 }
00619 id=1;
00620 break;
00621 case IDM_SNAP_MIDPOINT:
00622 get_centre(1,p,TVp,TRUE);
00623 id=1;
00624 break;
00625 case IDM_SNAP_MIDSELECT:
00626 if(NvertSelect == 0)break;
00627 get_centre(1,p,TVp,FALSE);
00628 id=1;
00629 break;
00630 case IDM_SNAP_CENTROID:
00631 get_centre(0,p,TVp,TRUE);
00632 id=1;
00633 break;
00634 case IDM_SNAP_HPLANE:
00635 if(NvertSelect > 0)get_centre(2,p,TVp,FALSE);
00636 else get_centre(2,p,TVp,TRUE);
00637 id=1;
00638 break;
00639 case IDM_SNAP_VPLANERL:
00640 if(NvertSelect > 0)get_centre(4,p,TVp,FALSE);
00641 else get_centre(4,p,TVp,TRUE);
00642 id=1;
00643 break;
00644 case IDM_SNAP_VPLANEFB:
00645 if(NvertSelect > 0)get_centre(3,p,TVp,FALSE);
00646 else get_centre(3,p,TVp,TRUE);
00647 id=1;
00648 break;
00649 case IDM_SNAP_STORE:
00650 cursor_memory[0]=NpointerX;
00651 cursor_memory[1]=NpointerY;
00652 cursor_memory[2]=NpointerZ;
00653 id=0;
00654 break;
00655 case IDM_SNAP_TOSTORED:
00656 p[0]=cursor_memory[0];
00657 p[1]=cursor_memory[1];
00658 p[2]=cursor_memory[2];
00659 id=1;
00660 break;
00661 case IDM_SNAP_TOCOORD:
00662 x=(double)(NpointerX-lrulerx)/ruler;
00663 y=(double)(NpointerY-lrulery)/ruler;
00664 z=(double)(NpointerZ-lrulerz)/ruler;
00665 if(fabs(x) > 999999 || fabs(y) > 999999 || fabs(z) > 999999){
00666 SendPrgmQuery(IDQ_COORDTOOBIG,0);
00667 break;
00668 }
00669 if(Read3Reals("To Coordinate",&x,&y,&z,0) == 0)break;
00670 p[0]=(long)(x*ruler)+lrulerx;
00671 p[1]=(long)(y*ruler)+lrulery;
00672 p[2]=(long)(z*ruler)+lrulerz;
00673 id=1;
00674 break;
00675 case IDM_SNAP_INCREMENT:
00676 x=y=z=0.0;
00677 if(Read3Reals("Move by",&x,&y,&z,0) == 0)break;
00678 p[0]=(long)(x*ruler)+NpointerX;
00679 p[1]=(long)(y*ruler)+NpointerY;
00680 p[2]=(long)(z*ruler)+NpointerZ;
00681 id=1;
00682 break;
00683 default:
00684 break;
00685 }
00686 if(id){
00687 if( (p[0] > TVpointX && p[0] < TVpointX+TVsizeX)
00688 && (p[1] > TVpointY && p[1] < TVpointY+TVsizeY)
00689 && (p[2] > TVpointZ && p[2] < TVpointZ+TVsizeZ)){
00690 Draw3dCursor();
00691 NpointerX=p[0]; NpointerY=p[1]; NpointerZ=p[2];
00692 Draw3dCursor();
00693 }
00694 else{
00695 NpointerX=p[0]; NpointerY=p[1]; NpointerZ=p[2];
00696 TVpointX=NpointerX-TVsizeX/2; TVcentreX=NpointerX;
00697 TVpointY=NpointerY-TVsizeY/2; TVcentreY=NpointerY;
00698 TVpointZ=NpointerZ-TVsizeZ/2; TVcentreZ=NpointerZ;
00699 DrawModel();
00700 }
00701 }
00702 SendMessage(ghwndCoord1,WM_COMMAND,IDC_COORD_UPDATE,0);
00703 return;
00704 }
00705
00706 static BOOL SelectBezier(void){
00707 long i;
00708 int id,redraw=0;
00709 char **bezier_list;
00710 vertex *Vp;
00711 if(N_Bcurves > 0){
00712 if((bezier_list=(char **)X__Malloc(N_Bcurves*sizeof(char *))) == NULL){
00713 SendPrgmQuery(IDQ_NOMEM2,0);
00714 return FALSE;
00715 }
00716 for(i=0;i<N_Bcurves;i++)bezier_list[i]=Bcurves[i].name;
00717 id=SelectScrolledItemList((int)N_Bcurves,bezier_list,"Which Curve",ghwnd_main);
00718 if(id >= 0){
00719 if(Bcurves[id].Vc != NULL)for(i=0;i<Bcurves[id].Nc;i++){
00720 Vp=(MainVp+Bcurves[id].Vc[i]);
00721 if(Vp->status == DESELECTED){
00722 Vp->status = SELECTED;
00723 NvertDeselect--; NvertSelect++;
00724 redraw=1;
00725 }
00726 }
00727 if(Bcurves[id].Vp != NULL)for(i=0;i<Bcurves[id].Np;i++){
00728 Vp=(MainVp+Bcurves[id].Vp[i]);
00729 if(Vp->status == DESELECTED){
00730 Vp->status = SELECTED;
00731 NvertDeselect--; NvertSelect++;
00732 redraw=1;
00733 }
00734 }
00735 }
00736 X__Free(bezier_list);
00737 if(redraw)return TRUE;
00738 }
00739 return FALSE;
00740 }
00741
00742 static BOOL SelectMappedVertices(int status){
00743 long i;
00744 vertex *vp;
00745 vp=MainVp;
00746 if(status == SELECTED){
00747 for(i=0;i<Nvert;i++){
00748 if(vp->status == DESELECTED && vp->gp > 0){
00749 NvertSelect++; NvertDeselect--;
00750 vp->status = SELECTED;
00751 }
00752 vp++;
00753 }
00754 }
00755 else if(status == DESELECTED){
00756 for(i=0;i<Nvert;i++){
00757 if(vp->status == SELECTED && vp->gp > 0){
00758 NvertSelect--; NvertDeselect++;
00759 vp->status = DESELECTED;
00760 }
00761 vp++;
00762 }
00763 }
00764 return TRUE;
00765 }
00766
00767 long PickVertex(void){
00768 vertex *Vp;
00769 long vp,vf;
00770 double d,dmin;
00771 int sho,svo,V,H;
00772 vp=0;
00773 vf=-1;
00774 dmin=(double)TVsizeY*(double)TVsizeY*(double)TVsizeZ;
00775 GetWindowCoords(ActiveView,NpointerX,NpointerY,NpointerZ,&H,&V);
00776 while(vp < Nvert){
00777 Vp=(MainVp+vp);
00778 if(intriview(Vp)){
00779 GetWindowCoords(ActiveView,Vp->xyz[0],Vp->xyz[1],Vp->xyz[2],&sho,&svo);
00780 if( (sho > H-4) && (sho < H+4) && (svo > V-4) && (svo < V+4)){
00781 d=(double)(Vp->xyz[0]-NpointerX)*(double)(Vp->xyz[0]-NpointerX)
00782 +(double)(Vp->xyz[1]-NpointerY)*(double)(Vp->xyz[1]-NpointerY)
00783 +(double)(Vp->xyz[2]-NpointerZ)*(double)(Vp->xyz[2]-NpointerZ);
00784 if(d < dmin){
00785 dmin=d;
00786 vf=vp;
00787 }
00788 }
00789 }
00790 Vp->id=0;
00791 vp++;
00792 }
00793 return vf;
00794 }
00795
00796 static void DeSelectEvery(void){
00797 vertex *Vp;
00798 long vp,vf,every=1,count=1;
00799 if(NvertSelect < 1 || NvertSelect > 32000)return;
00800 if((vf=get_closest_vertex()) < 0)return;
00801 if((every=RequestNumEntry((short)every,1,100,"De-select","Gap")) < 0)return;
00802 (MainVp+vf)->id=1;
00803 vp=0; while(vp < Nvert){
00804 Vp=(MainVp+vp);
00805 if(Vp->status == SELECTED && Vp->id == 0 && connected(vf,vp)){
00806 Vp->id=1;
00807 if(count == every){
00808 Vp->status=DESELECTED;
00809 NvertSelect--; NvertDeselect++; count=0;
00810 }
00811 else count++;
00812 vf=vp;
00813 vp=0;
00814 }
00815 else vp++;
00816 }
00817 return;
00818 }