// Copyright 2023-2024 ANSYS, Inc. Unauthorized use, distribution, or duplication is prohibited.
syntax = "proto3";

import "ansys/api/sherlock/v0/SherlockCommonService.proto";
import "ansys/api/sherlock/v0/SherlockAnalysisService.proto";

option java_package = "sherlock.grpc";
option java_outer_classname = "SherlockModelServiceProto";

/**
 * Request to export an FEA model.
 */
message ExportFEAModelRequest {
  string project							= 1;	// Sherlock project name.
  string ccaName							= 2;	// The CCA name.
  string exportFile		 					= 3;	// Full file path to the export file.
  enum ExportAnalysis {
    NaturalFreq 		= 0;
    HarmonicVibe 		= 1;
    ICTAnalysis 		= 2;
    MechanicalShock 	= 3;
    RandomVibe 			= 4;
  }
  ExportAnalysis analysis					= 4;
  message DrillHoleParam {
    string drillHoleModeling		= 1;			// Enables or disables drill hole modeling, valid values are ENABLED/enabled or DISABLED/disabled.
    message MinHoleDiameter {
      double value = 1;		// Minimum hole diameter value.
      string unit  = 2;		// Minimum hole diameter unit.
    }
    MinHoleDiameter minHoleDiameter	= 2;
    message MaxEdgeLength {
      double value = 1;		// Maximum edge length value.
      string unit  = 2;		// Maximum edge length unit.
    }
    MaxEdgeLength maxEdgeLength		= 3;
  }
  DrillHoleParam drillHoleParam				= 5;	// Drill Holes modeling parameters - Min Hole Diameter and Max. Edge Length. If any of this parameter is provided, drill hole modeling will be enabled.
  string detectLeadModeling					= 6;	// If enabled, automatically enable lead modeling if any part has lead geometry defined, valid values are ENABLED/enabled or DISABLED/disabled.
  message LeadModelParam {
    string leadModeling					= 1;		// Enables or disables lead modeling, valid values are ENABLED/enabled or DISABLED/disabled.
    string leadElemOrder				= 2;		// Element order, valid values are "First Order (Linear)", "Second Order (Quadratic)", or "Solid Shell".
    message MaxMeshSize {
      double value	= 1;	// Max mesh size value.
      string unit	= 2;	// Max mesh size unit.			
    }
    MaxMeshSize maxMeshSize				= 3;
    message VerticalMeshSize {
      double value	= 1;	// Vertical mesh size value.
      string unit	= 2;	// Vertical mesh size unit.
    }
    VerticalMeshSize verticalMeshSize	= 4;
  }
  LeadModelParam leadModelParam				= 7;
  bool displayModel							= 8;	// Display model after export.
  bool clearFEADatabase						= 9;	// Clear FEA Database before defining model.
  bool useFEAModelID						= 10;	// Use FEA Model ID.
  string coordinateUnits					= 11;	// Units of exported model coordinates, valid values are "in", "mm", "m", "mil", "micron", "nm".
}

/**
 * Request to export a trace reinforcement model.
 */
message ExportTraceReinforcementModelRequest {
  string project							= 1;	// Sherlock project name.
  string ccaName							= 2;	// The CCA name.
  string exportFile		 					= 3;	// Full file path to the trace reinforcement export file.
  bool   overwrite							= 4;	// Overwrite existing file if true.
  bool   displayModel						= 5;	// Display model after export if true.
  bool   clearFEADatabase					= 6;	// Clear FEA Database before defining model if true.
  bool   generateModelsForAllLayers			= 7;	// Generate models for all layers.
  message TraceParam {
    message DiameterThreshold {
      double value = 1;		// Diameter threshold value.
      string unit  = 2;		// Diameter threshold unit.
    }
    DiameterThreshold diameterThreshold	= 1;
    message MinHoleDiameterForShellOrBeam {
      double value = 1;		// Min. hole diameter value for Shell/Beam.
      string unit  = 2;		// Min. hole diameter unit for Shell/Beam.
    }
    MinHoleDiameterForShellOrBeam minHoleDiameterForShellOrBeam	= 2;
  }
  TraceParam traceParam						= 8;	// Trace properties (Diameter Threshold and Minimum Hole Diameter for Shell/Beam).
  
  message TraceDrillHoleParam {
    option deprecated = true;
    string drillHoleModeling		= 1;			// Enables or disables drill hole modeling, valid values are ENABLED/enabled or DISABLED/disabled.
    message MinHoleDiameter {
      double value = 1;		// Minimum hole diameter value.
      string unit  = 2;		// Minimum hole diameter unit.
    }
    MinHoleDiameter minHoleDiameter	= 2;
    message MaxEdgeLength {
      double value = 1;		// Maximum edge length value.
      string unit  = 2;		// Maximum edge length unit.
    }
    MaxEdgeLength maxEdgeLength		= 3;
  }
  oneof drillHoleParams{
    TraceDrillHoleParam traceDrillHoleParam	= 9 [deprecated = true];	// Drill Holes modeling parameters - Min Hole Diameter and Max. Edge Length. If any of this parameter is provided, drill hole modeling will be enabled.
    DrillHoleModeling drillHoleModeling = 11; // Properties used for exporting drill holes.
  }
 
  string coordinateUnits					= 10;	// Units of exported model coordinates, valid values are "in", "mm", "m", "mil", "micron", "nm".
}

/**
 * Request to generate a trace model.
 */
message GenerateTraceModelRequest {
  string project							= 1;	// Sherlock project name.
  string ccaName							= 2;	// The CCA name. If left empty, trace models will be generated for all CCAs and all of their copper layers.
  string copperLayerName					= 3;	// Copper layer from which to generate the trace model. If left empty, trace models will be generated for all copper layers.
  double maxArcSegment						= 4;	// Max arc segment.
  string maxArcSegmentUnits					= 5;	// Max arc segment units.
  double minTraceArea						= 6;	// Min trace area.
  string minTraceAreaUnits					= 7;	// Min trace area units.
  double minHoleArea						= 8;	// Min hole area.
  string minHoleAreaUnits					= 9;	// Min hole area units.
  bool   useSnapshotForNonImageLayer		= 10;   // Use an image to generate the trace model for layers that are not image layers. If a snapshot image exists for the layer, that snapshot is used. Otherwise this creates an image that is identical to creating a snapshot.
}

/**
 *  Different ways meshes are created. The options
 *  available depend on the export file type.
 */
enum MeshType {
  NONE = 0;   // Defines only geometric volumes without generating mesh elements.
  BONDED = 1; // Defines meshed elements generated by Sherlock.
  SWEEP = 2;  // Defines geometric volumes along with commands to mesh the volumes depending on the file type.
}

/*
 * Indicates which trace regions to include in the 3D model.
 */
enum TraceOutputType  {
  ALL_REGIONS = 0;        // Both Conductor and Dielectric.
  CONDUCTOR_REGIONS = 1;  // The traces themselves.
  DIELECTRIC_REGIONS = 2; // Regions that surround the conductor regions (Ex. areas filled with resin).
}

/**
 * Drill hole properties used for exporting trace models.
 */
message DrillHoleModeling {
  bool drillHoleModelingEnabled  = 1; // Determines if drill holes will be included in the exported model.
  Measurement minHoleDiameter = 2; // All drill holes with a diameter less than this will not be included in the exported model.
                                   // Set this to 0 to include all drill holes.
  Measurement maxEdgeLength = 3; // Specifies the size of the segments used to represent round drill holes by a polygon.
}

/**
 * Request to export one or many trace models.
 */
message ExportTraceModelRequest {
  repeated TraceModelExportParams traceModelExportParams = 1; // Parameters for a single trace model export.
}

/**
 * All parameters required to export a trace model.
 */
message TraceModelExportParams {
  string project = 1;  // Sherlock project name.
  string ccaName = 2;  // Sherlock CCA name.
  string filePath = 3; // Full file path to the trace export file.
  string copperLayerName = 4; // Name of the layer in the CCA to export.
  bool overwriteExistingFile = 5; // Option that determines if any existing files get overwritten.
  bool displayModelAfterExport = 6; // Option to display the model after the export is done.
  optional bool clearFEADatabase = 7; // Clears FEA Database. Applicable for .apdl, and .cdb. This will be set to false if it is omitted for applicable file types.
  bool useFEAModelID = 8;  // Use FEA Model ID.
  optional string coordUnits = 9;  // Units of the coordinate system. Applicable to .py .wbjn, and .stp/.step. This will be set to mm if omitted for applicable file types.
  
  /*
   * Mesh properties used for exporting trace models.
   */
  message PcbMeshPropParam {
    MeshType meshType = 1; // Options of different trace meshing strategies. The options available depend on export file type.
    bool isModelingRegionEnabled = 2; // Determines if pre-defined modeling regions will be applied to the exported trace model.
  }
  PcbMeshPropParam pcbMeshPropParam = 10; // Properties used for exporting PCB mesh.

  /**
   * Trace properties used for exporting trace models.
   */
  message TracePropParam {
    TraceOutputType traceOutputs = 1; // Options to select which trace regions to include in the 3D model.
    ElementOrder elementOrder = 2; // Type of FEA element to be used when modeling each component. (First/linear, Second/quadratic, Solid Shell)
    Measurement maxMeshSize = 3; // Value passed to FEA meshing tool to indicate the desired element sizes.
    int32 maxHolesPerTrace = 4; // Maximum number of holes allowed in a trace before partitioning it into multiple traces.
  }
  TracePropParam tracePropParam = 11;  // Properties used for exporting the traces.
  DrillHoleModeling drillHoleModeling = 12; // Properties used for exporting drill holes.
}

/**
 * Request to export an Electronics Desktop model.
 */
message ExportAEDBRequest {
  string project			= 1;	// Sherlock project name.
  string ccaName			= 2;	// The CCA name.
  string exportFile		 	= 3;	// Full file path to the Electronics Desktop export file.
  bool   overwrite			= 4;	// Overwrite existing file if true.
  bool   displayModel		= 5;	// Display model after export if true.
}
 
service SherlockModelService {
  // Export an FEA Model.
  rpc exportFEAModel(ExportFEAModelRequest) returns (ReturnCode);
  
  // Export a trace reinforcement model.
  rpc exportTraceReinforcementModel(ExportTraceReinforcementModelRequest) returns (ReturnCode);
  
  // Generate a trace model.
  rpc generateTraceModel(GenerateTraceModelRequest) returns (ReturnCode);

  // Export a trace model.
  rpc exportTraceModel(ExportTraceModelRequest) returns (ReturnCode);
  
  // Export an Electronics Desktop model.
  rpc exportAEDB(ExportAEDBRequest) returns (ReturnCode);
}

