iOS: DWG Expert
The DWG Expert addresses the possibilities to customize the core features especially in the ways to introduce more powerful tools to the UI part of the application.
Features
List blocks from external sources
Insert blocks from external sources
Create a custom UI for command prompts
Access entity properties
DWG Expert - List blocks from external sources OBJ-C C++
To accomplish a feature like a block library the DWG Expert introduces a simple block container. The block container is a NSMutableArray that stores the block definition name and a corresponding thumbnail. The block container is created and initialized with all blocks from the assets calling -(void)BuildBlockLibrary when CFxARESDelegate triggers onInitializationDone(). The method onInitializationDone() is called only once each application session. The block container uses -(UIImage*)getDrawingThumbnail:(NSString*)drawing from singleton CFxARESInstance to create a block preview.
File: CFxAresDelegate.mm
-(void)onInitializationDone
{
...
[_application BuildBlockLibrary];
}
File: AppDelegate.m
@interface AppDelegate ()
{
...
NSMutableArray* m_BlockLibrary;
}
-(void)BuildBlockLibrary
{
// Prepare block library.
NSString *bundlePath = [[aresDelegate resourceBundle] bundlePath];
NSString *dwgSamplesPath = [bundlePath stringByAppendingString:@"/Support/Samples/Blocks"];
NSArray *filePaths = [NSBundle pathsForResourcesOfType:@"dwg" inDirectory:dwgSamplesPath];
m_BlockLibrary = [NSMutableArray array];
for ( NSString* drawing in filePaths )
{
BlockDefinition* block = [[BlockDefinition alloc] init];
block._blockFilePath = drawing;
block._blockName = [drawing lastPathComponent];
block._icon = [[CFxARESInstance instance] getDrawingThumbnail:drawing];
[m_BlockLibrary addObject:block];
}
}
DWG Expert - Insert blocks from external sources OBJ-C C++
The DWG Expert uses another class BlocksDelegate.m to construct a widget that can be used to show all available blocks. The widget is a common OBJ-C class, the NSObject<UITableViewDataSource, UITableViewDelegate>. The block library view processes all data from the block library the block name and the thumbnail. The block delegate is created and initialized in the ViewController.m, the table view is part of the ViewController and shows up accordingly. The final user action will happen on -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath whenever a table cell is tapped. When the table cell is triggered the block insertion is initiated with a command sequence using -(void)runCommand:(NSString*)command.
File: ViewController.m
- (void)viewDidLoad
{
...
blockDelegate = [[BlocksDelegate alloc] init];
UINib* blockItem = [UINib nibWithNibName:@"blockview" bundle:nil];
[m_Blocks registerNib:blockItem forCellReuseIdentifier:@"block"];
m_Blocks.dataSource = blockDelegate;
m_Blocks.delegate = blockDelegate;
AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
[blockDelegate SetBlocks:[appDelegate GetBlockDefinitions]];
[m_Blocks reloadData];
...
}
File: BlocksDelegate.m
DWG Expert - Create a custom UI for command prompts OBJ-C
Coming soon.
DWG Expert - Access entity properties OBJ-C C++
It may be necessary to run certain actions whenever an entity is selected. The CFxARESInstanceDelegate provides a method that informs the host application a selection has changed. The method -(void)mainSelectionSetChanged:(BOOL)isEmpty commonObjectClass:(NSString*)dxfClassName; calls a native method -(NSArray*)GetProperties from CFxNativeConnection to retrieve more information about the entities selected. The DWG Expert uses a simple UIAlertController to display the necessary entity properties. The Obj-C implementation of -(void)DisplayProperties:(NSArray*)properties is part of ViewController.m. DisplayProperties must be executed from the UI thread. A suitable method +(void)runOnUiThread:(dispatch_block_t)block is provided by [CFxARESInstance].
File: ViewController.m
File: CFxAresDelegate.m
File: CFxNativeConnection.mm