修复窗口大小问题

This commit is contained in:
ShrlAlgo
2025-09-19 09:18:09 +08:00
parent d71019ac38
commit 3fc465959b
34 changed files with 592 additions and 238 deletions

View File

@@ -74,7 +74,8 @@ public partial class InstanceCreatorViewModel : ObservableObject
private BitmapSource image;
[ObservableProperty]
private string searchText;
public partial string SearchText { get; set; }
partial void OnSearchTextChanged(string value)
{
if (Families != null)

View File

@@ -2,15 +2,15 @@
x:Class="Szmedi.RvKits.Modeling.InstanceCreatorWin"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
xmlns:controls="clr-namespace:Szmedi.RvKits.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Szmedi.RvKits.Modeling"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="族实例布置"
Width="400"
Height="400"
MinHeight="300"
d:DataContext="{d:DesignInstance local:InstanceCreatorViewModel}"
mc:Ignorable="d">
<controls:MaterialWindow.Resources>
@@ -31,10 +31,10 @@
Grid.Column="0"
materialDesign:HintAssist.Hint="族名称"
DisplayMemberPath="Name"
Text="{Binding SearchText,UpdateSourceTrigger=PropertyChanged}"
IsEditable="True"
ItemsSource="{Binding FamiliesView}"
SelectedItem="{Binding SelectedFamily, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
SelectedItem="{Binding SelectedFamily, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}">
<!--<b:Interaction.Triggers>
<b:EventTrigger EventName="PreviewTextInput">
<b:InvokeCommandAction Command="{Binding PreviewTextInputCommand}" PassEventArgsToCommand="True"/>
@@ -56,7 +56,10 @@
Height="64"
Margin="5"
Source="{Binding Image}" />
<TextBox Grid.Row="3" materialDesign:TextFieldAssist.PrefixText="偏移量:" materialDesign:TextFieldAssist.SuffixText="mm">
<TextBox
Grid.Row="3"
materialDesign:TextFieldAssist.PrefixText="偏移量:"
materialDesign:TextFieldAssist.SuffixText="mm">
<TextBox.Text>
<Binding Path="Offset" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>

View File

@@ -29,9 +29,9 @@ namespace Szmedi.RvKits.Modeling
{
ProfileFamilyTypesView.Filter = obj =>
{
if (obj is FamilySymbol fs)
if (obj is WrapperSymbol ws)
{
return fs.Name.Contains(value) || fs.FamilyName.Contains(value);
return ws.FullName.Contains(value);
}
return false;
};
@@ -46,21 +46,41 @@ namespace Szmedi.RvKits.Modeling
{
FamilyTypesView.Filter = obj =>
{
if (obj is FamilySymbol fs)
if (obj is WrapperSymbol ws)
{
return fs.Name.Contains(value) || fs.FamilyName.Contains(value);
return ws.FullName.Contains(value);
}
return false;
};
FamilyTypesView.Refresh();
}
}
[ObservableProperty]
private string searchMaterialText;
partial void OnSearchMaterialTextChanged(string value)
{
if (Materials != null)
{
MaterialsView.Filter = obj =>
{
if (obj is Material mat)
{
return mat.Name.Contains(value);
}
return false;
};
MaterialsView.Refresh();
}
}
[ObservableProperty]
private CenterCurveType centerCurveType;
[ObservableProperty]
private List<FamilySymbol> familyTypes;
public partial List<WrapperSymbol> FamilyTypes { get; set; }
private readonly ActionEventHandler handler;
[Required(ErrorMessage = "不可为空")]
@@ -106,21 +126,21 @@ namespace Szmedi.RvKits.Modeling
private System.Windows.Media.ImageSource previewImage = Resources.TrackPic.ToBitmapSource();
[ObservableProperty]
private List<FamilySymbol> profileFamilyTypes;
public partial List<WrapperSymbol> ProfileFamilyTypes { get; set; }
public ICollectionView ProfileFamilyTypesView { get; set; }
public ICollectionView FamilyTypesView { get; set; }
public ICollectionView MaterialsView { get; set; }
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(CreateTrackCommand))]
private FamilySymbol selectedFamilyType;
public partial WrapperSymbol SelectedFamilyType { get; set; }
[ObservableProperty]
private Material selectedMaterial;
public partial Material SelectedMaterial { get; set; }
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(CreateTrackCommand))]
private FamilySymbol selectedProfileFamilyType;
public partial WrapperSymbol SelectedProfileFamilyType { get; set; }
[Required(ErrorMessage = "不可为空")]
[IsNumeric]
@@ -132,11 +152,11 @@ namespace Szmedi.RvKits.Modeling
public TrackCreatorViewModel(Document doc)
{
handler = new();
profileFamilyTypes = doc.QueryElementsByTypeAndCategory<FamilySymbol>(BuiltInCategory.OST_ProfileFamilies)
ProfileFamilyTypes = doc.QueryElementsByTypeAndCategory<FamilySymbol>(BuiltInCategory.OST_ProfileFamilies)
.Cast<FamilySymbol>()
.OrderBy(n => n.FamilyName)
.ToList();
familyTypes = doc.QueryElementsByType<FamilySymbol>()
.ToList().ConvertAll(s => new WrapperSymbol(s));
FamilyTypes = doc.QueryElementsByType<FamilySymbol>()
.OfType<FamilySymbol>()
.Where(
s =>
@@ -146,10 +166,11 @@ namespace Szmedi.RvKits.Modeling
&& s.Family.FamilyPlacementType == FamilyPlacementType.OneLevelBased
)
.OrderBy(n => n.FamilyName)
.ToList();
materials = doc.QueryElementsByType<Material>().OrderBy(n => n.Name).OfType<Material>().ToList();
.ToList().ConvertAll(s => new WrapperSymbol(s));
Materials = doc.QueryElementsByType<Material>().OrderBy(n => n.Name).OfType<Material>().ToList();
ProfileFamilyTypesView = CollectionViewSource.GetDefaultView(ProfileFamilyTypes);
FamilyTypesView = CollectionViewSource.GetDefaultView(FamilyTypes);
MaterialsView = CollectionViewSource.GetDefaultView(Materials);
}
[RelayCommand]
@@ -344,9 +365,9 @@ namespace Szmedi.RvKits.Modeling
{
var horizonSpline = HermiteSpline.Create(planePoints, false);
if (!SelectedFamilyType.IsActive)
if (!SelectedFamilyType.FamilySymbol.IsActive)
{
SelectedFamilyType.Activate();
SelectedFamilyType.FamilySymbol.Activate();
}
//找到零标高
var level = new FilteredElementCollector(doc)
@@ -377,7 +398,7 @@ namespace Szmedi.RvKits.Modeling
Autodesk.Revit.Creation.FamilyInstanceCreationData data1 =
new(
locLeft,
SelectedFamilyType,
SelectedFamilyType.FamilySymbol,
referVector,
level,
Autodesk.Revit.DB.Structure.StructuralType.Footing
@@ -388,7 +409,7 @@ namespace Szmedi.RvKits.Modeling
Autodesk.Revit.Creation.FamilyInstanceCreationData data =
new(
loc,
SelectedFamilyType,
SelectedFamilyType.FamilySymbol,
referVector,
level,
Autodesk.Revit.DB.Structure.StructuralType.Footing
@@ -422,7 +443,7 @@ namespace Szmedi.RvKits.Modeling
//非刚性变换,会改变原几何,此变换在曲线计算导数时为非刚性变换各个basis的模不等于1
var transform = spline3D.ComputeDerivatives(0, false);
familyDocument = doc.EditFamily(SelectedProfileFamilyType.Family);
familyDocument = doc.EditFamily(SelectedProfileFamilyType.FamilySymbol.Family);
XYZ tangent;
XYZ rightBasis;
XYZ topBasis;
@@ -467,7 +488,7 @@ namespace Szmedi.RvKits.Modeling
var fm = familyDocument.FamilyManager;
foreach (FamilyType type in fm.Types)
{
if (type.Name == SelectedProfileFamilyType.Name)
if (type.Name == SelectedProfileFamilyType.FamilySymbol.Name)
{
fm.CurrentType = type;
break;
@@ -626,6 +647,23 @@ namespace Szmedi.RvKits.Modeling
// set { SetProperty(ref spacing, value, true); }
//}
}
public class WrapperSymbol
{
public FamilySymbol FamilySymbol { get; }
public WrapperSymbol(FamilySymbol familySymbol)
{
FamilySymbol = familySymbol;
}
public string FullName => $"{FamilySymbol.FamilyName} : {FamilySymbol.Name}";
public override string ToString()
{
return $"{FamilySymbol.FamilyName} : {FamilySymbol.Name}";
}
}
public enum CenterCurveType
{
ModelCurve,

View File

@@ -11,9 +11,8 @@
Title="轨道创建"
Width="420"
Height="720"
SizeToContent="Height"
d:DataContext="{d:DesignInstance Type=local:TrackCreatorViewModel}"
SizeToContent="Height"
mc:Ignorable="d">
<controls:MaterialWindow.Resources>
<ResourceDictionary Source="pack://application:,,,/Szmedi.RvKits;component/WPFUI.xaml" />
@@ -35,15 +34,18 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<GroupBox Grid.Row="0" Grid.Column="0" Header="轨道">
<GroupBox
Grid.Row="0"
Grid.Column="0"
Header="轨道">
<StackPanel>
<ComboBox
materialDesign:HintAssist.Hint="轨道轮廓类型"
ItemTemplate="{StaticResource MultiDisplayMemberPath}"
ItemsSource="{Binding ProfileFamilyTypesView}"
DisplayMemberPath="FullName"
IsEditable="True"
Text="{Binding SearchProfileText,UpdateSourceTrigger=PropertyChanged}"
ItemsSource="{Binding ProfileFamilyTypesView, Mode=OneWay}"
SelectedItem="{Binding SelectedProfileFamilyType, UpdateSourceTrigger=PropertyChanged}"
Text="{Binding SearchProfileText, UpdateSourceTrigger=PropertyChanged}"
ToolTip="未选择则不创建,&#x0a;右键点击清除选择">
<b:Interaction.Triggers>
<b:EventTrigger EventName="MouseRightButtonUp">
@@ -54,8 +56,10 @@
<ComboBox
materialDesign:HintAssist.Hint="轨道材质"
DisplayMemberPath="Name"
ItemsSource="{Binding Materials, Mode=OneWay}"
IsEditable="True"
ItemsSource="{Binding MaterialsView, Mode=OneWay}"
SelectedItem="{Binding SelectedMaterial, UpdateSourceTrigger=PropertyChanged}"
Text="{Binding SearchMaterialText, UpdateSourceTrigger=PropertyChanged}"
ToolTip="未选择无材质,&#x0a;右键点击清除选择">
<b:Interaction.Triggers>
<b:EventTrigger EventName="MouseRightButtonUp">
@@ -77,15 +81,18 @@
ToolTip="向上偏移设置为正值,&#x0a;向下偏移为负值" />
</StackPanel>
</GroupBox>
<GroupBox Grid.Row="0" Grid.Column="1" Header="扣件、轨枕">
<GroupBox
Grid.Row="0"
Grid.Column="1"
Header="扣件、轨枕">
<StackPanel>
<ComboBox
materialDesign:HintAssist.Hint="扣件或轨枕类型"
ItemTemplate="{StaticResource MultiDisplayMemberPath}"
ItemsSource="{Binding FamilyTypesView}"
DisplayMemberPath="FullName"
IsEditable="True"
Text="{Binding SearchFamilyText,UpdateSourceTrigger=PropertyChanged}"
ItemsSource="{Binding FamilyTypesView, Mode=OneWay}"
SelectedItem="{Binding SelectedFamilyType, UpdateSourceTrigger=PropertyChanged}"
Text="{Binding SearchFamilyText, UpdateSourceTrigger=PropertyChanged}"
ToolTip="未选择则不创建,&#x0a;右键点击清除选择">
<b:Interaction.Triggers>
<b:EventTrigger EventName="MouseRightButtonUp">
@@ -115,9 +122,18 @@
</Grid>
<GroupBox Grid.Row="2" Header="中心线类型">
<UniformGrid VerticalAlignment="Center" Rows="1">
<RadioButton Content="模型线" IsChecked="{Binding CenterCurveType, ConverterParameter={x:Static local:CenterCurveType.ModelCurve}, Converter={StaticResource ComparisonConverter}}" ToolTip="框选连续、非闭合的模型线并在工具栏完成选择,&#x0a;模型线的定位平面为绘制时的工作平面,&#x0a;如在楼层楼层平面为该楼层高度" />
<RadioButton Content="体量族" IsChecked="{Binding CenterCurveType, ConverterParameter={x:Static local:CenterCurveType.MassCurve}, Converter={StaticResource ComparisonConverter}}" ToolTip="体量族中仅包含有一条连续的三维曲线" />
<RadioButton Content="dwg链接" IsChecked="{Binding CenterCurveType, ConverterParameter={x:Static local:CenterCurveType.DWGCurve}, Converter={StaticResource ComparisonConverter}}" ToolTip="dwg中仅有一条连续的三维曲线" />
<RadioButton
Content="模型线"
IsChecked="{Binding CenterCurveType, ConverterParameter={x:Static local:CenterCurveType.ModelCurve}, Converter={StaticResource ComparisonConverter}}"
ToolTip="框选连续、非闭合的模型线并在工具栏完成选择,&#x0a;模型线的定位平面为绘制时的工作平面,&#x0a;如在楼层楼层平面为该楼层高度" />
<RadioButton
Content="体量族"
IsChecked="{Binding CenterCurveType, ConverterParameter={x:Static local:CenterCurveType.MassCurve}, Converter={StaticResource ComparisonConverter}}"
ToolTip="体量族中仅包含有一条连续的三维曲线" />
<RadioButton
Content="dwg链接"
IsChecked="{Binding CenterCurveType, ConverterParameter={x:Static local:CenterCurveType.DWGCurve}, Converter={StaticResource ComparisonConverter}}"
ToolTip="dwg中仅有一条连续的三维曲线" />
</UniformGrid>
</GroupBox>
<UniformGrid Grid.Row="3" Rows="1">
@@ -132,7 +148,10 @@
Content="两侧布置"
IsChecked="{Binding IsTwoSides}"
ToolTip="截面或者实例是否在中心线另一侧创建或布置" />
<Button Command="{Binding CreateTrackCommand}" Content="创建" ToolTip="选择合适的选项,创建模型。&#x0a;注意:两根模型线之间若角度极小,&#x0a;可作为一条直线时,使用一条直线代替" />
<Button
Command="{Binding CreateTrackCommand}"
Content="创建"
ToolTip="选择合适的选项,创建模型。&#x0a;注意:两根模型线之间若角度极小,&#x0a;可作为一条直线时,使用一条直线代替" />
</UniformGrid>
</Grid>
</controls:MaterialWindow>