Esempio n. 1
0
 def Activated(self):
   # start properties window
   OSPropWind.showProps();
Esempio n. 2
0
def UpdateFunction():
  OSPropWind.hideProps();
  doc=FreeCAD.ActiveDocument;
  if (hasattr(doc,'OSData')==True):
    osd=doc.OSData;
    # full count
    FC=int(osd.getContents("B1"));
    # ray count
    RC=int(osd.getContents("C1"));
    # fill up labels
    # Optical objects
    j=4;
    while (j<RC-1):
      name1=osd.getContents(cl[3]+str(j));
      #label1=osd.getContents(cl[4]+str(j));
      if ((hasattr(doc,name1)==False)):
        osd.removeRows(str(j),1);
        # new full count
        FC=int(osd.getContents("B1"))-1;
        osd.set("B1",str(FC));
        # new ray count
        RC=int(osd.getContents("C1"))-1;
        osd.set("C1",str(RC));
        # numbers - 1
        for k in xrange(j,RC-1):
          osd.set("A"+str(k),str(int(osd.getContents('A'+str(k)))-1));
        # end for
        doc.recompute();
        j=4; # start loop again to delet another elements if needed
        continue;
      else:
        ob1=doc.getObject(name1);
        # Update Base
        v1=ob1.Placement.Base;
        if (str(v1.x)!=osd.getContents(cl[5]+str(j))):
          osd.set(cl[5]+str(j),str(v1.x));
        # end if
        if (str(v1.y)!=osd.getContents(cl[6]+str(j))):
          osd.set(cl[6]+str(j),str(v1.y));
        # end if
        if (str(v1.z)!=osd.getContents(cl[7]+str(j))):
          osd.set(cl[7]+str(j),str(v1.z));
        # end if
        # Update Rotation
        A1=ob1.Placement.Rotation.toEuler();
        if (str(A1[2])!=osd.getContents(cl[8]+str(j))):
          osd.set(cl[8]+str(j),str(A1[2]));
        # end if
        if (str(A1[1])!=osd.getContents(cl[9]+str(j))):
          osd.set(cl[9]+str(j),str(A1[1]));
        # end if
        if (str(A1[0])!=osd.getContents(cl[10]+str(j))):
          osd.set(cl[10]+str(j),str(A1[0]));
        # end if
        # Update Aperture
        if (hasattr(ob1,'Radius')==True):
          Ap1=2.*ob1.Radius.Value;
          if (str(Ap1)!=float(osd.getContents(cl[11]+str(j)))):
            osd.set(cl[11]+str(j),str(Ap1));
          # end if
        # end if
        # Update Length
        if (hasattr(ob1,'Length')==True):
          l1=ob1.Height.Value;
          if (str(l1)!=osd.getContents(cl[12]+str(j))):
            osd.set(cl[12]+str(j),str(l1));
          # end if
        # end if
        # Update Height
        if (hasattr(ob1,'Height')==True):
          h1=ob1.Height.Value;
          if (str(h1)!=osd.getContents(cl[13]+str(j))):
            osd.set(cl[13]+str(j),str(h1));
          # end if
        # end if
        # Update Thickness
        if ((ob1.Name).find('IPLT')!=-1):
          t1=(ob1.Shapes[0].Placement.Base-ob1.Shapes[1].Placement.Base).Length;
          if (str(t1)!=osd.getContents(cl[17]+str(j))):
            osd.set(cl[17]+str(j),str(t1));
          # end if
        # end if
      j=j+1;
    # end while

    # Rays
    j=RC+2;
    while (j<FC+1):
      ray1=osd.getContents(cl[3]+str(j));
      if (hasattr(doc,ray1)==False):
        osd.removeRows(str(j),1);
        FC=int(osd.getContents("B1"));
        osd.set("B1",str(FC-1));
        FreeCAD.Console.PrintMessage(str(j)+", "+str(FC-1)+"\n");
        # new full count
        FC=int(osd.getContents("B1"));
        # numbers - 1
        for k in xrange(j,FC+1):
          osd.set("A"+str(k),str(int(osd.getContents('A'+str(k)))-1));
        # end for
        doc.recompute();
        j=RC+2; # start loop again to delet another rays if needed
        continue;
      else:
        ob1=doc.getObject(ray1);
        # Update Base
        v1=ob1.Placement.Base;
        if (str(v1.x)!=osd.getContents(cl[5]+str(j))):
          osd.set(cl[5]+str(j),str(v1.x));
        # end if
        if (str(v1.y)!=osd.getContents(cl[6]+str(j))):
          osd.set(cl[6]+str(j),str(v1.y));
        # end if
        if (str(v1.z)!=osd.getContents(cl[7]+str(j))):
          osd.set(cl[7]+str(j),str(v1.z));
        # end if
        # Update Rotation
        A1=ob1.Placement.Rotation.toEuler();
        if (str(A1[2])!=osd.getContents(cl[8]+str(j))):
          osd.set(cl[8]+str(j),str(A1[2]));
        # end if
        if (str(A1[1])!=osd.getContents(cl[9]+str(j))):
          osd.set(cl[9]+str(j),str(A1[1]));
        # end if
        if (str(A1[0])!=osd.getContents(cl[10]+str(j))):
          osd.set(cl[10]+str(j),str(A1[0]));
        # end if
        # Update Color
        c1=ob1.ViewObject.LineColor;
        if (str(c1)!=osd.getContents(cl[12]+str(j))):
          osd.set(cl[12]+str(j),str(c1));
        # end if
        # Update Length
        l1=ob1.Shape.Length;
        if (str(l1)!=osd.getContents(cl[13]+str(j))):
          osd.set(cl[13]+str(j),str(l1));
        # end if
      j=j+1;
    # end while
  # end if
  doc.recompute();
  FreeCAD.Console.PrintMessage("Optical System was updated\n");