Hallo,
das ich nicht gleich oder sofort den Quellcode herstellen kann liegt daran: Arbeit ==> Proficam ==> kein Forum
zuhause ==> Internet ==> kein Proficam
Weiter unten dann noch eine Beispieldatei und alles zusammen und mehr Beispiele im .ZIP-Packet.
Also hier:
/**********************************************************************/
#include "std.h"
#include "megatyp.h"
#include "megacad.h"
/**********************************************************************/
short vorz;
short linienart;
short linienfarb;
char rein[200];
double aktx=0;
double akty=0;
double akti=0;
double aktk=0;
short aktg=0;
double altx=0;
double alty=0;
/********************************************************************/
void zurliste( short listenp, char *was)
{ short cwritten;
static int zeile=0;
zeile++;
ML_Printf(listenp,"No.%4d %s\n",zeile,was);
return(0);
}
/********************************************************************/
static void setxy(short lip)
{
short a,vor,plus,retgart;
long d;
double h,alx,aly,lesx,lesy,lesi,lesk;
char tex[200];
char buf[200];
d=0;
h=0.0;
plus=0;
vor=0;
lesx=0;
lesy=0;
lesi=0;
lesk=0;
alx=aktx;
aly=akty;
retgart=aktg;
strcpy(tex,rein);
for ( a=0; ; a++ )
{
if ( tex[a] == '+' ) { plus=1; vor++;d=0;h=0;}
if ( tex[a] == '-' ) { plus=0;vor++;d=0;h=0;}
// Fehlende Null am Ende z.B. +1234+
if ( tex[a] == '\0' ) {
if ( tex[a-1] == '+' ) {if ( vor == 2 ) { lesy=0; } }
if ( tex[a-1] == '-' ) {if ( vor == 2 ) { lesy=0; } }
}
// ende fehlende 0
if ( tex[a] == '\0' ) {d=akty; break;}
if ( tex[a] >= '0' && tex[a] <= '9' ) { d=10*d+tex[a]-'0'; h = d;}
if ( plus == 1) { h=h; } else { h = (h *(-1));}
if ( vor == 1 ) lesx = h/10;
if ( vor == 2 ) lesy = h/10;
if ( vor == 3 ) lesi = h/10;
if ( vor == 4 ) lesk = h/10;
if ( vor == 5 ) {if (plus == 1) {aktg=3; } else { aktg = 2;} } else {aktg=retgart;}
}
aktx=(alx)+(lesx);
akty=(aly)+(lesy);
akti=(alx)+(lesi);
aktk=(aly)+(lesk);
sprintf(buf,"setxy vorz %d aktx %+7.2f akty %+7.2f akti %+7.2f aktk %+7.2f richt %d |%s",vorz,aktx,akty,akti,aktk,aktg,rein);
zurliste(lip,buf);
}
/********************************************************************/
void setz_farbe()
{
t_attribs attr;
// aktuellen Attribute für das Element Linie ermitteln
GetAttributes(E_LINE,&attr);
attr.lay = 102;
if ( linienart == 0) attr.stl = 2;
if ( linienart == 1) attr.stl = 1;
if ( linienfarb == 1) attr.col = YELLOW ;
if ( linienfarb == 2) attr.col = BLUE ;
if ( linienfarb == 3) attr.col = GREEN ;
if ( linienfarb == 4) attr.col = YELLOW ;
// die neuen Attribute setzen
SetAttributes(E_LINE,&attr);
}
/********************************************************************/
static void linie(
double ax,
double ay,
double ex,
double ey)
{
char buf[200];
t_line li;
li.x1=ax;
li.y1=ay;
li.x2=ex;
li.y2=ey;
setz_farbe();
CreateEntity(E_LINE,NULL,&li,NULL,NULL,NULL);
savecount();
}
/********************************************************************/
static void kreis(
double ax,
double ay,
double ex,
double ey,
short lip)
{
double ra,h,g,aw,ew,ret;
char buf[200];
short startq,stopq;
static double max=0.0;
static double min=0.0;
t_c_arc bog;
//double xm; // x-coordinate of mid point
//double ym; // y-coordinate of mid point
//double rd; // radius
//double a1; // start angle
//double a2; // end angle
ra=1.111;h=2.222;g=3.333;ret=0.0;
aw=1.111;ew=2.22;
startq=0;stopq=0;
sprintf(buf,"1KREIS g%f h%f ra%f",g,h,ra);
zurliste(lip,buf);
h=(altx)-(akti);
g=(alty)-(aktk);
sprintf(buf,"1KREIS g%f h%f ra%f",g,h,ra);
zurliste(lip,buf);
g=fabs(g);
h=fabs(h);
sprintf(buf,"2KREIS g%f h%f ra%f",g,h,ra);
zurliste(lip,buf);
ra=(h*h)+(g*g);
sprintf(buf,"3KREIS g%f h%f ra%f",g,h,ra);
zurliste(lip,buf);
ra=(sqrt(ra));
sprintf(buf,"Radius berechnet 4KREIS g%f h%f ra%f",g,h,ra);
zurliste(lip,buf);
// Anfangswinkel
h = ((altx)-(akti));
g = h/ra;
if ( g <= (-1)) { h=0; } else { h=acos(g); }
if ( g >= 1) { h=0; } else { h=acos(g); }
g=h;
aw = g ;
// Endwinkel ??
g=((aktx)-(akti));
h=g/ra;
if ( h < min ) min=h;
if ( h > max ) max=h;
sprintf(buf,"aKREIS %f %f g%f h%f ra%f min%2.9f max %2.9f",aktx,akti,g,h,ra,min,max);
zurliste(lip,buf);
if ( h <= (-1)) { g=0; } else { g=acos(h); }
if ( h >= 1) { g=0; } else { g=acos(h); }
h= g;
ew=h;
sprintf(buf,"KREIS Mx %f My %f RAD %f Aw %f EW %f ",akti,aktk,ra,aw,ew);
zurliste(lip,buf);
// Startquadranten ermitteln
ret=DEF_PI-aw;
if (altx > akti ) {
if (alty > aktk) {startq=1;}
if (alty < aktk) {startq=4;aw=ret+DEF_PI;}
if (alty == aktk) {startq=6;}
}
if (altx == akti ) {
if (alty > aktk) {startq=7;}
if (alty < aktk) {startq=9;aw=ret+DEF_PI;}
}
if (altx < akti ) {
if (alty > aktk) {startq=2;}
if (alty < aktk) {startq=3;aw=ret+DEF_PI;}
if (alty == aktk) {startq=8;}
}
// Stopquadranten ermitteln
ret=DEF_PI-ew;
if (aktx > akti ) {
if (akty > aktk) {stopq=1;}
if (akty < aktk) {stopq=4; ew=ret+DEF_PI;}
if (akty == aktk) {stopq=6;}
}
if (aktx == akti ) {
if (akty > aktk) {stopq=7;}
if (akty < aktk) {stopq=9;ew=ret+DEF_PI;}
}
if (aktx < akti ) {
if (akty > aktk) {stopq=2;}
if (akty < aktk) {stopq=3;ew=ret+DEF_PI;}
if (akty == aktk) {stopq=8;}
}
if ( aktg == 2 ) {
// hier den drehsinn tauschen
ret=ew;
ew=aw;
aw=ret;
}
setz_farbe();
sprintf(buf,"KREIS Mx %f My %f RAD %f Aw %f EW %f startq%d stopq%d",akti,aktk,ra,aw,ew,startq,stopq);
zurliste(lip,buf);
bog.xm = akti;
bog.ym = aktk;
bog.rd = ra;
bog.a1 = aw;
bog.a2 = ew;
CreateEntity(E_C_ARC,NULL,&bog,NULL,NULL,NULL);
savecount();
}
/********************************************************************/
static void wertezuweisen(
char *hil)
{
char tex[200];
char buf[200];
short a,b;
b=0;
vorz=0;
strcpy(tex,hil);
for ( a=0; ; a++ )
{
if ( tex[a] == ' ' ) { continue;}
if ( tex[a] == '+' ) { vorz++; rein[b]=tex[a];b++;rein[b]='\0';}
if ( tex[a] == '-' ) { vorz++;rein[b]=tex[a];b++;rein[b]='\0';}
if ( tex[a] == '\0' ) { break;rein[b]=tex[a];b++;rein[b]='\0';}
// hier RESTzeile sauber retten
if ( tex[a] >= '0' && tex[a] <= '9' ) { rein[b]=tex[a];b++;rein[b]='\0';}
}
}
/********************************************************************/
static void tausch()
{
altx=aktx;
alty=akty;
}
/********************************************************************/
short main(
char *filename,
char *args )
{
char *fpret;
char fname[200];
char neuname[200];
char buf[200];
char hil[200];
double mpd;
short butret, mret ,listenp, fp , a , b , wayout = FALSE , kommentar=0;
/********************************************************************/
t_attribs alte_line_attribute;
t_attribs alte_krei_attribute;
t_text txtdata;
char str[255];
char partno[255];
GetAttributes(E_LINE,&alte_line_attribute);
GetAttributes(E_C_ARC,&alte_krei_attribute);
strcpy(fname,"G:\\prod\\cnc\\DATEN\\block\\ncb_neu\\*.nc");
GetFilename("Datei ausw„hlen",fname);
fp = ML_Open(fname,ML_READ);
if ( fp == 0 ) {butret = Message("Konnte Datei nicht oeffnen",fname,"knopf1","Knopf2","Knopf3",3);
exit; }
//Koordinatendatein oeffnen
strcpy(buf,"C:\\tmp\\koordinaten.txt");
listenp = ML_Open(buf, ML_WRITE | ML_TEXT);
if ( listenp == 0 ) {butret = Message("Konnte Datei nicht oeffnen",buf,"knopf1","Knopf2","Knopf3",3);
exit; }
sprintf(buf,"Datei: %s ",fname);
zurliste(listenp,buf);
while(wayout == FALSE)
{
fpret = ML_Gets(hil,200,fp) ;
if ( fpret == NULL ) {ML_Close(fp); fp=0; wayout = TRUE;}
if ( fp == 0 ) {butret = Message("DATEIENDEEREICHT",fname,"knopf1","Knopf2","Knopf3",3); }
// Partno in der ersten Zeile weglesen und speichern
if((hil[0]=='P')&&(hil[1]=='A')&&(hil[2]=='R')&&(hil[3]=='T')&&(hil[4]=='N')&&(hil[5]=='O')) {strcpy(partno,hil); zurliste(listenp,partno); continue;
} // ende Partno speichern
wertezuweisen(hil);
if ( vorz == 0 ) { if ( strcmp(rein,"3") == NULL ) {kommentar=1; } }
if ( vorz == 0 ) { if ( strcmp(rein,"4") == NULL ) {kommentar=0; } }
if ( kommentar == 1 ) continue;
if ( vorz == 0 ) { if ( strcmp(rein,"5") == NULL ) {linienart=0; aktg=0;} }
if ( vorz == 0 ) { if ( strcmp(rein,"6") == NULL ) {linienart=1; aktg=1;} }
if ( vorz == 0 ) { if ( strcmp(rein,"7") == NULL ) {linienfarb=1; } }
if ( vorz == 0 ) { if ( strcmp(rein,"56") == NULL ){linienfarb=2; } }
if ( vorz == 0 ) { if ( strcmp(rein,"57") == NULL ){linienfarb=3; } }
if ( vorz == 0 ) { if ( strcmp(rein,"8") == NULL ) {linienfarb=4; } }
if ( vorz == 0 ) {sprintf(buf," Zeile %s",rein); zurliste(listenp,buf); }
if ( vorz == 2 ) {setxy(listenp);linie(altx,alty,aktx,akty);tausch();}
if ( vorz == 5 ) {setxy(listenp);kreis(altx,alty,aktx,akty,listenp); tausch();}
butret=1;
switch(butret)
{
case 1:
break;
case 2:
break;
case 3:
break;
default:
Message("Auáerhalb gedrckt","",NULL,NULL,"ok",3);
wayout = TRUE;
break;
}
}
SetAttributes(E_LINE,&alte_line_attribute);
SetAttributes(E_C_ARC,&alte_krei_attribute);
ML_Close(fp);
ML_Close(listenp);
}
/**********************************************************************/
Eine Beispieldatei:
PARTNO
39+850
5
+3500+0
-10000+10000
6
57
7
-3500+3500-3500++
+-3500
+3000+
-2500+2958-3000++
+-2458
+1949+
-1949+1949-2449-500+
8
5
-500+1050
6
57
7
-3500-3500+-3500+
+3500+
++3000
-2958-2500+-3000+
+2458+
++1949
-1949-1949+500-2449+
8
5
-1050-500
6
39+850
57
7
+3500-3500+3500++
++3500
-3000+
+2500-2958+3000++
++2458
-1949+
+1949-1949+2449+500+
8
5
+500-1050
6
39+850
57
7
+3500+3500++3500+
-3500+
+-3000
+2958+2500++3000+
-2458+
+-1949
+1949+1949-500+2449+
8
0
63
bis dann
Ulli
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP