public static void AddElements(this MeshGeometry3D m, EntitySelection selection, XbimMatrix3D wcsTransform)
 {
     foreach (var item in selection)
     {
         m.AddElements(item, wcsTransform);
     }
 }
示例#2
0
        public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (byEntity.World is IClientWorldAccessor)
            {
                ModelTransform tf = new ModelTransform();
                tf.EnsureDefaultValues();

                tf.Origin.Set(0, -1, 0);
                tf.Rotation.Z = Math.Min(30, secondsUsed * 40);
                byEntity.Controls.UsingHeldItemTransformAfter = tf;

                if (secondsUsed > 0.6)
                {
                    Vec3d pos =
                        byEntity.Pos.XYZ.Add(0, byEntity.EyeHeight, 0)
                        .Ahead(1f, byEntity.Pos.Pitch, byEntity.Pos.Yaw)
                    ;

                    Vec3f speedVec = new Vec3d(0, 0, 0).Ahead(5, byEntity.Pos.Pitch, byEntity.Pos.Yaw).ToVec3f();
                    particles.minVelocity = speedVec;
                    Random rand = new Random();
                    particles.color  = ColorUtil.ToRgba(255, rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255));
                    particles.minPos = pos.AddCopy(-0.05, -0.05, -0.05);
                    particles.addPos.Set(0.1, 0.1, 0.1);
                    particles.minSize    = 0.1F;
                    particles.SizeEvolve = EvolvingNatFloat.create(EnumTransformFunction.SINUS, 10);
                    byEntity.World.SpawnParticles(particles);
                }
            }
            return(true);
        }
示例#3
0
        public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (byEntity.Pos.Y > ceiling)
            {
                return(false);
            }

            throttlePercent = Math.Min(secondsUsed, throttleSpeed) / throttleSpeed;


            Vec3d vecthrust = Vec3d.Zero;
            bool  hovermode = false;

            if (byEntity.Pos.Motion.Y < maxSpeed && byEntity.HeadPitch < -0.05f)
            {
                byEntity.Pos.Motion.Y = thrust * throttlePercent;
            }
            //else if (byEntity.HeadPitch > 0.05f)
            //{
            //let gravity do its thing
            //}
            else
            {
                hovermode = true;
            }
            vecthrust           += byEntity.Controls.WalkVector.Normalize() * lateralthrust * throttlePercent;
            byEntity.Pos.Motion += vecthrust;
            if (hovermode)
            {
                byEntity.Pos.Motion.Y *= 0.1;
            }
            //byEntity.Pos.Motion=    thrust * throttlePercent*byEntity;


            return(true);
        }
示例#4
0
        public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (entitySel != null)
            {
                if (byEntity.World.Side == EnumAppSide.Client)
                {
                    ModelTransform tf = new ModelTransform();
                    tf.EnsureDefaultValues();

                    float offset = GameMath.Clamp(secondsUsed * 5, 0, 2f);

                    byEntity.Controls.UsingHeldItemTransformBefore = tf;
                    tf.Origin.Set(1f, 0, 0.5f);
                    tf.Rotation.Set(0, 0, -offset * 15);
                    tf.Translation.Set(0, Math.Min(1f, secondsUsed), 0);


                    if (secondsUsed > 0.9f)
                    {
                        float offset2 = GameMath.Clamp((secondsUsed - 0.9f) * 5 * 240, 0, 70f);
                        tf.Rotation.Add(0, 0, offset2);
                        tf.Translation.Add(0, -Math.Min(1f, (secondsUsed - 0.9f) * 10), 0);
                    }
                    if (secondsUsed > 1f)
                    {
                        if (api.ObjectCache.ContainsKey("slaughterSoundPlayed") && (bool)api.ObjectCache["slaughterSoundPlayed"] == false)
                        {
                            byEntity.World.PlaySoundAt(new AssetLocation("sounds/tool/slash"), entitySel.Entity, (byEntity as EntityPlayer)?.Player, false, 12);
                            api.ObjectCache["slaughterSoundPlayed"] = true;
                        }
                    }

                    byEntity.Controls.UsingHeldItemTransformBefore = tf;
                }

                return(secondsUsed < 1.15f);
            }

            return(false);
        }
示例#5
0
 public override bool OnHeldAttackStep(float secondsPassed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSelection, EntitySelection entitySel)
 {
     return(false);
 }
示例#6
0
        public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling)
        {
            if (entitySel != null && entitySel.Entity.Alive && !(entitySel.Entity is EntityArmorStand))
            {
                handling = EnumHandHandling.PreventDefault;

                if (api.World.Side == EnumAppSide.Client)
                {
                    api.ObjectCache["slaughterSoundPlayed"] = false;
                }

                return;
            }

            handling = EnumHandHandling.NotHandled;
        }
示例#7
0
        public override bool OnHeldInteractCancel(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, EnumItemUseCancelReason cancelReason)
        {
            //byEntity.World.Logger.Debug("{0} knife interact cancelled, seconds used {1}", byEntity.World.Side, secondsUsed);

            return(base.OnHeldInteractCancel(secondsUsed, slot, byEntity, blockSel, entitySel, cancelReason));
        }
示例#8
0
        public override bool OnHeldInteractStep(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (blockSel == null)
            {
                return(false);
            }

            ILiquidMetalSink be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position) as ILiquidMetalSink;

            if (be == null)
            {
                return(false);
            }

            if (!be.CanReceiveAny)
            {
                return(false);
            }
            KeyValuePair <ItemStack, int> contents = GetContents(byEntity.World, slot.Itemstack);

            if (!be.CanReceive(contents.Key))
            {
                return(false);
            }

            float speed = 1.5f;
            float temp  = GetTemperature(byEntity.World, slot.Itemstack);

            if (byEntity.World is IClientWorldAccessor)
            {
                ModelTransform tf = new ModelTransform();
                tf.EnsureDefaultValues();

                tf.Origin.Set(0.5f, 0.2f, 0.5f);
                tf.Translation.Set(0, 0, -Math.Min(0.25f, speed * secondsUsed / 4));
                tf.Scale      = 1f + Math.Min(0.25f, speed * secondsUsed / 4);
                tf.Rotation.X = Math.Max(-110, -secondsUsed * 90 * speed);
                byEntity.Controls.UsingHeldItemTransformBefore = tf;
            }

            IPlayer byPlayer = null;

            if (byEntity is IEntityPlayer)
            {
                byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID);
            }


            if (secondsUsed > 1 / speed)
            {
                if ((int)(30 * secondsUsed) % 3 == 1)
                {
                    Vec3d pos =
                        byEntity.Pos.XYZ
                        .Ahead(0.1f, byEntity.Pos.Pitch, byEntity.Pos.Yaw)
                        .Ahead(1.0f, byEntity.Pos.Pitch, byEntity.Pos.Yaw - GameMath.PIHALF)
                    ;
                    pos.Y += byEntity.EyeHeight - 0.4f;

                    smokePouring.minPos = pos.AddCopy(-0.15, -0.15, -0.15);

                    Vec3d blockpos = blockSel.Position.ToVec3d().Add(0.5, 0.2, 0.5);

                    bigMetalSparks.minQuantity = Math.Max(0.2f, 1 - (secondsUsed - 1) / 4);

                    if ((int)(30 * secondsUsed) % 7 == 1)
                    {
                        bigMetalSparks.minPos = pos;
                        bigMetalSparks.minVelocity.Set(-2, -1, -2);
                        bigMetalSparks.addVelocity.Set(4, 1, 4);
                        byEntity.World.SpawnParticles(bigMetalSparks, byPlayer);

                        byEntity.World.SpawnParticles(smokePouring, byPlayer);
                    }

                    float     y2       = 0;
                    Block     block    = byEntity.World.BlockAccessor.GetBlock(blockSel.Position);
                    Cuboidf[] collboxs = block.GetCollisionBoxes(byEntity.World.BlockAccessor, blockSel.Position);
                    for (int i = 0; collboxs != null && i < collboxs.Length; i++)
                    {
                        y2 = Math.Max(y2, collboxs[i].Y2);
                    }

                    // Metal Spark on the mold
                    bigMetalSparks.minVelocity.Set(-2, 1, -2);
                    bigMetalSparks.addVelocity.Set(4, 5, 4);
                    bigMetalSparks.minPos = blockpos.AddCopy(-0.25, y2 - 2 / 16f, -0.25);
                    bigMetalSparks.addPos.Set(0.5, 0, 0.5);
                    bigMetalSparks.glowLevel = (byte)GameMath.Clamp((int)temp - 770, 48, 128);
                    byEntity.World.SpawnParticles(bigMetalSparks, byPlayer);

                    // Smoke on the mold
                    byEntity.World.SpawnParticles(
                        Math.Max(1, 12 - (secondsUsed - 1) * 6),
                        ColorUtil.ToRgba(50, 220, 220, 220),
                        blockpos.AddCopy(-0.5, y2 - 2 / 16f, -0.5),
                        blockpos.Add(0.5, y2 - 2 / 16f + 0.15, 0.5),
                        new Vec3f(-0.5f, 0f, -0.5f),
                        new Vec3f(0.5f, 0f, 0.5f),
                        1.5f,
                        -0.05f,
                        0.75f,
                        EnumParticleModel.Quad,
                        byPlayer
                        );
                }

                int transferedAmount = Math.Min(2, contents.Value);


                be.ReceiveLiquidMetal(contents.Key, ref transferedAmount, temp);

                int newAmount = Math.Max(0, contents.Value - (2 - transferedAmount));
                slot.Itemstack.Attributes.SetInt("units", newAmount);


                if (newAmount <= 0 && byEntity.World is IServerWorldAccessor)
                {
                    slot.Itemstack = new ItemStack(byEntity.World.GetBlock(new AssetLocation("crucible-burned")));
                    slot.MarkDirty();
                    // Since we change the item stack we have to call this ourselves
                    OnHeldInteractStop(secondsUsed, slot, byEntity, blockSel, entitySel);
                    return(false);
                }

                return(true);
            }

            return(true);
        }
示例#9
0
        private ItemStack[] getMatchingStacks(WorldInteraction wi, BlockSelection blockSelection, EntitySelection entitySelection)
        {
            BlockEntityBloomery beb = api.World.BlockAccessor.GetBlockEntity(blockSelection.Position) as BlockEntityBloomery;

            if (beb == null || wi.Itemstacks.Length == 0)
            {
                return(null);
            }

            List <ItemStack> matchStacks = new List <ItemStack>();

            foreach (ItemStack stack in wi.Itemstacks)
            {
                if (beb.CanAdd(stack))
                {
                    matchStacks.Add(stack);
                }
            }

            return(matchStacks.ToArray());
        }
示例#10
0
        public override void OnHeldInteractStart(IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handHandling)
        {
            if (blockSel == null)
            {
                return;
            }

            ILiquidMetalSink be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position) as ILiquidMetalSink;

            if (be != null && be.CanReceiveAny)
            {
                KeyValuePair <ItemStack, int> contents = GetContents(byEntity.World, slot.Itemstack);

                if (contents.Key == null)
                {
                    slot.Itemstack = new ItemStack(byEntity.World.GetBlock(new AssetLocation("crucible-burned")));
                    slot.MarkDirty();
                    handHandling = EnumHandHandling.PreventDefault;
                    return;
                }


                if (HasSolidifed(slot.Itemstack, contents.Key, byEntity.World))
                {
                    return;
                }

                if (contents.Value <= 0)
                {
                    return;
                }
                if (!be.CanReceive(contents.Key))
                {
                    return;
                }
                be.BeginFill(blockSel.HitPosition);

                byEntity.World.RegisterCallback((world, pos, dt) =>
                {
                    if (byEntity.Controls.HandUse == EnumHandInteract.HeldItemInteract)
                    {
                        IPlayer byPlayer = null;
                        if (byEntity is IEntityPlayer)
                        {
                            byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID);
                        }

                        world.PlaySoundAt(new AssetLocation("sounds/hotmetal"), byEntity, byPlayer);
                    }
                }, blockSel.Position, 666);

                handHandling = EnumHandHandling.PreventDefault;
            }
        }
示例#11
0
        public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling)
        {
            if (blockSel == null)
            {
                base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handHandling);
                return;
            }

            BlockLiquidContainerBase blockLiqContainer = byEntity.World.BlockAccessor.GetBlock(blockSel.Position) as BlockLiquidContainerBase;
            IPlayer player = (byEntity as EntityPlayer)?.Player;

            string contents = BowlContentItemCode();

            if (blockLiqContainer != null)
            {
                if (contents == null)
                {
                    ItemStack stack = blockLiqContainer.GetContent(byEntity.World, blockSel.Position);
                    if (stack != null && ContentBlockForContents(stack.Collectible.Code.Path) != null)
                    {
                        InsertIntoBowl(slot, byEntity, stack.Collectible.Code.Path);
                        blockLiqContainer.TryTakeContent(byEntity.World, blockSel.Position, 1);
                    }

                    BlockEntityContainer bebarrel = api.World.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityContainer;
                    if (bebarrel != null && bebarrel.Inventory.Count > 0)
                    {
                        stack = bebarrel.Inventory[0].Itemstack;

                        if (stack != null && stack.Collectible.Attributes["crockable"].AsBool() == true)
                        {
                            Block     mealblock = api.World.GetBlock(AssetLocation.Create(slot.Itemstack.Collectible.Attributes["mealBlockCode"].AsString(), slot.Itemstack.Collectible.Code.Domain));
                            ItemStack mealstack = new ItemStack(mealblock);
                            mealstack.StackSize = 1;

                            (mealblock as IBlockMealContainer).SetContents(null, mealstack, new ItemStack[] { bebarrel.Inventory[0].TakeOut(4) }, 1);

                            if (slot.StackSize == 1)
                            {
                                slot.Itemstack = mealstack;
                            }
                            else
                            {
                                slot.TakeOut(1);
                                if (!player.InventoryManager.TryGiveItemstack(mealstack, true))
                                {
                                    api.World.SpawnItemEntity(mealstack, byEntity.Pos.XYZ.Add(0.5, 0.5, 0.5));
                                }
                            }
                            slot.MarkDirty();

                            bebarrel.MarkDirty(true);
                        }
                    }
                }
                else
                {
                    ItemStack stack = blockLiqContainer.GetContent(byEntity.World, blockSel.Position);
                    if (stack == null || stack.Collectible.Code.Equals(new AssetLocation(BowlContentItemCode())))
                    {
                        Item contentItem = byEntity.World.GetItem(new AssetLocation(BowlContentItemCode()));
                        if (blockLiqContainer.TryPutContent(byEntity.World, blockSel.Position, new ItemStack(contentItem), 1) > 0)
                        {
                            EmptyOutBowl(slot, byEntity);
                        }
                    }
                }

                handHandling = EnumHandHandling.PreventDefaultAction;
                return;
            }


            handHandling = EnumHandHandling.PreventDefault;

            base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handHandling);
        }
示例#12
0
        public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (blockSel != null && (byEntity.World.BlockAccessor.GetBlock(blockSel.Position) as BlockLiquidContainerBase) != null)
            {
                return(false);
            }

            return(base.OnHeldInteractStep(secondsUsed, slot, byEntity, blockSel, entitySel));
        }
示例#13
0
        public override void OnHeldInteractStart(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling)
        {
            if (blockSel == null)
            {
                return;
            }

            BlockPos pos = blockSel.Position;

            string lastCodePart = itemslot.Itemstack.Collectible.LastCodePart();

            BlockEntity be = byEntity.World.BlockAccessor.GetBlockEntity(pos);

            if (be is BlockEntityFarmland)
            {
                Block cropBlock = byEntity.World.GetBlock(CodeWithPath("crops-" + lastCodePart + "-0"));
                if (cropBlock == null)
                {
                    return;
                }

                IPlayer byPlayer = null;
                if (byEntity is EntityPlayer)
                {
                    byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID);
                }
                bool planted = (be as BlockEntityFarmland).TryPlant(cropBlock);

                if (planted)
                {
                    byEntity.World.PlaySoundAt(new AssetLocation("sounds/block/plant"), pos.X, pos.Y, pos.Z, byPlayer);

                    ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract);

                    if (byPlayer?.WorldData?.CurrentGameMode != EnumGameMode.Creative)
                    {
                        itemslot.TakeOut(1);
                        itemslot.MarkDirty();
                    }
                }

                if (planted)
                {
                    handHandling = EnumHandHandling.PreventDefault;
                }
            }
        }
示例#14
0
        public override void OnHeldInteractStart(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling)
        {
            if (blockSel == null)
            {
                return;
            }

            BlockEntity be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position.AddCopy(blockSel.Face.Opposite));

            IPlayer byPlayer = null;

            if (byEntity is EntityPlayer)
            {
                byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID);
            }

            if (byPlayer != null && be is BlockEntityToolMold)
            {
                BlockEntityToolMold beim = (BlockEntityToolMold)be;
                if (beim.OnPlayerInteract(byPlayer, blockSel.Face, blockSel.HitPosition))
                {
                    handHandling = EnumHandHandling.PreventDefault;
                }
            }
        }
示例#15
0
        public override void OnHeldInteractStop(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            slot.MarkDirty();

            if (blockSel == null)
            {
                return;
            }

            ILiquidMetalSink be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position) as ILiquidMetalSink;

            be?.OnPourOver();
        }
示例#16
0
        private void txtCommand_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Enter &&
                (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                )
            {
            #if DEBUG
                // stores the commands being launched
                var fname = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "xbimquerying.txt");
                using (StreamWriter writer = File.CreateText(fname))
                {
                    writer.Write(txtCommand.Text);
                    writer.Flush();
                    writer.Close();
                }
            #endif

                e.Handled = true;
                if (bDoClear)
                    txtOut.Document = new FlowDocument();

                string[] CommandArray = txtCommand.Text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                if (txtCommand.SelectedText != string.Empty)
                    CommandArray = txtCommand.SelectedText.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var cmd_f in CommandArray)
                {
                    ReportAdd("> " + cmd_f, Brushes.ForestGreen);
                    var cmd = cmd_f;
                    int i = cmd.IndexOf("//");
                    if (i > 0)
                    {
                        cmd = cmd.Substring(0, i);
                    }
                    if (cmd.TrimStart().StartsWith("//"))
                        continue;

                    // put here all commands that don't require a database open
                    var mdbclosed = Regex.Match(cmd, @"help", RegexOptions.IgnoreCase);
                    if (mdbclosed.Success)
                    {
                        DisplayHelp();
                        continue;
                    }

                    mdbclosed = Regex.Match(cmd, @"xplorer", RegexOptions.IgnoreCase);
                    if (mdbclosed.Success)
                    {
                        if (ParentWindow != null)
                            ParentWindow.Focus();
                        else
                        {
                            // todo: bonghi: open the model in xplorer if needed.
                            XplorerMainWindow xp = new XplorerMainWindow();
                            ParentWindow = xp;
                            xp.Show();
                        }
                        continue;
                    }

                    mdbclosed = Regex.Match(cmd, @"clear *\b(?<mode>(on|off))*", RegexOptions.IgnoreCase);
                    if (mdbclosed.Success)
                    {
                        try
                        {
                            string option = mdbclosed.Groups["mode"].Value;

                            if (option == "")
                            {
                                txtOut.Document = new FlowDocument();
                                continue;
                            }
                            else if (option == "on")
                                bDoClear = true;
                            else if (option == "off")
                                bDoClear = false;
                            else
                            {
                                ReportAdd(string.Format("Autoclear not changed ({0} is not a valid option).", option));
                                continue;
                            }
                            ReportAdd(string.Format("Autoclear set to {0}", option.ToLower()));
                            continue;
                        }
                        catch (Exception)
                        {
                        }
                        txtOut.Document = new FlowDocument();
                        continue;
                    }

                    if (Model == null)
                    {
                        ReportAdd("Plaese open a database.", Brushes.Red);
                        continue;
                    }

                    // all commands here
                    //
                    var m = Regex.Match(cmd, @"^(entitylabel|el) (?<el>\d+)(?<recursion> -*\d+)*", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        int recursion = 0;
                        int v = Convert.ToInt32(m.Groups["el"].Value);
                        try
                        {
                            recursion = Convert.ToInt32(m.Groups["recursion"].Value);
                        }
                        catch (Exception)
                        {
                        }

                        ReportAdd(ReportEntity(v, recursion));
                        continue;
                    }

                    m = Regex.Match(cmd, @"^(Header|he)$", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        if (Model.Header == null)
                        {
                            ReportAdd("Model header is not defined.", Brushes.Red);
                            continue;
                        }
                        ReportAdd("FileDescription:");
                        foreach (var item in Model.Header.FileDescription.Description)
                        {
                            ReportAdd(string.Format("- Description: {0}", item));
                        }
                        ReportAdd(string.Format("- ImplementationLevel: {0}", Model.Header.FileDescription.ImplementationLevel));
                        ReportAdd(string.Format("- EntityCount: {0}", Model.Header.FileDescription.EntityCount));

                        ReportAdd("FileName:");
                        ReportAdd(string.Format("- Name: {0}", Model.Header.FileName.Name));
                        ReportAdd(string.Format("- TimeStamp: {0}", Model.Header.FileName.TimeStamp));
                        foreach (var item in Model.Header.FileName.Organization)
                        {
                            ReportAdd(string.Format("- Organization: {0}", item));
                        }
                        ReportAdd(string.Format("- OriginatingSystem: {0}", Model.Header.FileName.OriginatingSystem));
                        ReportAdd(string.Format("- PreprocessorVersion: {0}", Model.Header.FileName.PreprocessorVersion));
                        foreach (var item in Model.Header.FileName.AuthorName)
                        {
                            ReportAdd(string.Format("- AuthorName: {0}", item));
                        }

                        ReportAdd(string.Format("- AuthorizationName: {0}", Model.Header.FileName.AuthorizationName));
                        foreach (var item in Model.Header.FileName.AuthorizationMailingAddress)
                        {
                            ReportAdd(string.Format("- AuthorizationMailingAddress: {0}", item));
                        }

                        ReportAdd("FileSchema:");
                        foreach (var item in Model.Header.FileSchema.Schemas)
                        {
                            ReportAdd(string.Format("- Schema: {0}", item));
                        }
                        continue;
                    }

                    // SelectionHighlighting [WholeMesh|Normals]
                    m = Regex.Match(cmd, @"^(SelectionHighlighting|sh) (?<mode>(wholemesh|normals))+", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        string mode = m.Groups["mode"].Value.ToLowerInvariant();
                        if (mode == "normals")
                        {
                            ReportAdd("Selection visual style set to 'Normals'");
                            ParentWindow.DrawingControl.SelectionHighlightMode = DrawingControl3D.SelectionHighlightModes.Normals;
                        }
                        else
                        {
                            ReportAdd("Selection visual style set to 'WholeMesh'");
                            ParentWindow.DrawingControl.SelectionHighlightMode = DrawingControl3D.SelectionHighlightModes.WholeMesh;
                        }
                        continue;
                    }

                    m = Regex.Match(cmd, @"^(IfcSchema|is) (?<mode>(list|count|short|full) )*(?<type>.+)", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        string type = m.Groups["type"].Value;
                        string mode = m.Groups["mode"].Value;

                        if (type == "/")
                        {
                        }
                        else if (type == PrepareRegex(type)) // there's not a regex expression, we will prepare one assuming the search for a bare name.
                        {
                            type = @".*\." + type + "$"; // any character repeated then a dot then the name and the end of line
                        }
                        else
                            type = PrepareRegex(type);

                        var TypeList = MatchingTypes(type);

                        if (mode.ToLower() == "list ")
                        {
                            foreach (var item in TypeList)
                                ReportAdd(item);
                        }
                        else if (mode.ToLower() == "count ")
                        {
                            ReportAdd("count: " + TypeList.Count());
                        }
                        else
                        {
                            // report
                            int  BeVerbose = 1;
                            if (mode.ToLower() == "short ")
                                BeVerbose = 0;
                            if (mode.ToLower() == "full ")
                                BeVerbose = 2;
                            foreach (var item in TypeList)
                            {
                                ReportAdd(ReportType(item, BeVerbose));
                            }
                        }
                        continue;
                    }

                    m = Regex.Match(cmd, @"^(reload|re) *(?<entities>([\d,]+|[^ ]+))", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        string start = m.Groups["entities"].Value;
                        IEnumerable<int> labels = tointarray(start, ',');
                        if (labels.Count() > 0)
                        {
                            ParentWindow.DrawingControl.LoadGeometry(Model, labels);
                        }
                        else
                        {
                            ParentWindow.DrawingControl.LoadGeometry(Model);
                        }
                        continue;
                    }

                    m = Regex.Match(cmd, @"^(GeometryInfo|gi) (?<mode>(binary|viewer) )*(?<entities>([\d,]+|[^ ]+))", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        string start = m.Groups["entities"].Value;
                        string mode = m.Groups["mode"].Value;
                        IEnumerable<int> labels = tointarray(start, ',');
                        foreach (var item in labels)
                        {
                            ReportAdd("Geometry for: " + item.ToString(), Brushes.Green);
                            ReportAdd(GeomQuerying.GeomInfoBoundBox(Model, item));
                            ReportAdd(GeomQuerying.GeomLayers(Model, item, ParentWindow.DrawingControl.scenes));
                            if (mode == "binary ")
                            {
                                ReportAdd(GeomQuerying.GeomInfoMesh(Model, item));
                            }
                            if (mode == "viewer ")
                            {
                                ReportAdd(
                                    GeomQuerying.Viewerdata(ParentWindow.DrawingControl, Model, item)
                                    );
                            }
                        }
                        continue;
                    }

                    m = Regex.Match(cmd, @"^(select|se) (?<mode>(count|list|short) )*(?<tt>(transverse|tt) )*(?<hi>(highlight|hi) )*(?<start>([\d,-]+|[^ ]+)) *(?<props>.*)", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        string start = m.Groups["start"].Value;
                        string props = m.Groups["props"].Value;
                        string mode = m.Groups["mode"].Value;

                        // transverse tree mode
                        bool transverseT = false;
                        string transverse = m.Groups["tt"].Value;
                        if (transverse != "")
                            transverseT = true;

                        bool Highlight = false;
                        string HighlightT = m.Groups["hi"].Value;
                        if (HighlightT != "")
                            Highlight = true;

                        IEnumerable<int> labels = tointarray(start, ',');
                        IEnumerable<int> ret = null;
                        if (labels.Count() == 0)
                        {
                            // see if it's a type string instead
                            SquareBracketIndexer sbi = new SquareBracketIndexer(start);
                            labels = QueryEngine.EntititesForType(sbi.Property, Model);
                            labels = sbi.getItem(labels);
                        }
                        ret = QueryEngine.RecursiveQuery(Model, props, labels, transverseT);

                        // textual report
                        if (mode.ToLower() == "count ")
                        {
                            ReportAdd(string.Format("Count: {0}", ret.Count()));
                        }
                        else if (mode.ToLower() == "list ")
                        {
                            foreach (var item in ret)
                            {
                                ReportAdd(item.ToString());
                            }
                        }
                        else
                        {
                            bool BeVerbose = true;
                            if (mode.ToLower() == "short ")
                                BeVerbose = false;
                            foreach (var item in ret)
                            {
                                ReportAdd(ReportEntity(item, 0, Verbose: BeVerbose));
                            }
                        }
                        // visual selection
                        if (Highlight)
                        {
                            EntitySelection s = new EntitySelection();
                            foreach (var item in ret)
                            {
                                s.Add(Model.Instances[item]);
                            }
                            ParentWindow.DrawingControl.Selection = s;
                        }
                        continue;
                    }

                    m = Regex.Match(cmd, @"^zoom (" +
                        @"(?<RegionName>.+$)" +
                        ")", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        string RName = m.Groups["RegionName"].Value;
                        var regionData = Model.GetGeometryData(Xbim.XbimExtensions.XbimGeometryType.Region).FirstOrDefault();
                        if (regionData == null)
                        {
                            ReportAdd("data not found");
                        }
                        XbimRegionCollection regions = XbimRegionCollection.FromArray(regionData.ShapeData);
                        var reg = regions.Where(x => x.Name == RName).FirstOrDefault();
                        if (reg != null)
                        {
                            XbimMatrix3D mcp = XbimMatrix3D.Copy(ParentWindow.DrawingControl.wcsTransform);
                            var bb = reg.Centre;
                            var tC = mcp.Transform(reg.Centre);
                            var tS = mcp.Transform(reg.Size);
                            XbimRect3D r3d = new XbimRect3D(
                                tC.X - tS.X / 2, tC.Y - tS.Y / 2, tC.Z - tS.Z / 2,
                                tS.X, tS.X, tS.Z
                                );
                            ParentWindow.DrawingControl.ZoomTo(r3d);
                            ParentWindow.Activate();
                            continue;
                        }
                        else
                        {
                            ReportAdd(string.Format("Something wrong with region name: '{0}'", RName));
                            ReportAdd("Names that should work are: ");
                            foreach (var str in regions)
                            {
                                ReportAdd(string.Format(" - '{0}'", str.Name));
                            }
                            continue;
                        }
                    }

                    m = Regex.Match(cmd, @"^clip off$", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        ParentWindow.DrawingControl.ClearCutPlane();
                        ReportAdd("Clip removed");
                        ParentWindow.Activate();
                        continue;
                    }

                    m = Regex.Match(cmd, @"^clip (" +
                        @"(?<elev>[-+]?([0-9]*\.)?[0-9]+) *$" +
                        "|" +
                        @"(?<px>[-+]?([0-9]*\.)?[0-9]+) *, *" +
                        @"(?<py>[-+]?([0-9]*\.)?[0-9]+) *, *" +
                        @"(?<pz>[-+]?([0-9]*\.)?[0-9]+) *, *" +
                        @"(?<nx>[-+]?([0-9]*\.)?[0-9]+) *, *" +
                        @"(?<ny>[-+]?([0-9]*\.)?[0-9]+) *, *" +
                        @"(?<nz>[-+]?([0-9]*\.)?[0-9]+)" +
                        "|" +
                        @"(?<StoreyName>.+$)" +
                        ")", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        double px = 0, py = 0, pz = 0;
                        double nx = 0, ny = 0, nz = -1;

                        if (m.Groups["elev"].Value != string.Empty)
                        {
                            pz = Convert.ToDouble(m.Groups["elev"].Value);
                        }
                        else if (m.Groups["StoreyName"].Value != string.Empty)
                        {
                            string msg = "";
                            string storName = m.Groups["StoreyName"].Value;
                            var storey = Model.Instances.OfType<Xbim.Ifc2x3.ProductExtension.IfcBuildingStorey>().Where(x => x.Name == storName).FirstOrDefault();
                            if (storey != null)
                            {
                                //get the object position data (should only be one)
                                Xbim.XbimExtensions.XbimGeometryData geomdata = Model.GetGeometryData(storey.EntityLabel, Xbim.XbimExtensions.XbimGeometryType.TransformOnly).FirstOrDefault();
                                if (geomdata != null)
                                {
                                    Xbim.Common.Geometry.XbimPoint3D pt = new Xbim.Common.Geometry.XbimPoint3D(0, 0, geomdata.Transform.OffsetZ);
                                    Xbim.Common.Geometry.XbimMatrix3D mcp = Xbim.Common.Geometry.XbimMatrix3D.Copy(ParentWindow.DrawingControl.wcsTransform);
                                    var transformed = mcp.Transform(pt);
                                    msg = string.Format("Clip 1m above storey elevation {0} (height: {1})", pt.Z, transformed.Z + 1);
                                    pz = transformed.Z + 1;
                                }
                            }
                            if (msg == "")
                            {
                                ReportAdd(string.Format("Something wrong with storey name: '{0}'", storName));
                                ReportAdd("Names that should work are: ");
                                var strs = Model.Instances.OfType<Xbim.Ifc2x3.ProductExtension.IfcBuildingStorey>();
                                foreach (var str in strs)
                                {
                                    ReportAdd(string.Format(" - '{0}'", str.Name));
                                }
                                continue;
                            }
                            ReportAdd(msg);
                        }
                        else
                        {
                            px = Convert.ToDouble(m.Groups["px"].Value);
                            py = Convert.ToDouble(m.Groups["py"].Value);
                            pz = Convert.ToDouble(m.Groups["pz"].Value);
                            nx = Convert.ToDouble(m.Groups["nx"].Value);
                            ny = Convert.ToDouble(m.Groups["ny"].Value);
                            nz = Convert.ToDouble(m.Groups["nz"].Value);
                        }

                        ParentWindow.DrawingControl.ClearCutPlane();
                        ParentWindow.DrawingControl.SetCutPlane(
                            px, py, pz,
                            nx, ny, nz
                            );

                        ReportAdd("Clip command sent");
                        ParentWindow.Activate();
                        continue;
                    }

                    m = Regex.Match(cmd, @"^Styler (?<command>.+)", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        var st = ParentWindow.DrawingControl.LayerStyler as Xbim.Presentation.LayerStyling.LayerStylerTypeAndIFCStyleExtended;
                        if (st != null)
                        {
                            string command = m.Groups["command"].Value;
                            ReportAdd(
                                st.SendCommand(command, ParentWindow.DrawingControl.Selection)
                                );
                            ParentWindow.DrawingControl.ReloadModel();
                        }
                        else
                        {
                            ReportAdd("Command not valid under current styler configuration.");
                        }
                        continue;
                    }

                    m = Regex.Match(cmd, @"^Visual (?<action>list|tree|on|off|mode)( (?<Name>[^ ]+))*", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        string Name = m.Groups["Name"].Value;
                        if (m.Groups["action"].Value.ToLowerInvariant() == "list")
                        {
                            foreach (var item in ParentWindow.DrawingControl.ListItems(Name))
                            {
                                ReportAdd(item);
                            }
                        }
                        else if (m.Groups["action"].Value.ToLowerInvariant() == "tree")
                        {
                            foreach (var item in ParentWindow.DrawingControl.LayersTree())
                            {
                                ReportAdd(item);
                            }
                        }
                        else if (m.Groups["action"].Value.ToLowerInvariant() == "mode")
                        {
                            string t = Name.ToLowerInvariant();
                            if (t == "type")
                            {
                                ReportAdd("Visual mode set to EntityType.");
                                ParentWindow.DrawingControl.LayerStyler = new Xbim.Presentation.LayerStyling.LayerStylerTypeAndIFCStyle();
                                ParentWindow.DrawingControl.ReloadModel(Options: DrawingControl3D.ModelRefreshOptions.ViewPreserveAll);
                            }
                            else if (t == "entity")
                            {
                                ReportAdd("Visual mode set to EntityLabel.");
                                ParentWindow.DrawingControl.LayerStyler = new Xbim.Presentation.LayerStyling.LayerStylerPerEntity();
                                ParentWindow.DrawingControl.ReloadModel(Options: DrawingControl3D.ModelRefreshOptions.ViewPreserveAll);
                            }
                            else if (t == "oddeven")
                            {
                                ReportAdd("Visual mode set to Odd/Even.");
                                ParentWindow.DrawingControl.LayerStyler = new Xbim.Presentation.LayerStyling.LayerStylerEvenOdd();
                                ParentWindow.DrawingControl.ReloadModel(Options: DrawingControl3D.ModelRefreshOptions.ViewPreserveAll);
                            }
                            else if (t == "demo")
                            {
                                ReportAdd("Visual mode set to Demo.");
                                ParentWindow.DrawingControl.LayerStyler = new Xbim.Presentation.LayerStyling.LayerStylerTypeAndIFCStyleExtended();
                                ParentWindow.DrawingControl.ReloadModel(Options: DrawingControl3D.ModelRefreshOptions.ViewPreserveAll);
                            }
                            else
                                ReportAdd(string.Format("mode not understood: {0}.", t));
                        }
                        else
                        {
                            bool bVis = false;
                            if (m.Groups["action"].Value.ToLowerInvariant() == "on")
                                bVis = true;
                            ParentWindow.DrawingControl.SetVisibility(Name, bVis);
                        }
                        continue;
                        }
                    m = Regex.Match(cmd, @"^SimplifyGUI$", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        XbimXplorer.Simplify.IfcSimplify s = new Simplify.IfcSimplify();
                        s.Show();
                        continue;
                    }

                    m = Regex.Match(cmd, @"^test$", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        int iPass = -728;
                        ReportAdd(RunTestCode(iPass));
                        continue;
                    }
                    ReportAdd(string.Format("Command not understood: {0}.", cmd));
                }
            }
        }
        private void ClearGraphics(bool recalcView = true)
        {
           
            _selection = new EntitySelection();
         //   UserModeledDimension.Clear();

            Opaques.Children.Clear();
            Transparents.Children.Clear();
            Extras.Children.Clear();
           // this.ClearCutPlane();
            Highlighted.Mesh = null;

            if (recalcView)
            {
                _modelBounds = XbimRect3D.Empty;
                _viewBounds = new XbimRect3D(0, 0, 0, 10, 10, 5);
                Viewport.ResetCamera();
            }

        }
示例#18
0
 public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling)
 {
     if (byEntity.LeftHandItemSlot.Itemstack != null)
     {
         Item leftHandItem = byEntity.LeftHandItemSlot.Itemstack.Item;
         if (leftHandItem.Code.ToString() == "sharper:whetstone")
         {
             if (this.api.Side == EnumAppSide.Client)
             {
                 ((ICoreClientAPI)this.api).StartTrack(new AssetLocation("sharper", "music/whetstone"), 1, EnumSoundType.Sound);
             }
             this.AttackPower += 0.1f;
             this.DamageItem(byEntity.World, byEntity, slot, 10);
             leftHandItem.DamageItem(byEntity.World, byEntity, byEntity.LeftHandItemSlot, 10);
             return;
         }
     }
     base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handling);
 }
示例#19
0
        public override void OnHeldInteractStart(IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling)
        {
            BlockPos pos = blockSel.Position;

            AssetLocation asset = new AssetLocation("amethyst:amethyst-dust-isolated-unlit");

            if (pos != null && !api.World.BlockAccessor.GetBlock(pos + new BlockPos(0, 1, 0)).WildCardMatch(new AssetLocation("amethyst:amethyst-dust*")) && !api.World.BlockAccessor.GetBlock(pos).WildCardMatch(new AssetLocation("amethyst:amethyst-dust*")))
            {
                api.World.BlockAccessor.SetBlock(api.World.BlockAccessor.GetBlock(asset).BlockId, pos + new BlockPos(0, 1, 0));
                slot.TakeOut(1);
                slot.MarkDirty();
                api.World.PlaySoundAt(api.World.BlockAccessor.GetBlock(asset).Sounds.Place, pos.X, pos.Y, pos.Z);
                return;
            }
            return;
        }
示例#20
0
 public override void OnHeldAttackStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling)
 {
 }
示例#21
0
        /// <summary>
        /// Called every frame while the player is using this collectible. Return false to stop the interaction.
        /// </summary>
        /// <param name="secondsUsed"></param>
        /// <param name="slot"></param>
        /// <param name="byEntity"></param>
        /// <param name="blockSel"></param>
        /// <param name="entitySel"></param>
        /// <returns>False if the interaction should be stopped. True if the interaction should continue</returns>
        public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (GetContentNutritionProperties(byEntity.World, slot, byEntity) == null)
            {
                return(false);
            }

            Vec3d pos = byEntity.Pos.AheadCopy(0.4f).XYZ.Add(byEntity.LocalEyePos);

            pos.Y -= 0.4f;

            IPlayer player = (byEntity as EntityPlayer).Player;

            if (secondsUsed > 0.5f && (int)(30 * secondsUsed) % 7 == 1)
            {
                ItemStack[] contents = GetNonEmptyContents(byEntity.World, slot.Itemstack);
                if (contents.Length > 0)
                {
                    ItemStack rndStack = contents[byEntity.World.Rand.Next(contents.Length)];
                    byEntity.World.SpawnCubeParticles(pos, rndStack, 0.3f, 4, 1, player);
                }
            }


            if (byEntity.World is IClientWorldAccessor)
            {
                ModelTransform tf = new ModelTransform();
                tf.Origin.Set(1.1f, 0.5f, 0.5f);
                tf.EnsureDefaultValues();

                tf.Translation.X -= Math.Min(1.7f, secondsUsed * 4 * 1.8f) / FpHandTransform.ScaleXYZ.X;
                tf.Translation.Y += Math.Min(0.4f, secondsUsed * 1.8f) / FpHandTransform.ScaleXYZ.X;
                tf.Scale          = 1 + Math.Min(0.5f, secondsUsed * 4 * 1.8f) / FpHandTransform.ScaleXYZ.X;
                tf.Rotation.X    += Math.Min(40f, secondsUsed * 350 * 0.75f) / FpHandTransform.ScaleXYZ.X;

                if (secondsUsed > 0.5f)
                {
                    tf.Translation.Y += GameMath.Sin(30 * secondsUsed) / 10 / FpHandTransform.ScaleXYZ.Y;
                }

                byEntity.Controls.UsingHeldItemTransformBefore = tf;


                return(secondsUsed <= 1.5f);
            }

            // Let the client decide when he is done eating
            return(true);
        }
示例#22
0
 public override bool OnHeldAttackCancel(float secondsPassed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSelection, EntitySelection entitySel, EnumItemUseCancelReason cancelReason)
 {
     return(false);
 }
示例#23
0
        /// <summary>
        /// Called when the player successfully completed the using action, always called once an interaction is over
        /// </summary>
        /// <param name="secondsUsed"></param>
        /// <param name="slot"></param>
        /// <param name="byEntity"></param>
        /// <param name="blockSel"></param>
        /// <param name="entitySel"></param>
        public override void OnHeldInteractStop(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            FoodNutritionProperties[] multiProps = GetContentNutritionProperties(byEntity.World, slot, byEntity);

            if (byEntity.World.Side == EnumAppSide.Server && multiProps != null && secondsUsed >= 1.45f)
            {
                ItemStack eatenFromBowlStack = slot.TakeOut(1);
                slot.MarkDirty();
                IPlayer player = (byEntity as EntityPlayer).Player;

                float       servingsLeft = GetQuantityServings(byEntity.World, eatenFromBowlStack);
                ItemStack[] stacks       = GetNonEmptyContents(api.World, eatenFromBowlStack);

                if (stacks.Length == 0)
                {
                    servingsLeft = 0;
                }
                else
                {
                    string recipeCode = GetRecipeCode(api.World, eatenFromBowlStack);
                    servingsLeft = Consume(byEntity.World, player, slot, stacks, servingsLeft, recipeCode == null || recipeCode == "");
                }


                if (servingsLeft <= 0)
                {
                    Block block = byEntity.World.GetBlock(new AssetLocation(Attributes["eatenBlock"].AsString()));

                    if (slot.Empty)
                    {
                        slot.Itemstack = new ItemStack(block);
                    }
                    else
                    {
                        if (player == null || !player.InventoryManager.TryGiveItemstack(new ItemStack(block), true))
                        {
                            byEntity.World.SpawnItemEntity(new ItemStack(block), byEntity.SidedPos.XYZ);
                        }
                    }
                }
                else
                {
                    (eatenFromBowlStack.Collectible as BlockMeal).SetQuantityServings(byEntity.World, eatenFromBowlStack, servingsLeft);

                    if (slot.Empty)
                    {
                        slot.Itemstack = eatenFromBowlStack;
                    }
                    else
                    {
                        if (player == null || !player.InventoryManager.TryGiveItemstack(eatenFromBowlStack, true))
                        {
                            byEntity.World.SpawnItemEntity(eatenFromBowlStack, byEntity.SidedPos.XYZ);
                        }
                    }
                }
            }
        }
示例#24
0
 public override void OnHeldAttackStop(float secondsPassed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSelection, EntitySelection entitySel)
 {
 }
示例#25
0
        public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling)
        {
            if (!byEntity.Controls.Sneak && GetContentNutritionProperties(byEntity.World, slot, byEntity) != null)
            {
                byEntity.World.RegisterCallback((dt) =>
                {
                    if (byEntity.Controls.HandUse == EnumHandInteract.HeldItemInteract)
                    {
                        byEntity.PlayEntitySound("eat", (byEntity as EntityPlayer)?.Player);
                    }
                }, 500);

                handHandling = EnumHandHandling.PreventDefault;
                return;
            }

            base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handHandling);
        }
示例#26
0
        public override void OnHeldInteractStop(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (entitySel == null || secondsUsed < 1.05f)
            {
                return;
            }
            if (entitySel.Entity is EntityPlayer)
            {
                return;
            }

            int generation = entitySel.Entity.WatchedAttributes.GetInt("generation", 0);

            slot?.Itemstack?.Collectible.DamageItem(byEntity.World, byEntity, slot, 1);

            float slaughterChance = generation / 3f;
            float dmg             = 9999;

            if (api.World.Rand.NextDouble() > slaughterChance)
            {
                dmg = 1;
            }

            entitySel.Entity.ReceiveDamage(new DamageSource()
            {
                DamageTier   = 0,
                HitPosition  = entitySel.HitPosition,
                Source       = EnumDamageSource.Player,
                SourceEntity = byEntity,
                Type         = EnumDamageType.SlashingAttack
            }, dmg);
        }
示例#27
0
        public override void OnHeldInteractStart(IItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling)
        {
            if (byEntity.World.Side == EnumAppSide.Client)
            {
                handling = EnumHandHandling.PreventDefaultAction;
                return;
            }
            if (blockSel == null)
            {
                return;
            }

            ModSystemBlockReinforcement bre = byEntity.Api.ModLoader.GetModSystem <ModSystemBlockReinforcement>();

            IPlayer player = (byEntity as EntityPlayer).Player;

            if (player == null)
            {
                return;
            }

            ItemSlot resSlot = bre.FindResourceForReinforcing(player);

            if (resSlot == null)
            {
                return;
            }

            int strength = resSlot.Itemstack.ItemAttributes["reinforcementStrength"].AsInt(0);

            if (!bre.StrengthenBlock(blockSel.Position, player, strength))
            {
                (player as IServerPlayer).SendMessage(GlobalConstants.CurrentChatGroup, "Cannot reinforce block, it's already reinforced!", EnumChatType.Notification);
                return;
            }

            resSlot.TakeOut(1);
            resSlot.MarkDirty();

            BlockPos pos = blockSel.Position;

            byEntity.World.PlaySoundAt(new AssetLocation("blockreinforcement", "sounds/reinforce"), pos.X, pos.Y, pos.Z, null);

            handling = EnumHandHandling.PreventDefaultAction;
        }
示例#28
0
 public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling)
 {
     handling = EnumHandHandling.Handled;
 }
示例#29
0
        public override void OnHeldAttackStart(IItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling)
        {
            if (byEntity.World.Side == EnumAppSide.Client)
            {
                handling = EnumHandHandling.PreventDefaultAction;
                return;
            }

            if (blockSel == null)
            {
                return;
            }

            ModSystemBlockReinforcement bre = byEntity.Api.ModLoader.GetModSystem <ModSystemBlockReinforcement>();
            IServerPlayer player            = (byEntity as EntityPlayer).Player as IServerPlayer;

            if (player == null)
            {
                return;
            }

            string errorCode = "";

            if (!bre.TryRemoveReinforcement(blockSel.Position, player, ref errorCode))
            {
                player.SendMessage(GlobalConstants.CurrentChatGroup, "Cannot remove reinforcement: " + errorCode, EnumChatType.Notification);
                return;
            }

            BlockPos pos = blockSel.Position;

            byEntity.World.PlaySoundAt(new AssetLocation("blockreinforcement", "sounds/reinforce"), pos.X, pos.Y, pos.Z, null);

            handling = EnumHandHandling.PreventDefaultAction;
        }
示例#30
0
        public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling)
        {
            if (byEntity.Controls.Sneak)
            {
                base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handHandling);
                return;
            }

            IPlayer byPlayer = (byEntity as EntityPlayer)?.Player;

            if (byPlayer == null)
            {
                return;
            }

            IInventory inv = byPlayer.InventoryManager.GetOwnInventory(GlobalConstants.characterInvClassName);

            if (inv == null)
            {
                return;
            }
            if (DressType == EnumCharacterDressType.Unknown)
            {
                return;
            }

            if (inv[(int)DressType].TryFlipWith(slot))
            {
                handHandling = EnumHandHandling.PreventDefault;
            }
        }
示例#31
0
        public override void OnHeldInteractStart(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling)
        {
            if (blockSel == null || byEntity?.World == null || !byEntity.Controls.Sneak)
            {
                return;
            }

            IPlayer byPlayer = null;

            if (byEntity is EntityPlayer)
            {
                byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID);
            }
            if (byPlayer == null)
            {
                return;
            }

            if (!byEntity.World.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak))
            {
                itemslot.MarkDirty();
                return;
            }

            BlockIngotPile block = byEntity.World.GetBlock(new AssetLocation("ingotpile")) as BlockIngotPile;

            if (block == null)
            {
                return;
            }

            BlockEntity be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position);

            if (be is BlockEntityIngotPile)
            {
                BlockEntityIngotPile pile = (BlockEntityIngotPile)be;
                if (pile.OnPlayerInteract(byPlayer))
                {
                    handHandling = EnumHandHandling.PreventDefault;
                }
                return;
            }

            if (be is BlockEntityAnvil)
            {
                return;
            }

            BlockPos pos = blockSel.Position.AddCopy(blockSel.Face);

            if (byEntity.World.BlockAccessor.GetBlock(pos).Replaceable < 6000)
            {
                return;
            }

            be = byEntity.World.BlockAccessor.GetBlockEntity(pos);
            if (be is BlockEntityIngotPile)
            {
                BlockEntityIngotPile pile = (BlockEntityIngotPile)be;
                if (pile.OnPlayerInteract(byPlayer))
                {
                    handHandling = EnumHandHandling.PreventDefault;
                }
                return;
            }


            if (block.Construct(itemslot, byEntity.World, blockSel.Position.AddCopy(blockSel.Face), byPlayer))
            {
                handHandling = EnumHandHandling.PreventDefault;
            }
        }
示例#32
0
        public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling)
        {
            if (blockSel == null || byEntity?.World == null || !byEntity.Controls.Sneak)
            {
                return;
            }

            BlockPos onBlockPos = blockSel.Position;
            Block    block      = byEntity.World.BlockAccessor.GetBlock(onBlockPos);

            if (block is BlockFirepit)
            {
                // Prevent placing firewoodpiles when trying to construct firepits
                return;
            }

            base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handling);
        }
示例#33
0
 public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling)
 {
     if (blockSel != null && byEntity.World is IServerWorldAccessor)
     {
         ITreeAttribute treeAttributes = slot.Itemstack.Attributes.GetTreeAttribute("farmland");
         if (treeAttributes == null)
         {
             PickupFarmland(slot, byEntity, blockSel);
         }
         else
         {
             PlaceFarmland(slot, byEntity, blockSel, treeAttributes);
         }
     }
     handling = EnumHandHandling.Handled;
 }
        public string SendCommand(string command, EntitySelection entitySelection)
        {
            StringBuilder sb = new StringBuilder();
            Regex re = new Regex("(?<action>HIDE|MT) (?<selection>SET|SE)", RegexOptions.IgnoreCase);
            if (command == "default")
            {
                Initialise();
                SetDefaults();
                sb.AppendLine("Done.");
            }
            else if (command == "reset")
            {
                Initialise();
                sb.AppendLine("Done.");
            }
            else if (re.IsMatch(command))
            {
                var m = re.Match(command);
                string action = m.Groups["action"].Value;
                string selection = m.Groups["selection"].Value;

                if (selection == "set") // selection type
                {
                    var dest = _lightTransparentTypes;
                    if (action == "hide")
                        dest = _hiddenTypes;
                    foreach (var item in entitySelection)
                    {
                        if (!dest.Contains(item.GetType()))
                        {
                            dest.Add(item.GetType());
                        }
                    }
                }
                if (selection == "se") // selection items
                {
                    var dest = _lightTransparentEntities;
                    if (action == "hide")
                        dest = _hiddenEntities;
                    foreach (var item in entitySelection)
                    {
                        int i = Math.Abs(item.EntityLabel);
                        if (!dest.Contains(i))
                        {
                            dest.Add(i);
                        }
                    }
                }
            }
            else
            {
                sb.AppendLine("Command not understood from Styler.");
                sb.AppendLine("- reset");
                sb.AppendLine("- default");
                sb.AppendLine("- HIDE/MT SE/SET");
            }
            return sb.ToString();
        }
示例#35
0
        private void Execute() {
#if DEBUG
            // stores the commands being launched
            var fname = Path.Combine(Path.GetTempPath(), "xbimquerying.txt");
            using (var writer = File.CreateText(fname))
            {
                writer.Write(TxtCommand.Text);
                writer.Flush();
                writer.Close();
            }
#endif

           
            if (_bDoClear)
                TxtOut.Document = new FlowDocument();

            var commandArray = TxtCommand.Text.Split(new[] {"\r\n"}, StringSplitOptions.RemoveEmptyEntries);
            if (TxtCommand.SelectedText != string.Empty)
                commandArray = TxtCommand.SelectedText.Split(new[] {"\r\n"}, StringSplitOptions.RemoveEmptyEntries);

            foreach (var cmdF in commandArray)
            {
                ReportAdd("> " + cmdF, Brushes.ForestGreen);
                var cmd = cmdF;
                var i = cmd.IndexOf("//", StringComparison.Ordinal);
                if (i > 0)
                {
                    cmd = cmd.Substring(0, i);
                }
                if (cmd.TrimStart().StartsWith("//"))
                    continue;

                // put here all commands that don't require a database open
                var mdbclosed = Regex.Match(cmd, @"^help$", RegexOptions.IgnoreCase);
                if (mdbclosed.Success)
                {
                    DisplayHelp();
                    continue;
                }

                mdbclosed = Regex.Match(cmd, @"^Plugin Refresh$", RegexOptions.IgnoreCase);
                if (mdbclosed.Success)
                {
                    if (_parentWindow != null)
                        _parentWindow.RefreshPlugins();
                    continue;
                }

                mdbclosed = Regex.Match(cmd, @"^Plugin Load (?<assemblyName>.+)$", RegexOptions.IgnoreCase);
                if (mdbclosed.Success)
                {
                    var assemblyName = mdbclosed.Groups["assemblyName"].Value;
                    if (File.Exists(assemblyName))
                        if (_parentWindow != null && _parentWindow is XplorerMainWindow)
                            ((XplorerMainWindow)_parentWindow).LoadPlugin(assemblyName);
                    continue;
                }

                mdbclosed = Regex.Match(cmd, @"^xplorer$", RegexOptions.IgnoreCase);
                if (mdbclosed.Success)
                {
                    if (_parentWindow != null)
                        _parentWindow.Focus();
                    else
                    {
                        // todo: bonghi: open the model in xplorer if needed.
                        var xp = new XplorerMainWindow();
                        _parentWindow = xp;
                        xp.Show();
                    }
                    continue;
                }

                mdbclosed = Regex.Match(cmd, @"^versions$", RegexOptions.IgnoreCase);
                if (mdbclosed.Success)
                {
                    var asms = AppDomain.CurrentDomain.GetAssemblies();
                    ReportAdd("List of loaded assemblies:", Brushes.Black);
                    foreach (var asm in asms)
                    {
                        var asmName = asm.GetName();
                        ReportAdd(string.Format(" - {0}", asmName.FullName), Brushes.Black);
                    }
                    continue;
                }

                mdbclosed = Regex.Match(cmd, @"clear *\b(?<mode>(on|off))*", RegexOptions.IgnoreCase);
                if (mdbclosed.Success)
                {
                    try
                    {
                        var option = mdbclosed.Groups["mode"].Value;

                        if (option == "")
                        {
                            TxtOut.Document = new FlowDocument();
                            continue;
                        }
                        if (option == "on")
                            _bDoClear = true;
                        else if (option == "off")
                            _bDoClear = false;
                        else
                        {
                            ReportAdd(string.Format("Autoclear not changed ({0} is not a valid option).", option));
                            continue;
                        }
                        ReportAdd(string.Format("Autoclear set to {0}", option.ToLower()));
                        continue;
                    }
// ReSharper disable once EmptyGeneralCatchClause
                    catch
                    {
                    }
                    TxtOut.Document = new FlowDocument();
                    continue;
                }


                if (Model == null)
                {
                    ReportAdd("Plaese open a database.", Brushes.Red);
                    continue;
                }

                // all commands here
                //
                var m = Regex.Match(cmd, @"^(entitylabel|el) (?<el>\d+)(?<recursion> -*\d+)*",
                    RegexOptions.IgnoreCase);
                if (m.Success)
                {
                    var recursion = 0;
                    var v = Convert.ToInt32(m.Groups["el"].Value);
                    try
                    {
                        recursion = Convert.ToInt32(m.Groups["recursion"].Value);
                    }
// ReSharper disable once EmptyGeneralCatchClause
                    catch
                    {
                    }

                    ReportAdd(ReportEntity(v, recursion));
                    continue;
                }



                m = Regex.Match(cmd, @"^(Header|he)$", RegexOptions.IgnoreCase);
                if (m.Success)
                {
                    if (Model.Header == null)
                    {
                        ReportAdd("Model header is not defined.", Brushes.Red);
                        continue;
                    }
                    ReportAdd("FileDescription:");
                    foreach (var item in Model.Header.FileDescription.Description)
                    {
                        ReportAdd(string.Format("- Description: {0}", item));
                    }
                    ReportAdd(string.Format("- ImplementationLevel: {0}",
                        Model.Header.FileDescription.ImplementationLevel));
                    ReportAdd(string.Format("- EntityCount: {0}", Model.Header.FileDescription.EntityCount));

                    ReportAdd("FileName:");
                    ReportAdd(string.Format("- Name: {0}", Model.Header.FileName.Name));
                    ReportAdd(string.Format("- TimeStamp: {0}", Model.Header.FileName.TimeStamp));
                    foreach (var item in Model.Header.FileName.Organization)
                    {
                        ReportAdd(string.Format("- Organization: {0}", item));
                    }
                    ReportAdd(string.Format("- OriginatingSystem: {0}", Model.Header.FileName.OriginatingSystem));
                    ReportAdd(string.Format("- PreprocessorVersion: {0}", Model.Header.FileName.PreprocessorVersion));
                    foreach (var item in Model.Header.FileName.AuthorName)
                    {
                        ReportAdd(string.Format("- AuthorName: {0}", item));
                    }

                    ReportAdd(string.Format("- AuthorizationName: {0}", Model.Header.FileName.AuthorizationName));
                    foreach (var item in Model.Header.FileName.AuthorizationMailingAddress)
                    {
                        ReportAdd(string.Format("- AuthorizationMailingAddress: {0}", item));
                    }

                    ReportAdd("FileSchema:");
                    foreach (var item in Model.Header.FileSchema.Schemas)
                    {
                        ReportAdd(string.Format("- Schema: {0}", item));
                    }
                    continue;
                }

                // SelectionHighlighting [WholeMesh|Normals]
                m = Regex.Match(cmd, @"^(SelectionHighlighting|sh) (?<mode>(wholemesh|normals|wireframe))+",
                    RegexOptions.IgnoreCase);
                if (m.Success)
                {
                    var mode = m.Groups["mode"].Value.ToLowerInvariant();
                    if (mode == "normals")
                    {
                        ReportAdd("Selection visual style set to 'Normals'");
                        _parentWindow.DrawingControl.SelectionHighlightMode =
                            DrawingControl3D.SelectionHighlightModes.Normals;
                    }
                    else if (mode == "wholemesh")
                    {
                        ReportAdd("Selection visual style set to 'WholeMesh'");
                        _parentWindow.DrawingControl.SelectionHighlightMode =
                            DrawingControl3D.SelectionHighlightModes.WholeMesh;
                    }
                    else if (mode == "wireframe")
                    {
                        ReportAdd("Selection visual style set to 'WireFrame'");
                        _parentWindow.DrawingControl.SelectionHighlightMode =
                            DrawingControl3D.SelectionHighlightModes.WireFrame;
                    }
                    continue;
                }

                m = Regex.Match(cmd, @"^(IfcSchema|is) (?<mode>(list|count|short|full) )*(?<type>\w+)[ ]*",
                    RegexOptions.IgnoreCase);
                if (m.Success)
                {
                    var type = m.Groups["type"].Value;
                    var mode = m.Groups["mode"].Value;

                    if (type == "/")
                    {
                        // this is a magic case handled by the matchingType
                    }
                    else if (type == PrepareRegex(type))
                        // there's not a regex expression, we will prepare one assuming the search for a bare name.
                    {
                        type = @".*\." + type + "$";
                        // any character repeated then a dot then the name and the end of line
                    }
                    else
                        type = PrepareRegex(type);

                    var typeList = MatchingTypes(type);


                    if (mode.ToLower() == "list ")
                    {
                        foreach (var item in typeList)
                            ReportAdd(item);
                    }
                    else if (mode.ToLower() == "count ")
                    {
                        ReportAdd("count: " + typeList.Count());
                    }
                    else
                    {
                        // report
                        var beVerbose = 1;
                        if (mode.ToLower() == "short ")
                            beVerbose = 0;
                        if (mode.ToLower() == "full ")
                            beVerbose = 2;
                        foreach (var item in typeList)
                        {
                            ReportAdd(ReportType(item, beVerbose));
                        }
                    }
                    continue;
                }

                m = Regex.Match(cmd, @"^(reload|re) *(?<entities>([\d,]+|[^ ]+))", RegexOptions.IgnoreCase);
                if (m.Success)
                {
                    var start = m.Groups["entities"].Value;
                    IEnumerable<int> labels = ToIntarray(start, ',');
                    if (labels.Any())
                    {
                        _parentWindow.DrawingControl.LoadGeometry(Model, labels);
                    }
                    else
                    {
                        _parentWindow.DrawingControl.LoadGeometry(Model);
                    }
                    continue;
                }

                m = Regex.Match(cmd, @"^(GeometryInfo|gi) (?<mode>(binary|viewer) )*(?<entities>([\d,]+|[^ ]+))",
                    RegexOptions.IgnoreCase);
                if (m.Success)
                {
                    var start = m.Groups["entities"].Value;
                    var mode = m.Groups["mode"].Value;
                    IEnumerable<int> labels = ToIntarray(start, ',');
                    foreach (var item in labels)
                    {
                        ReportAdd("Geometry for: " + item, Brushes.Green);
                        ReportAdd(GeomQuerying.GeomInfoBoundBox(Model, item));
                        ReportAdd(GeomQuerying.GeomLayers(Model, item, _parentWindow.DrawingControl.Scenes));
                        if (mode == "binary ")
                        {
                            ReportAdd(GeomQuerying.GeomInfoMesh(Model, item));
                        }
                        if (mode == "viewer ")
                        {
                            ReportAdd(
                                GeomQuerying.Viewerdata(_parentWindow.DrawingControl, Model, item)
                                );
                        }
                    }
                    continue;
                }

                m = Regex.Match(cmd,
                    @"^(select|se) " +
                    @"(?<mode>(count|list|typelist|short|full) )*" +
                    @"(?<tt>(transverse|tt) )*" +
                    @"(?<hi>(highlight|hi) )*" +
                    @"(?<svt>(showvaluetype|svt) )*" +
                    @"(?<start>([\d,-]+|[^ ]+)) *(?<props>.*)",
                    RegexOptions.IgnoreCase);
                if (m.Success)
                {
                    var start = m.Groups["start"].Value;
                    var props = m.Groups["props"].Value;
                    var mode = m.Groups["mode"].Value;
                    var svt = m.Groups["svt"].Value;


                    // transverse tree mode
                    var transverseT = false;
                    var transverse = m.Groups["tt"].Value;
                    if (transverse != "")
                        transverseT = true;

                    var highlight = false;
                    var highlightT = m.Groups["hi"].Value;
                    if (highlightT != "")
                        highlight = true;

                    IEnumerable<int> labels = ToIntarray(start, ',');
                    if (!labels.Any())
                    {
                        // see if it's a type string instead;
                        var subRe = new Regex(@"[\+\-]*([A-Za-z0-9\[\]]+)");
                        var res = subRe.Matches(start);
                        foreach (Match submatch in res)
                        {
                            var modeAdd = !submatch.Value.Contains("-");
                            // the syntax could be IfcWall[10]
                            var sbi = new SquareBracketIndexer(submatch.Groups[1].Value);
                            IEnumerable<int> thisLabels = QueryEngine.EntititesForType(sbi.Property, Model);
                            thisLabels = sbi.GetItem(thisLabels);
                            labels = modeAdd
                                ? labels.Concat(thisLabels)
                                : labels.Where(t => !thisLabels.Contains(t));
                        }
                    }
                    var ret = QueryEngine.RecursiveQuery(Model, props, labels, transverseT);

                    // textual report
                    switch (mode.ToLower())
                    {
                        case "count ":
                            ReportAdd(string.Format("Count: {0}", ret.Count()));
                            break;
                        case "list ":
                            foreach (var item in ret)
                            {
                                ReportAdd(item.ToString(CultureInfo.InvariantCulture));
                            }
                            break;
                        case "typelist ":
                            foreach (var item in ret)
                            {
                                ReportAdd(item + "\t" + Model.Instances[item].IfcType().Name);
                            }
                            break;
                        default:
                            var beVerbose = false;
                            if (mode.ToLower() == "short ")
                                beVerbose = false;
                            if (mode.ToLower() == "full ")
                                beVerbose = true;
                            var svtB = (svt != "");
                            foreach (var item in ret)
                            {
                                ReportAdd(ReportEntity(item, 0, verbose: beVerbose, showValueType: svtB));
                            }
                            break;
                    }
                    // visual selection
                    if (highlight)
                    {
                        var s = new EntitySelection();
                        foreach (var item in ret)
                        {
                            s.Add(Model.Instances[item]);
                        }
                        _parentWindow.DrawingControl.Selection = s;
                    }
                    continue;
                }

                m = Regex.Match(cmd, @"^zoom (" +
                                     @"(?<RegionName>.+$)" +
                                     ")", RegexOptions.IgnoreCase);
                if (m.Success)
                {
                    var rName = m.Groups["RegionName"].Value;
                    var regionData = Model.GetGeometryData(XbimGeometryType.Region).FirstOrDefault();
                    if (regionData == null)
                    {
                        ReportAdd("data not found");
                    }
                    var regions = XbimRegionCollection.FromArray(regionData.ShapeData);
                    var reg = regions.FirstOrDefault(x => x.Name == rName);
                    if (reg != null)
                    {
                        var mcp = XbimMatrix3D.Copy(_parentWindow.DrawingControl.ModelPositions[Model].Transfrom);
                        var tC = mcp.Transform(reg.Centre);
                        var tS = mcp.Transform(reg.Size);
                        var r3D = new XbimRect3D(
                            tC.X - tS.X/2, tC.Y - tS.Y/2, tC.Z - tS.Z/2,
                            tS.X, tS.X, tS.Z
                            );
                        _parentWindow.DrawingControl.ZoomTo(r3D);
                        _parentWindow.Activate();
                        continue;
                    }
                    else
                    {
                        ReportAdd(string.Format("Something wrong with region name: '{0}'", rName));
                        ReportAdd("Names that should work are: ");
                        foreach (var str in regions)
                        {
                            ReportAdd(string.Format(" - '{0}'", str.Name));
                        }
                        continue;
                    }
                }

                m = Regex.Match(cmd, @"^clip off$", RegexOptions.IgnoreCase);
                if (m.Success)
                {
                    _parentWindow.DrawingControl.ClearCutPlane();
                    ReportAdd("Clip removed");
                    _parentWindow.Activate();
                    continue;
                }

                m = Regex.Match(cmd, @"^clip (" +
                                     @"(?<elev>[-+]?([0-9]*\.)?[0-9]+) *$" +
                                     "|" +
                                     @"(?<px>[-+]?([0-9]*\.)?[0-9]+) *, *" +
                                     @"(?<py>[-+]?([0-9]*\.)?[0-9]+) *, *" +
                                     @"(?<pz>[-+]?([0-9]*\.)?[0-9]+) *, *" +
                                     @"(?<nx>[-+]?([0-9]*\.)?[0-9]+) *, *" +
                                     @"(?<ny>[-+]?([0-9]*\.)?[0-9]+) *, *" +
                                     @"(?<nz>[-+]?([0-9]*\.)?[0-9]+)" +
                                     "|" +
                                     @"(?<StoreyName>.+$)" +
                                     ")", RegexOptions.IgnoreCase);
                if (m.Success)
                {
                    double px = 0, py = 0, pz = 0;
                    double nx = 0, ny = 0, nz = -1;

                    if (m.Groups["elev"].Value != string.Empty)
                    {
                        pz = Convert.ToDouble(m.Groups["elev"].Value);
                    }
                    else if (m.Groups["StoreyName"].Value != string.Empty)
                    {
                        var msg = "";
                        var storName = m.Groups["StoreyName"].Value;
                        var storey =
                            Model.Instances.OfType<IfcBuildingStorey>().FirstOrDefault(x => x.Name == storName);
                        if (storey != null)
                        {

                            //get the object position data (should only be one)
                            if (Model.GeometrySupportLevel == 1)
                            {
                                var geomdata =
                                    Model.GetGeometryData(storey.EntityLabel, XbimGeometryType.TransformOnly)
                                        .FirstOrDefault();
                                if (geomdata != null)
                                {
                                    var pt = new XbimPoint3D(0, 0,
                                        XbimMatrix3D.FromArray(geomdata.DataArray2).OffsetZ);
                                    var mcp = XbimMatrix3D.Copy(_parentWindow.DrawingControl.ModelPositions[Model].Transfrom);
                                    var transformed = mcp.Transform(pt);
                                    msg = string.Format("Clip 1m above storey elevation {0} (height: {1})", pt.Z, transformed.Z + 1);
                                    pz = transformed.Z + 1;
                                }
                            }
                            else if (Model.GeometrySupportLevel == 2)
                            {
                                var v = new TransformGraph(Model);
                                v.AddProduct(storey);
                                var v2 = v[storey].LocalMatrix;
                                var pt = new XbimPoint3D(0, 0, v2.OffsetZ);

                                var mcp = XbimMatrix3D.Copy(_parentWindow.DrawingControl.ModelPositions[Model].Transfrom);
                                var transformed = mcp.Transform(pt);
                                msg = string.Format("Clip 1m above storey elevation {0} (height: {1})", pt.Z, transformed.Z + 1);
                                pz = transformed.Z + 1;
                            }
                        }
                        if (msg == "")
                        {
                            ReportAdd(string.Format("Something wrong with storey name: '{0}'", storName));
                            ReportAdd("Names that should work are: ");
                            var strs = Model.Instances.OfType<IfcBuildingStorey>();
                            foreach (var str in strs)
                            {
                                ReportAdd(string.Format(" - '{0}'", str.Name));
                            }
                            continue;
                        }
                        ReportAdd(msg);
                    }
                    else
                    {
                        px = Convert.ToDouble(m.Groups["px"].Value);
                        py = Convert.ToDouble(m.Groups["py"].Value);
                        pz = Convert.ToDouble(m.Groups["pz"].Value);
                        nx = Convert.ToDouble(m.Groups["nx"].Value);
                        ny = Convert.ToDouble(m.Groups["ny"].Value);
                        nz = Convert.ToDouble(m.Groups["nz"].Value);
                    }


                    _parentWindow.DrawingControl.ClearCutPlane();
                    _parentWindow.DrawingControl.SetCutPlane(
                        px, py, pz,
                        nx, ny, nz
                        );

                    ReportAdd("Clip command sent");
                    _parentWindow.Activate();
                    continue;
                }

                m = Regex.Match(cmd, @"^Styler (?<command>.+)", RegexOptions.IgnoreCase);
                if (m.Success)
                {
                    var st = _parentWindow.DrawingControl.LayerStyler as LayerStylerTypeAndIfcStyleExtended;
                    if (st != null)
                    {
                        var command = m.Groups["command"].Value;
                        ReportAdd(
                            st.SendCommand(command, _parentWindow.DrawingControl.Selection)
                            );
                        _parentWindow.DrawingControl.ReloadModel();
                    }
                    else
                    {
                        ReportAdd("Command not valid under current styler configuration.");
                    }
                    continue;
                }

                m = Regex.Match(cmd, @"^Visual (?<action>list|tree|on|off|mode)( (?<Name>[^ ]+))*",
                    RegexOptions.IgnoreCase);
                if (m.Success)
                {
                    var parName = m.Groups["Name"].Value;
                    if (m.Groups["action"].Value.ToLowerInvariant() == "list")
                    {
                        foreach (var item in _parentWindow.DrawingControl.ListItems(parName))
                        {
                            ReportAdd(item);
                        }
                    }
                    else if (m.Groups["action"].Value.ToLowerInvariant() == "tree")
                    {
                        foreach (var item in _parentWindow.DrawingControl.LayersTree())
                        {
                            ReportAdd(item);
                        }
                    }
                    else if (m.Groups["action"].Value.ToLowerInvariant() == "mode")
                    {
                        parName = parName.ToLowerInvariant();
                        var sb = new StringBuilder();

                        // foreach model
                        if (_parentWindow.DrawingControl.LayerStylerForceVersion1 || Model.GeometrySupportLevel == 1)
                            ReportAdd(string.Format(@"Current mode is {0}",
                                _parentWindow.DrawingControl.LayerStyler.GetType())
                                , Brushes.Green);
                        else if (Model.GeometrySupportLevel == 2)
                            ReportAdd(string.Format(@"Current mode is {0}",
                                _parentWindow.DrawingControl.GeomSupport2LayerStyler.GetType()), Brushes.Green);
                        else
                            ReportAdd(@"Visual mode not enabled on GeometrySupportLevel 0", Brushes.Red);
                        

                        bool stylerSet = false;

                        var v1 = TypesImplementingInterface(typeof (ILayerStyler));
                        foreach (var instance in v1.Where(IsRealClass))
                        {
                            if (instance.Name.ToLowerInvariant() == parName ||
                                instance.FullName.ToLowerInvariant() == parName)
                            {
                                _parentWindow.DrawingControl.LayerStylerForceVersion1 = true;
                                _parentWindow.DrawingControl.LayerStyler =
                                    (ILayerStyler) Activator.CreateInstance(instance);
                                _parentWindow.DrawingControl.FederationLayerStyler =
                                    (ILayerStyler)Activator.CreateInstance(instance);


                                _parentWindow.DrawingControl.ReloadModel(
                                    options: DrawingControl3D.ModelRefreshOptions.ViewPreserveAll
                                    );
                                ReportAdd("Visual mode set to " + instance.FullName + ".", Brushes.Orange);
                                stylerSet = true;
                                continue;
                            }
                            sb.AppendLine(" - " + instance.FullName);
                        }
                        var v2 = TypesImplementingInterface(typeof(ILayerStylerV2));
                        foreach (var instance in v2.Where(IsRealClass))
                        {
                            if (instance.Name.ToLowerInvariant() == parName ||
                                instance.FullName.ToLowerInvariant() == parName)
                            {
                                _parentWindow.DrawingControl.LayerStylerForceVersion1 = false;
                                _parentWindow.DrawingControl.GeomSupport2LayerStyler =
                                    (ILayerStylerV2) Activator.CreateInstance(instance);
                                _parentWindow.DrawingControl.ReloadModel(
                                    options: DrawingControl3D.ModelRefreshOptions.ViewPreserveAll
                                    );
                                ReportAdd("Visual mode set to " + instance.FullName + ".", Brushes.Orange);
                                stylerSet = true;
                                continue;
                            }
                            sb.AppendLine(" - " + instance.FullName);
                        }
                        if (!stylerSet)
                            ReportAdd(string.Format("Nothing done; valid modes are:\r\n{0}", sb));
                    }
                    else
                    {
                        var bVis = m.Groups["action"].Value.ToLowerInvariant() == "on";
                        _parentWindow.DrawingControl.SetVisibility(parName, bVis);
                    }
                    continue;
                }
                m = Regex.Match(cmd, @"^SimplifyGUI$", RegexOptions.IgnoreCase);
                if (m.Success)
                {
                    var s = new IfcSimplify();
                    s.Show();
                    continue;
                }

                m = Regex.Match(cmd, @"^test$", RegexOptions.IgnoreCase);
                if (m.Success)
                {
                    if (SelectedEntity != null)
                        Debug.Write(SelectedEntity.EntityLabel);
                    else
                        Debug.Write(null);


                    continue;
                }
                ReportAdd(string.Format("Command not understood: {0}.", cmd));
            }
        }