Exemplo n.º 1
0
        public RenderNodeAction OnViewBegin(ViewNode node)
        {
            View3D view = m_doc.GetElement(node.ViewId) as View3D;

            if (view != null)
            {
                MessageBuffer mb = new MessageBuffer();
                mb.add(view.Id.IntegerValue);
                mb.add(view.Name);
                mb.add(view.Origin);
                mb.add(view.ViewDirection);
                mb.add(view.UpDirection);
                OpenCOVERPlugin.COVER.Instance.sendMessage(mb.buf, OpenCOVERPlugin.COVER.MessageTypes.AddView);
            }

            // Setting our default LoD for the view
            // The scale goes from 0 to 10, but the value close to the edges
            // aren't really that usable, except maybe of experimenting

            node.LevelOfDetail = 5;   // a good middle ground

            return(RenderNodeAction.Proceed);
        }
Exemplo n.º 2
0
        public bool ConnectToOpenCOVER(string host, int port, Autodesk.Revit.DB.Document doc)
        {
            document = doc;
             handler = new externalMessageHandler();
             messageEvent = Autodesk.Revit.UI.ExternalEvent.Create(handler);
             messageQueue = new Queue<COVERMessage>();

             System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("Revit");

             if (0 < processes.Length)
             {
             ApplicationWindow = processes[0].MainWindowHandle;
             }
             try
             {
             if (toCOVER != null)
             {
                 messageThread.Abort(); // stop reading from the old toCOVER connection
                 toCOVER.Close();
                 toCOVER = null;
                 setConnected(false);
             }

             toCOVER = new TcpClient(host, port);
             if (toCOVER.Connected)
             {
                 // Sends data immediately upon calling NetworkStream.Write.
                 toCOVER.NoDelay = true;
                 LingerOption lingerOption = new LingerOption(false, 0);
                 toCOVER.LingerState = lingerOption;

                 NetworkStream s = toCOVER.GetStream();
                 Byte[] data = new Byte[256];
                 data[0] = 1;
                 try
                 {
                     //toCOVER.ReceiveTimeout = 1000;
                     s.Write(data, 0, 1);
                     //toCOVER.ReceiveTimeout = 10000;
                 }
                 catch (System.IO.IOException)
                 {
                     // probably socket closed
                     setConnected(false);
                     return false;
                 }

                 int numRead = 0;
                 try
                 {
                     //toCOVER.ReceiveTimeout = 1000;
                     numRead = s.Read(data, 0, 1);
                     //toCOVER.ReceiveTimeout = 10000;
                 }
                 catch (System.IO.IOException)
                 {
                     // probably socket closed
                     setConnected(false);
                     return false;
                 }

                 List<View3D> views = new List<View3D>(
             new FilteredElementCollector(doc)
               .OfClass(typeof(View3D))
               .Cast<View3D>()
               .Where<View3D>(v =>
             v.CanBePrinted && !v.IsTemplate));
                 int n = views.Count;

                 if (0 == n)
                 {
                     setConnected(false);
                     return false;
                 }
                 MessageBuffer mb = new MessageBuffer();
                 mb.add(n);
                 foreach (View3D v in views)
                 {
                     mb.add(v.Name);
                 }
                 sendMessage(mb.buf, MessageTypes.Views);

                 if (numRead == 1)
                 {
                     setConnected(true);
                     messageThread = new Thread(new ThreadStart(this.handleMessages));

                     // Start the thread
                     messageThread.Start();

                 }

                 return true;
             }
             System.Windows.Forms.MessageBox.Show("Could not connect to OpenCOVER on localhost, port 31821");
             }
             catch
             {

             setConnected(false);
             System.Windows.Forms.MessageBox.Show("Connection error while trying to connect to OpenCOVER on localhost, port 31821");
             }
             return false;
        }
Exemplo n.º 3
0
        private void SendSolid(Autodesk.Revit.DB.Solid geomSolid, Autodesk.Revit.DB.Element elem)
        {
            Autodesk.Revit.DB.Material m = null;
             bool sameMaterial=true;
             int triangles=0;
             bool twoSided=false;

             Autodesk.Revit.DB.FaceArray faces = geomSolid.Faces;
             if (faces.Size == 0)
             {
            return;
             }

             Autodesk.Revit.DB.WallType wallType = elem.Document.GetElement(elem.GetTypeId()) as Autodesk.Revit.DB.WallType; // get element type
             if (wallType != null)
             {
             if (wallType.Kind == Autodesk.Revit.DB.WallKind.Curtain)
            {
               //return; // don't display curtain walls, these are probably fassades with bars and Glazing
            }
             }
             Autodesk.Revit.DB.ElementId materialID;
             materialID = faces.get_Item(0).MaterialElementId;
             foreach (Autodesk.Revit.DB.Face face in faces)
             {
            if (m == null)
            {
                materialID = face.MaterialElementId;
                Autodesk.Revit.DB.Material materialElement = elem.Document.GetElement(face.MaterialElementId) as Autodesk.Revit.DB.Material;

                /* Autodesk.Revit.DB.ElementId appearanceID = materialElement.AppearanceAssetId;
                 Autodesk.Revit.DB.AppearanceAssetElement ae = elem.Document.GetElement(appearanceID) as Autodesk.Revit.DB.AppearanceAssetElement;
                 Autodesk.Revit.Utility.Asset asset = ae.GetRenderingAsset();
                 Autodesk.Revit.DB.ParameterSet ps = ae.Parameters;
                 for (int i = 0; i < asset.Size; i++)
                 {
                     Autodesk.Revit.Utility.AssetProperty ap = asset[i];
                     string pn = ap.Name;
                     string val = ap.ToString();

                     System.Collections.Generic.IList<string> props = ap.GetConnectedPropertiesNames();
                     foreach (string p in props)
                     {
                         string pName = p;
                     }
                 }
                 foreach (Autodesk.Revit.DB.Parameter p in ae.Parameters)
                 {
                     string pName = p.AsString();
                     string val = p.AsValueString();
                 }
                System.Collections.Generic.IList<Autodesk.Revit.Utility.AssetProperty> props2 = asset.GetAllConnectedProperties();*/
                m = materialElement;
               twoSided = face.IsTwoSided;
            }
            Autodesk.Revit.DB.Mesh geomMesh = face.Triangulate();
            if (geomMesh != null)
            {
               triangles += geomMesh.NumTriangles;
               if (materialID != face.MaterialElementId)
               {
                  sameMaterial = false;
                  break;
               }
            }
             }
             if (triangles == 0)
            return;
             if (sameMaterial)
             {
            MessageBuffer mb = new MessageBuffer();
            mb.add(elem.Id.IntegerValue);
            mb.add(elem.Name + "_combined");
            mb.add((int)ObjectTypes.Mesh);
            mb.add(twoSided);
            mb.add(triangles);

            int i = 0;

            foreach (Autodesk.Revit.DB.Face face in geomSolid.Faces)
            {
               Autodesk.Revit.DB.Mesh geomMesh = face.Triangulate();
               if (geomMesh != null)
               {
                  for (i = 0; i < geomMesh.NumTriangles; i++)
                  {
                     Autodesk.Revit.DB.MeshTriangle triangle = default(Autodesk.Revit.DB.MeshTriangle);
                     triangle = geomMesh.get_Triangle(i);
                     mb.add((float)triangle.get_Vertex(0).X);
                     mb.add((float)triangle.get_Vertex(0).Y);
                     mb.add((float)triangle.get_Vertex(0).Z);
                     mb.add((float)triangle.get_Vertex(1).X);
                     mb.add((float)triangle.get_Vertex(1).Y);
                     mb.add((float)triangle.get_Vertex(1).Z);
                     mb.add((float)triangle.get_Vertex(2).X);
                     mb.add((float)triangle.get_Vertex(2).Y);
                     mb.add((float)triangle.get_Vertex(2).Z);
                  }
               }
            }

            if (m == null)
            {
               mb.add((byte)220); // color
               mb.add((byte)220);
               mb.add((byte)220);
               mb.add((byte)255);
               mb.add(-1); // material ID
            }
            else
            {
               mb.add(m.Color);
               mb.add((byte)(((100 - (m.Transparency)) / 100.0) * 255));
               mb.add(m.Id.IntegerValue);
            }
            sendMessage(mb.buf, MessageTypes.NewObject);
             }
             else
             {
            int num = 0;
            foreach (Autodesk.Revit.DB.Face face in geomSolid.Faces)
            {
               Autodesk.Revit.DB.Mesh geomMesh = face.Triangulate();
               if (geomMesh != null)
               {
                  MessageBuffer mb = new MessageBuffer();
                  mb.add(elem.Id.IntegerValue);
                  mb.add(elem.Name + "_f_" + num.ToString());
                  mb.add((int)ObjectTypes.Mesh);

                  SendMesh(geomMesh, ref mb, face.IsTwoSided);
                  if (face.MaterialElementId == Autodesk.Revit.DB.ElementId.InvalidElementId)
                  {
                     mb.add((byte)220); // color
                     mb.add((byte)220);
                     mb.add((byte)220);
                     mb.add((byte)255);
                     mb.add(-1); // material ID
                  }
                  else
                  {
                      Autodesk.Revit.DB.Material materialElement = elem.Document.GetElement(face.MaterialElementId) as Autodesk.Revit.DB.Material;

                     mb.add(materialElement.Color);
                     mb.add((byte)(((100 - (materialElement.Transparency)) / 100.0) * 255));
                     mb.add(materialElement.Id.IntegerValue);
                  }
                  sendMessage(mb.buf, MessageTypes.NewObject);
               }
               num++;
            }
             }

             //Autodesk.Revit.DB.Edge Edge = default(Autodesk.Revit.DB.Edge);
             //foreach (var Edge in geomSolid.Edges)
             //{
             //   DrawEdge(Edge);
             //}
        }
Exemplo n.º 4
0
        /// <summary>
        /// send a mesh to OpenCOVER.
        /// </summary>
        /// <param name="geomMesh"></param>
        /// <remarks></remarks>
        private void SendMesh(Autodesk.Revit.DB.Mesh geomMesh, ref MessageBuffer mb, bool twoSided)
        {
            int i = 0;
             mb.add(twoSided);
             mb.add(geomMesh.NumTriangles);

             for (i = 0; i < geomMesh.NumTriangles; i++)
             {
            Autodesk.Revit.DB.MeshTriangle triangle = default(Autodesk.Revit.DB.MeshTriangle);
            triangle = geomMesh.get_Triangle(i);
            mb.add((float)triangle.get_Vertex(0).X);
            mb.add((float)triangle.get_Vertex(0).Y);
            mb.add((float)triangle.get_Vertex(0).Z);
            mb.add((float)triangle.get_Vertex(1).X);
            mb.add((float)triangle.get_Vertex(1).Y);
            mb.add((float)triangle.get_Vertex(1).Z);
            mb.add((float)triangle.get_Vertex(2).X);
            mb.add((float)triangle.get_Vertex(2).Y);
            mb.add((float)triangle.get_Vertex(2).Z);
             }
        }
Exemplo n.º 5
0
Arquivo: COVER.cs Projeto: nixz/covise
        void handleMessage(MessageBuffer buf, int msgType,Document doc,UIDocument uidoc)
        {
            // create Avatar object if not present
             /* if (avatarObject == null)
              {
              createAvatar(doc,uidoc);
              }*/
              switch ((MessageTypes)msgType)
              {
              case MessageTypes.SetParameter:
                  {
                      int elemID = buf.readInt();
                      int paramID = buf.readInt();

                      Autodesk.Revit.DB.ElementId id = new Autodesk.Revit.DB.ElementId(elemID);
                      Autodesk.Revit.DB.Element elem = document.GetElement(id);

                      foreach (Autodesk.Revit.DB.Parameter para in elem.Parameters)
                      {
                          if (para.Id.IntegerValue == paramID)
                          {

                              switch (para.StorageType)
                              {
                                  case Autodesk.Revit.DB.StorageType.Double:
                                      double d = buf.readDouble();
                                      try
                                      {
                                          para.Set(d);
                                      }
                                      catch
                                      {
                                          Autodesk.Revit.UI.TaskDialog.Show("Double", "para.Set failed");
                                      }
                                      d = para.AsDouble();
                                      break;
                                  case Autodesk.Revit.DB.StorageType.ElementId:
                                      //find out the name of the element
                                      int tmpid = buf.readInt();
                                      Autodesk.Revit.DB.ElementId eleId = new Autodesk.Revit.DB.ElementId(tmpid);
                                      try
                                      {
                                          para.Set(eleId);
                                      }
                                      catch
                                      {
                                          Autodesk.Revit.UI.TaskDialog.Show("Double", "para.Set failed");
                                      }
                                      break;
                                  case Autodesk.Revit.DB.StorageType.Integer:
                                      try
                                      {
                                          para.Set(buf.readInt());
                                      }
                                      catch
                                      {
                                          Autodesk.Revit.UI.TaskDialog.Show("Double", "para.Set failed");
                                      }
                                      break;
                                  case Autodesk.Revit.DB.StorageType.String:
                                      try
                                      {
                                          para.Set(buf.readString());
                                      }
                                      catch
                                      {
                                          Autodesk.Revit.UI.TaskDialog.Show("Double", "para.Set failed");
                                      }
                                      break;
                                  default:
                                      try
                                      {
                                          para.SetValueString(buf.readString());
                                      }
                                      catch
                                      {
                                          Autodesk.Revit.UI.TaskDialog.Show("Double", "para.Set failed");
                                      }
                                      break;
                              }

                          }
                      }
                  }
                  break;
              case MessageTypes.SetTransform:
                  {
                      int elemID = buf.readInt();
                      double x = buf.readDouble();
                      double y = buf.readDouble();
                      double z = buf.readDouble();

                      Autodesk.Revit.DB.ElementId id = new Autodesk.Revit.DB.ElementId(elemID);
                      Autodesk.Revit.DB.Element elem = document.GetElement(id);
                      Autodesk.Revit.DB.XYZ translationVec = new Autodesk.Revit.DB.XYZ(x, y, z);
                      Autodesk.Revit.DB.LocationCurve ElementPosCurve = elem.Location as Autodesk.Revit.DB.LocationCurve;
                      if (ElementPosCurve != null)
                          ElementPosCurve.Move(translationVec);
                      Autodesk.Revit.DB.LocationPoint ElementPosPoint = elem.Location as Autodesk.Revit.DB.LocationPoint;
                      if (ElementPosPoint != null)
                          ElementPosPoint.Move(translationVec);
                  }
                  break;
              case MessageTypes.UpdateView:
                  {
                      int elemID = buf.readInt();
                      double ex = buf.readDouble();
                      double ey = buf.readDouble();
                      double ez = buf.readDouble();
                      double dx = buf.readDouble();
                      double dy = buf.readDouble();
                      double dz = buf.readDouble();
                      double ux = buf.readDouble();
                      double uy = buf.readDouble();
                      double uz = buf.readDouble();

                      Autodesk.Revit.DB.ElementId id = new Autodesk.Revit.DB.ElementId(elemID);
                      Autodesk.Revit.DB.Element elem = document.GetElement(id);
                      Autodesk.Revit.DB.View3D v3d = (Autodesk.Revit.DB.View3D)elem;
                      Autodesk.Revit.DB.ViewOrientation3D ori = new Autodesk.Revit.DB.ViewOrientation3D(new Autodesk.Revit.DB.XYZ(ex, ey, ez), new Autodesk.Revit.DB.XYZ(ux, uy, uz), new Autodesk.Revit.DB.XYZ(dx, dy, dz));
                      v3d.SetOrientation(ori);
                  }
                  break;

              case MessageTypes.AvatarPosition:
                  {
                      double ex = buf.readDouble();
                      double ey = buf.readDouble();
                      double ez = buf.readDouble();
                      double dx = buf.readDouble();
                      double dy = buf.readDouble();
                      double dz = buf.readDouble();
                      Level currentLevel = getLevel(doc, ez);
                      string lev = "";
                      if (currentLevel != null)
                      {
                          lev = currentLevel.Name;
                      }
                      Room testRaum = getRoom(doc, ex, ey, ez);
                      XYZ point = new XYZ(ex, ey, ez);
                      Room currentRoom = doc.GetRoomAtPoint(point);
                      if (currentRoom == null)
                      {
                          point = new XYZ(ex, ey, currentLevel.ProjectElevation);
                          currentRoom = doc.GetRoomAtPoint(point);
                          if (currentRoom == null)
                              currentRoom = testRaum;
                      }
                      if (currentRoom != null)
                      {

                          string nr = currentRoom.Number;
                          string name = currentRoom.Name;
                          double area = currentRoom.Area;
                          MessageBuffer mb = new MessageBuffer();
                          mb.add(nr);
                          mb.add(name);
                          mb.add(area);
                          mb.add(lev);
                          sendMessage(mb.buf, MessageTypes.RoomInfo);
                      }
                      else
                      {
                          string nr = "-1";
                          string name = "No Room";
                          double area = 0.0;
                          MessageBuffer mb = new MessageBuffer();
                          mb.add(nr);
                          mb.add(name);
                          mb.add(area);
                          mb.add(lev);
                          sendMessage(mb.buf, MessageTypes.RoomInfo);
                      }
                      if (avatarObject != null)
                      {
                          /*
                          Autodesk.Revit.DB.LocationCurve ElementPosCurve = avatarObject.Location as Autodesk.Revit.DB.LocationCurve;
                          Autodesk.Revit.DB.XYZ translationVec = new Autodesk.Revit.DB.XYZ(ex, ey, ez);
                          ElementPosCurve.Move(translationVec);*/
                      }
                  }
                  break;

              }
        }
Exemplo n.º 6
0
        public void sendParameters(Autodesk.Revit.DB.Element elem)
        {
            // iterate element's parameters
              Autodesk.Revit.DB.ParameterSet vrps=new Autodesk.Revit.DB.ParameterSet();
              foreach (Autodesk.Revit.DB.Parameter para in elem.Parameters)
              {
              if (para.Definition.Name != null && para.Definition.Name.Length > 4)
              {
                  if (String.Compare(para.Definition.Name, 0, "coVR", 0, 4, true) == 0)
                  {
                      vrps.Insert(para);
                  }
              }
              }
              if (vrps.Size > 0)
              {

              MessageBuffer mb = new MessageBuffer();
              mb.add(elem.Id.IntegerValue);
              mb.add(vrps.Size);
              foreach (Autodesk.Revit.DB.Parameter para in vrps)
              {
                  mb.add(para.Id.IntegerValue);
                  mb.add(para.Definition.Name);
                  mb.add((int)para.StorageType);
                  mb.add((int)para.Definition.ParameterType);
                  switch (para.StorageType)
                  {
                      case Autodesk.Revit.DB.StorageType.Double:
                          mb.add(para.AsDouble());
                          break;
                      case Autodesk.Revit.DB.StorageType.ElementId:
                          //find out the name of the element
                          Autodesk.Revit.DB.ElementId id = para.AsElementId();
                          mb.add(id.IntegerValue);
                          break;
                      case Autodesk.Revit.DB.StorageType.Integer:
                          mb.add(para.AsInteger());
                          break;
                      case Autodesk.Revit.DB.StorageType.String:
                          mb.add(para.AsString());
                          break;
                      default:
                          mb.add("Unknown Parameter Storage Type");
                          break;
                  }

              }
              sendMessage(mb.buf, MessageTypes.NewParameters);
              }
        }
Exemplo n.º 7
0
 public void SendGeometry(Autodesk.Revit.DB.FilteredElementIterator iter, Autodesk.Revit.UI.UIApplication application)
 {
     UIDocument uidoc = application.ActiveUIDocument;
      Application app = application.Application;
      Document doc = uidoc.Document;
      MessageBuffer mb = new MessageBuffer();
      mb.add(1);
      sendMessage(mb.buf, MessageTypes.ClearAll);
      View3D = null;
      if (uidoc.ActiveView is View3D)
      {
      View3D = uidoc.ActiveView as View3D;
      }
      if (View3D == null)
      {
      iter.Reset();
      while (iter.MoveNext())
      {
          if (iter.Current is Autodesk.Revit.DB.View3D)
          {
              View3D = iter.Current as Autodesk.Revit.DB.View3D;
              break;
          }
          // this one handles Group.
      }
      }
       ElementId activeOptId = Autodesk.Revit.DB.DesignOption.GetActiveDesignOptionId(doc);
      iter.Reset();
      while (iter.MoveNext())
      {
      Autodesk.Revit.DB.Element el = iter.Current as Autodesk.Revit.DB.Element;
      if (el.DesignOption == null || el.DesignOption.Id == activeOptId)
      {
          SendElement(el);
      }
     // this one handles Group.
      }
 }
Exemplo n.º 8
0
 public COVERMessage(MessageBuffer m, int mt)
 {
     message = m;
     messageType = mt;
 }
Exemplo n.º 9
0
        public void OnInstanceEnd(InstanceNode node)
        {
            MessageBuffer mb = new MessageBuffer();

            OpenCOVERPlugin.COVER.Instance.sendMessage(mb.buf, OpenCOVERPlugin.COVER.MessageTypes.EndInstance);
        }
Exemplo n.º 10
0
        public RenderNodeAction OnViewBegin(ViewNode node)
        {
            View3D view = m_doc.GetElement(node.ViewId) as View3D;
            if (view != null)
            {
                MessageBuffer mb = new MessageBuffer();
                mb.add(view.Id.IntegerValue);
                mb.add(view.Name);
                mb.add(view.Origin);
                mb.add(view.ViewDirection);
                mb.add(view.UpDirection);
                OpenCOVERPlugin.COVER.Instance.sendMessage(mb.buf, OpenCOVERPlugin.COVER.MessageTypes.AddView);
            }

            // Setting our default LoD for the view
            // The scale goes from 0 to 10, but the value close to the edges
            // aren't really that usable, except maybe of experimenting

            node.LevelOfDetail = 5;   // a good middle ground

            return RenderNodeAction.Proceed;
        }
Exemplo n.º 11
0
        public void OnPolymesh(PolymeshTopology node)
        {
            num++;
            MessageBuffer mb = new MessageBuffer();
            mb.add(node.NumberOfPoints);
            mb.add(node.NumberOfFacets);
            mb.add(node.NumberOfNormals);
            mb.add(node.NumberOfUVs);

            foreach (Autodesk.Revit.DB.XYZ point in node.GetPoints())
            {
                mb.add(point);
            }
            foreach (Autodesk.Revit.DB.XYZ normal in node.GetNormals())
            {
                mb.add(normal);
            }
            foreach (Autodesk.Revit.DB.UV uv in node.GetUVs())
            {
                mb.add((float)uv.U);
                mb.add((float)uv.V);
            }
            foreach (Autodesk.Revit.DB.PolymeshFacet facet in node.GetFacets())
            {
                mb.add(facet.V1);
                mb.add(facet.V2);
                mb.add(facet.V3);
            }

            OpenCOVERPlugin.COVER.Instance.sendMessage(mb.buf, OpenCOVERPlugin.COVER.MessageTypes.NewPolyMesh);
            return;
        }
Exemplo n.º 12
0
        public void OnMaterial(MaterialNode node)
        {
            materialNode = node;
            MessageBuffer mb = new MessageBuffer();

            mb.add(node.MaterialId.IntegerValue);
            mb.add(node.NodeName);
            mb.add(node.Color);
            mb.add((byte)(((100 - (node.Transparency)) / 100.0) * 255));
            Asset asset;
            if (node.HasOverriddenAppearance)
            {
                asset = node.GetAppearanceOverride();
            }
            else
            {
                asset = node.GetAppearance();
            }
            String textureName = "";
            AssetProperties properties = asset as AssetProperties;
            for (int index = 0; index < asset.Size; index++)
            {

                if (properties[index].Type == AssetPropertyType.APT_Reference)
                {
                    AssetPropertyReference e = properties[index] as AssetPropertyReference;
                    if (e != null)
                    {
                        AssetProperty p = e.GetConnectedProperty(0);
                        if (p.Type == AssetPropertyType.APT_Asset)
                        {
                            Asset a = p as Asset;
                            if (a != null)
                            {
                                Boolean foundValidTexture = false;
                                AssetProperties prop = a as AssetProperties;
                                for (int ind = 0; ind < a.Size; ind++)
                                {
                                    if (prop[ind].Name == "unifiedbitmap_Bitmap")
                                    {

                                        AssetPropertyString ps = prop[ind] as AssetPropertyString;
                                        if (ps.Value != "")
                                        {
                                            textureName = ps.Value;
                                            foundValidTexture = true;
                                        }
                                    }
                                    if (prop[ind].Name == "texture_URepeat")
                                    {
                                        AssetPropertyBoolean ps = prop[ind] as AssetPropertyBoolean;
                                        if (foundValidTexture)
                                        {

                                        }
                                        //textureName = ps.Value;
                                    }
                                    if (prop[ind].Name == "texture_VRepeat")
                                    {

                                        AssetPropertyBoolean ps = prop[ind] as AssetPropertyBoolean;
                                        if (foundValidTexture)
                                        {

                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            mb.add(textureName);
            OpenCOVERPlugin.COVER.Instance.sendMessage(mb.buf, OpenCOVERPlugin.COVER.MessageTypes.NewMaterial);

            return;
        }
Exemplo n.º 13
0
 public void OnInstanceEnd(InstanceNode node)
 {
     MessageBuffer mb = new MessageBuffer();
     OpenCOVERPlugin.COVER.Instance.sendMessage(mb.buf, OpenCOVERPlugin.COVER.MessageTypes.EndInstance);
 }
Exemplo n.º 14
0
        public RenderNodeAction OnInstanceBegin(InstanceNode node)
        {
            Transform t = node.GetTransform();
            MessageBuffer mb = new MessageBuffer();

            mb.add(node.GetSymbolId().IntegerValue);
            mb.add(node.NodeName);
            mb.add(t.BasisX.Multiply(t.Scale));
            mb.add(t.BasisY.Multiply(t.Scale));
            mb.add(t.BasisZ.Multiply(t.Scale));
            mb.add(t.Origin);
            OpenCOVERPlugin.COVER.Instance.sendMessage(mb.buf, OpenCOVERPlugin.COVER.MessageTypes.NewInstance);
            return RenderNodeAction.Proceed;
        }
Exemplo n.º 15
0
        private void sendTextNote(Autodesk.Revit.DB.Element elem)
        {
            Autodesk.Revit.DB.TextNote tn = (Autodesk.Revit.DB.TextNote)elem;
              if (tn is Autodesk.Revit.DB.TextNote)
              {
              MessageBuffer mb = new MessageBuffer();
              mb.add(elem.Id.IntegerValue);
              mb.add(tn.Coord);
              mb.add(tn.Text);
              sendMessage(mb.buf, MessageTypes.NewAnnotation);

              }
              else
              {
              }
        }
Exemplo n.º 16
0
 private void sendViewpoint(Autodesk.Revit.DB.Element elem)
 {
     Autodesk.Revit.DB.View view = (Autodesk.Revit.DB.View)elem;
      if (view is Autodesk.Revit.DB.View3D)
      {
     Autodesk.Revit.DB.View3D v3d = (Autodesk.Revit.DB.View3D)view;
     MessageBuffer mb = new MessageBuffer();
     mb.add(elem.Id.IntegerValue);
     mb.add(elem.Name);
     mb.add(v3d.Origin);
     mb.add(v3d.ViewDirection);
     mb.add(v3d.UpDirection);
     sendMessage(mb.buf, MessageTypes.AddView);
      }
      else
      {
      }
 }
Exemplo n.º 17
0
        //  public void OnDaylightPortal(DaylightPortalNode node)
        //{
        // Like RPCs, Daylight Portals too have their assets available only.
        // THere is no other public API for them currently available.


        //   return;
        //}

        public void OnMaterial(MaterialNode node)
        {
            materialNode = node;
            MessageBuffer mb = new MessageBuffer();

            mb.add(node.MaterialId.IntegerValue);
            mb.add(node.NodeName);
            mb.add(node.Color);
            mb.add((byte)(((100 - (node.Transparency)) / 100.0) * 255));
            Asset asset;

            if (node.HasOverriddenAppearance)
            {
                asset = node.GetAppearanceOverride();
            }
            else
            {
                asset = node.GetAppearance();
            }
            String          textureName = "";
            AssetProperties properties  = asset as AssetProperties;

            for (int index = 0; index < asset.Size; index++)
            {
                if (properties[index].Type == AssetPropertyType.Reference)
                {
                    AssetPropertyReference e = properties[index] as AssetPropertyReference;
                    if (e != null)
                    {
                        AssetProperty p = e.GetConnectedProperty(0);
                        if (p.Type == AssetPropertyType.Asset)
                        {
                            Asset a = p as Asset;
                            if (a != null)
                            {
                                Boolean         foundValidTexture = false;
                                AssetProperties prop = a as AssetProperties;
                                for (int ind = 0; ind < a.Size; ind++)
                                {
                                    if (prop[ind].Name == "unifiedbitmap_Bitmap")
                                    {
                                        AssetPropertyString ps = prop[ind] as AssetPropertyString;
                                        if (ps.Value != "")
                                        {
                                            textureName       = ps.Value;
                                            foundValidTexture = true;
                                        }
                                    }
                                    if (prop[ind].Name == "texture_URepeat")
                                    {
                                        AssetPropertyBoolean ps = prop[ind] as AssetPropertyBoolean;
                                        if (foundValidTexture)
                                        {
                                        }
                                        //textureName = ps.Value;
                                    }
                                    if (prop[ind].Name == "texture_VRepeat")
                                    {
                                        AssetPropertyBoolean ps = prop[ind] as AssetPropertyBoolean;
                                        if (foundValidTexture)
                                        {
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            mb.add(textureName);
            OpenCOVERPlugin.COVER.Instance.sendMessage(mb.buf, OpenCOVERPlugin.COVER.MessageTypes.NewMaterial);

            return;
        }
Exemplo n.º 18
0
 public void deleteElement(Autodesk.Revit.DB.ElementId ID)
 {
     MessageBuffer mb = new MessageBuffer();
       mb.add(ID.IntegerValue);
       sendMessage(mb.buf, MessageTypes.DeleteElement);
 }
Exemplo n.º 19
0
        /// <summary>
        /// Draw geometry of element.
        /// </summary>
        /// <param name="elementGeom"></param>
        /// <remarks></remarks>
        private void SendElement(Autodesk.Revit.DB.GeometryElement elementGeom, Autodesk.Revit.DB.Element elem)
        {
            if (elementGeom == null)
             {
            return;
             }
             try
             {
            if (elem.IsHidden(View3D))
            {
               return;
            }
            if (!elem.Category.get_Visible(View3D as Autodesk.Revit.DB.View))
            {
               return;
            }
             }
             catch
             {
             }
             int num = 0;
             IEnumerator<Autodesk.Revit.DB.GeometryObject> Objects = elementGeom.GetEnumerator();
             while (Objects.MoveNext())
             {
             Autodesk.Revit.DB.GeometryObject geomObject = Objects.Current;
            if (geomObject.Visibility == Autodesk.Revit.DB.Visibility.Visible)
            {
               if ((geomObject is Autodesk.Revit.DB.Curve))
               {
                  //mb.add((int)ObjectTypes.Curve);
                  //SendCurve(geomObject);
               }
               else if ((elem is Autodesk.Revit.DB.SpatialElement))
               {
                   // don't show room volumes
               }
               else if ((geomObject is Autodesk.Revit.DB.GeometryInstance))
               {
                   /*if (elem.Category.Name != "{3}")
                   {
                      if (!elem.Category.get_Visible(View3D as Autodesk.Revit.DB.View))
                      {
                         return;
                      }
                   }*/

                   SendInstance(geomObject as Autodesk.Revit.DB.GeometryInstance, elem);
               }
               else if ((geomObject is Autodesk.Revit.DB.Mesh))
               {
                   MessageBuffer mb = new MessageBuffer();
                   mb.add(elem.Id.IntegerValue);
                   mb.add(elem.Name + "_m_" + num.ToString());
                   mb.add((int)ObjectTypes.Mesh);
                   Autodesk.Revit.DB.Mesh meshObj = geomObject as Autodesk.Revit.DB.Mesh;
                   SendMesh(meshObj, ref mb, true);// TODO get information on whether a mesh is twosided or not

                   Autodesk.Revit.DB.ElementId materialID;
                   materialID = meshObj.MaterialElementId;
                   Autodesk.Revit.DB.Material materialElement = elem.Document.GetElement(materialID) as Autodesk.Revit.DB.Material;
                   if (materialElement != null)
                   {
                       mb.add(materialElement.Color);
                       mb.add((byte)(((100 - (materialElement.Transparency)) / 100.0) * 255));
                       mb.add(materialID.IntegerValue); // material ID
                   }
                   else
                   {
                       mb.add((byte)250); // color
                       mb.add((byte)250);
                       mb.add((byte)250);
                       mb.add((byte)255);
                       mb.add(-1); // material ID
                   }
                   sendMessage(mb.buf, MessageTypes.NewObject);
                   if (num == 0)
                   sendParameters(elem);
               }
               else if ((geomObject is Autodesk.Revit.DB.Solid))
               {
                   MessageBuffer mb = new MessageBuffer();
                   mb.add(elem.Id.IntegerValue);
                   mb.add(elem.Name + "_s_" + num.ToString());
                   sendMessage(mb.buf, MessageTypes.NewGroup);
                   SendSolid((Autodesk.Revit.DB.Solid)geomObject, elem);
                   mb = new MessageBuffer();
                   sendMessage(mb.buf, MessageTypes.EndGroup);
                   if(num == 0)
                    sendParameters(elem);
               }
               num++;
            }
             }
        }
Exemplo n.º 20
0
 public void SendGeometry(Autodesk.Revit.DB.FilteredElementIterator iter, List<int> IDs)
 {
     iter.Reset();
      while (iter.MoveNext())
      {
     if (iter.Current is Autodesk.Revit.DB.View3D)
     {
        View3D = iter.Current as Autodesk.Revit.DB.View3D;
        break;
     }
     // this one handles Group.
      }
      iter.Reset();
      while (iter.MoveNext())
      {
     Autodesk.Revit.DB.Element elem;
     elem = iter.Current as Autodesk.Revit.DB.Element;
     foreach (int ID in IDs)   // get the wall type by the name
     {
         if (ID == elem.Id.IntegerValue)
        {
           MessageBuffer mb = new MessageBuffer();
           mb.add(ID);
           sendMessage(mb.buf, MessageTypes.DeleteObject);
           SendElement(elem);
           break;
        }
     }
     // this one handles Group.
      }
 }
Exemplo n.º 21
0
        private void SendInstance(Autodesk.Revit.DB.GeometryInstance geomInstance, Autodesk.Revit.DB.Element elem)
        {
            MessageBuffer mb = new MessageBuffer();
             mb.add(elem.Id.IntegerValue);
             mb.add(elem.Name + "__" + elem.UniqueId.ToString());
             try
             {
             mb.add(geomInstance.Transform.BasisX.Multiply(geomInstance.Transform.Scale));
             mb.add(geomInstance.Transform.BasisY.Multiply(geomInstance.Transform.Scale));
             mb.add(geomInstance.Transform.BasisZ.Multiply(geomInstance.Transform.Scale));
             mb.add(geomInstance.Transform.Origin);
             }
             catch (Autodesk.Revit.Exceptions.InvalidOperationException)
             {
             mb.add(new XYZ(1, 0, 0));
             mb.add(new XYZ(0, 1, 0));
             mb.add(new XYZ(0, 0, 1));
             mb.add(new XYZ(0, 0, 0));
             }
             sendMessage(mb.buf, MessageTypes.NewTransform);
             //Autodesk.Revit.DB.GeometryElement ge = geomInstance.GetInstanceGeometry(geomInstance.Transform);
             Autodesk.Revit.DB.GeometryElement ge = geomInstance.GetSymbolGeometry();
             SendElement(ge, elem);

             mb = new MessageBuffer();
             sendMessage(mb.buf, MessageTypes.EndGroup);
        }
Exemplo n.º 22
0
        void handleMessage(MessageBuffer buf, int msgType,Document doc,UIDocument uidoc, UIApplication app)
        {
            // create Avatar object if not present
             /* if (avatarObject == null)
              {
              createAvatar(doc,uidoc);
              }*/
              switch ((MessageTypes)msgType)
              {

              case MessageTypes.Resend:
                  {
                      Autodesk.Revit.DB.FilteredElementCollector collector = new Autodesk.Revit.DB.FilteredElementCollector(uidoc.Document);
                      COVER.Instance.SendGeometry(collector.WhereElementIsNotElementType().GetElementIterator(), app);

                      ElementClassFilter FamilyFilter = new ElementClassFilter(typeof(FamilySymbol));
                      FilteredElementCollector FamilyCollector = new FilteredElementCollector(uidoc.Document);
                      ICollection<Element> AllFamilies = FamilyCollector.WherePasses(FamilyFilter).ToElements();
                      foreach (FamilySymbol Fmly in AllFamilies)
                      {
                          COVER.Instance.sendFamilySymbolParameters(Fmly);
                      }
                  }
                  break;
              case MessageTypes.SetParameter:
                  {
                      int elemID = buf.readInt();
                      int paramID = buf.readInt();

                      Autodesk.Revit.DB.ElementId id = new Autodesk.Revit.DB.ElementId(elemID);
                      Autodesk.Revit.DB.Element elem = document.GetElement(id);

                      foreach (Autodesk.Revit.DB.Parameter para in elem.Parameters)
                      {
                          if (para.Id.IntegerValue == paramID)
                          {

                              switch (para.StorageType)
                              {
                                  case Autodesk.Revit.DB.StorageType.Double:
                                      double d = buf.readDouble();
                                      try
                                      {
                                          para.Set(d);
                                      }
                                      catch
                                      {
                                          Autodesk.Revit.UI.TaskDialog.Show("Double", "para.Set failed");
                                      }
                                      d = para.AsDouble();
                                      break;
                                  case Autodesk.Revit.DB.StorageType.ElementId:
                                      //find out the name of the element
                                      int tmpid = buf.readInt();
                                      Autodesk.Revit.DB.ElementId eleId = new Autodesk.Revit.DB.ElementId(tmpid);
                                      try
                                      {
                                          para.Set(eleId);
                                      }
                                      catch
                                      {
                                          Autodesk.Revit.UI.TaskDialog.Show("Double", "para.Set failed");
                                      }
                                      break;
                                  case Autodesk.Revit.DB.StorageType.Integer:
                                      try
                                      {
                                          para.Set(buf.readInt());
                                      }
                                      catch
                                      {
                                          Autodesk.Revit.UI.TaskDialog.Show("Double", "para.Set failed");
                                      }
                                      break;
                                  case Autodesk.Revit.DB.StorageType.String:
                                      try
                                      {
                                          para.Set(buf.readString());
                                      }
                                      catch
                                      {
                                          Autodesk.Revit.UI.TaskDialog.Show("Double", "para.Set failed");
                                      }
                                      break;
                                  default:
                                      try
                                      {
                                          para.SetValueString(buf.readString());
                                      }
                                      catch
                                      {
                                          Autodesk.Revit.UI.TaskDialog.Show("Double", "para.Set failed");
                                      }
                                      break;
                              }

                          }
                      }
                  }
                  break;
              case MessageTypes.SetTransform:
                  {
                      int elemID = buf.readInt();
                      double x = buf.readDouble();
                      double y = buf.readDouble();
                      double z = buf.readDouble();

                      Autodesk.Revit.DB.ElementId id = new Autodesk.Revit.DB.ElementId(elemID);
                      Autodesk.Revit.DB.Element elem = document.GetElement(id);
                      Autodesk.Revit.DB.XYZ translationVec = new Autodesk.Revit.DB.XYZ(x, y, z);
                      Autodesk.Revit.DB.LocationCurve ElementPosCurve = elem.Location as Autodesk.Revit.DB.LocationCurve;
                      if (ElementPosCurve != null)
                          ElementPosCurve.Move(translationVec);
                      Autodesk.Revit.DB.LocationPoint ElementPosPoint = elem.Location as Autodesk.Revit.DB.LocationPoint;
                      if (ElementPosPoint != null)
                          ElementPosPoint.Move(translationVec);
                  }
                  break;
              case MessageTypes.UpdateView:
                  {
                      int elemID = buf.readInt();
                      double ex = buf.readDouble();
                      double ey = buf.readDouble();
                      double ez = buf.readDouble();
                      double dx = buf.readDouble();
                      double dy = buf.readDouble();
                      double dz = buf.readDouble();
                      double ux = buf.readDouble();
                      double uy = buf.readDouble();
                      double uz = buf.readDouble();

                      Autodesk.Revit.DB.ElementId id = new Autodesk.Revit.DB.ElementId(elemID);
                      Autodesk.Revit.DB.Element elem = document.GetElement(id);
                      Autodesk.Revit.DB.View3D v3d = (Autodesk.Revit.DB.View3D)elem;
                      Autodesk.Revit.DB.ViewOrientation3D ori = new Autodesk.Revit.DB.ViewOrientation3D(new Autodesk.Revit.DB.XYZ(ex, ey, ez), new Autodesk.Revit.DB.XYZ(ux, uy, uz), new Autodesk.Revit.DB.XYZ(dx, dy, dz));
                      v3d.SetOrientation(ori);
                  }
                  break;

              case MessageTypes.NewAnnotation:
                  {

                      int labelNumber = buf.readInt();
                      double x = buf.readDouble();
                      double y = buf.readDouble();
                      double z = buf.readDouble();
                      double h = buf.readDouble();
                      double p = buf.readDouble();
                      double r = buf.readDouble();
                      string labelText = buf.readString();

                      Autodesk.Revit.DB.XYZ translationVec = new Autodesk.Revit.DB.XYZ(x, y, z);
                      Autodesk.Revit.DB.View view = document.ActiveView;
                      ElementId currentTextTypeId = document.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType);
                      Autodesk.Revit.DB.TextNote tn = Autodesk.Revit.DB.TextNote.Create(document, view.Id, translationVec, labelText, currentTextTypeId);
                      // send back revit ID corresponding to this annotationID
                      // the mapping of annotationIDs to Revit element IDs is done in OpenCOVER
                      MessageBuffer mb = new MessageBuffer();
                      mb.add(labelNumber);
                      mb.add(tn.Id.IntegerValue);
                      sendMessage(mb.buf, MessageTypes.NewAnnotationID);

                  }
                  break;
              case MessageTypes.ChangeAnnotation:
                  {

                      int elemID = buf.readInt();
                      double x = buf.readDouble();
                      double y = buf.readDouble();
                      double z = buf.readDouble();
                      double h = buf.readDouble();
                      double p = buf.readDouble();
                      double r = buf.readDouble();

                      Autodesk.Revit.DB.ElementId id = new Autodesk.Revit.DB.ElementId(elemID);
                      Autodesk.Revit.DB.Element elem = document.GetElement(id);

                      Autodesk.Revit.DB.TextNote tn = elem as Autodesk.Revit.DB.TextNote;
                      if (tn != null)
                      {
                          Autodesk.Revit.DB.XYZ translationVec = new Autodesk.Revit.DB.XYZ(x, y, z);
                          tn.Coord = translationVec;
                      }

                  }
                  break;
              case MessageTypes.SetView:
                  {
                      int currentView = buf.readInt();

                      List<View3D> views = new List<View3D>(
              new FilteredElementCollector(doc)
            .OfClass(typeof(View3D))
            .Cast<View3D>()
            .Where<View3D>(v =>
              v.CanBePrinted && !v.IsTemplate));
                      int n = 0;
                      foreach (View3D v in views)
                      {
                          if (n == currentView)
                          {
                              try
                              {
                              uidoc.ActiveView = v;
                              }
                              catch (Autodesk.Revit.Exceptions.ArgumentNullException e)
                              {
                                  Console.WriteLine("Exception information: {0}", e);
                              }
                              catch (Autodesk.Revit.Exceptions.ArgumentException e)
                              {
                                  Console.WriteLine("Exception information: {0}", e);
                              }
                              catch (Autodesk.Revit.Exceptions.InvalidOperationException e)
                              {
                                  Console.WriteLine("Exception information: {0}", e);
                              }
                              break;
                          }
                          n++;
                      }
                  }
                  break;
              case MessageTypes.ChangeAnnotationText:
                  {

                      int elemID = buf.readInt();
                      string labelText = buf.readString();

                      Autodesk.Revit.DB.ElementId id = new Autodesk.Revit.DB.ElementId(elemID);
                      Autodesk.Revit.DB.Element elem = document.GetElement(id);

                      Autodesk.Revit.DB.TextNote tn = elem as Autodesk.Revit.DB.TextNote;
                      if (tn != null)
                      {
                          tn.Text = labelText;
                      }

                  }
                  break;

              case MessageTypes.AvatarPosition:
                  {
                      double ex = buf.readDouble();
                      double ey = buf.readDouble();
                      double ez = buf.readDouble();
                      double dx = buf.readDouble();
                      double dy = buf.readDouble();
                      double dz = buf.readDouble();
                      Level currentLevel = getLevel(doc, ez);
                      string lev = "";
                      if (currentLevel != null)
                      {
                          lev = currentLevel.Name;
                      }
                      Room testRaum = null;
                      Room currentRoom = null;
                      try
                      {
                          XYZ point = new XYZ(ex, ey, ez);
                          currentRoom = doc.GetRoomAtPoint(point);
                          if (currentRoom == null && (currentLevel != null))
                          {
                              point = new XYZ(ex, ey, currentLevel.ProjectElevation);
                              currentRoom = doc.GetRoomAtPoint(point);
                              if (currentRoom == null)
                              {
                                  testRaum = getRoom(doc, ex, ey, ez);
                                  currentRoom = testRaum;
                              }

                          }
                      }
                      catch
                      {
                      }
                      if (currentRoom != null)
                      {

                          string nr = currentRoom.Number;
                          string name = currentRoom.Name;
                          double area = currentRoom.Area;
                          MessageBuffer mb = new MessageBuffer();
                          mb.add(nr);
                          mb.add(name);
                          mb.add(area);
                          mb.add(lev);
                          sendMessage(mb.buf, MessageTypes.RoomInfo);
                      }
                      else
                      {
                          string nr = "-1";
                          string name = "No Room";
                          double area = 0.0;
                          MessageBuffer mb = new MessageBuffer();
                          mb.add(nr);
                          mb.add(name);
                          mb.add(area);
                          mb.add(lev);
                          sendMessage(mb.buf, MessageTypes.RoomInfo);
                      }
                      if (avatarObject != null)
                      {
                          /*
                          Autodesk.Revit.DB.LocationCurve ElementPosCurve = avatarObject.Location as Autodesk.Revit.DB.LocationCurve;
                          Autodesk.Revit.DB.XYZ translationVec = new Autodesk.Revit.DB.XYZ(ex, ey, ez);
                          ElementPosCurve.Move(translationVec);*/
                      }
                  }
                  break;

              }
        }
Exemplo n.º 23
0
Arquivo: COVER.cs Projeto: nixz/covise
 public void SendGeometry(Autodesk.Revit.DB.FilteredElementIterator iter, Autodesk.Revit.DB.Document doc)
 {
     MessageBuffer mb = new MessageBuffer();
      mb.add(1);
      sendMessage(mb.buf, MessageTypes.ClearAll);
       // todo use the current or default view
      iter.Reset();
      while (iter.MoveNext())
      {
     if (iter.Current is Autodesk.Revit.DB.View3D)
     {
         View3D = iter.Current as Autodesk.Revit.DB.View3D;
       break;
     }
     // this one handles Group.
      }
       ElementId activeOptId = Autodesk.Revit.DB.DesignOption.GetActiveDesignOptionId(doc);
      iter.Reset();
      while (iter.MoveNext())
      {
      Autodesk.Revit.DB.Element el = iter.Current as Autodesk.Revit.DB.Element;
      if (el.DesignOption == null || el.DesignOption.Id == activeOptId)
      {
          SendElement(el);
      }
     // this one handles Group.
      }
 }